【问题标题】:Magento ver 2.0.8 -JS texts is not translating in front-endMagento ver 2.0.8 -JS 文本没有在前端翻译
【发布时间】:2016-11-09 11:25:42
【问题描述】:

在 Js 中:

$.mage.__('text to translate')

app/design/frontend/<vendor>/<theme_name>/i18n/fr_FR.csv

"text to translate","text to translate in french"

这是在phtml 中翻译,但如果我们在 js 中使用此文本,则不是翻译。

请指导我解决此问题的步骤。

【问题讨论】:

  • 您阅读过 Magento 文档吗?

标签: php zend-framework translation magento2


【解决方案1】:

试试下面的代码:

require([
'jquery', // jquery Library
'jquery/ui', // Jquery UI Library
'mage/translate' // Magento text translate (Validation message translte as per language)
], function($){ 
    $(window).load(function() {
        alert($.mage.__('text to translate'));
    });
});

之后你需要做以下事情:

  • 检查你的 js 正在加载并且你已经安装了翻译包 也是。
  • 通过运行 cache:clean 命令清除缓存
  • 运行 setup:static-content:deploy 再次部署 js

【讨论】:

  • app\design\frontend\Theme\main\i18n\fr_FR.csv require([ 'jquery', // jquery Library 'jquery/ui', // Jquery UI Library 'mage/translate' // Magento text translate (Validation message translte as per language) ], function($){ $(window).load(function() { alert($.mage.__('Type in or select a city to discover') ); }); });这个“输入或选择要发现的城市”没有翻译。我做了 php bin/magento setup:static-content:deploy php bin/magento setup:static-content:deploy fr_FR,php bin/magento indexer:reindex,php bin/magento 缓存:干净,php bin/magento 缓存:刷新
  • @shaan 有什么问题?
  • 嗨 Manthan Dave,phtml 文本是从这些 csv 翻译而来的。但是我遇到了 js 翻译问题。控制台也没有错误
  • pub/static 文件夹中的 js-translation.json 为空 []
  • __('输入或选择要发现的城市'), ); ?> 正在工作
【解决方案2】:

这是 Magento 2 的错误。

解决方法是删除 js-translation.json 并运行 php bin/magento setup:static-content:deploy <locale>。这应该会填充文件并使 JS/KO 翻译工作。

您可能还想更改 js-translation.json 的文件权限,以防止 Magento 再次用 [] 覆盖它。

来源:https://github.com/magento/magento2/issues/2056#issuecomment-259641599

【讨论】:

    猜你喜欢
    • 2013-08-31
    • 2011-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-07
    • 1970-01-01
    • 2016-06-23
    相关资源
    最近更新 更多