Magento 2.0.8版本-JS文本未在前端进行翻译


Magento ver 2.0.8 -JS texts is not translating in front-end

在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中使用此文本,则这不是翻译。

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

尝试以下代码:

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

这是一个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