在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