PHP 模板里的文字能翻译,结账页 Knockout 提示却还是英文,说明 CSV 本身不一定有问题,JS 翻译字典可能没有重新生成,或者原代码根本没走 $t()。
先看js-translation.json里有没有这句话
打开当前 locale 的:
pub/static/frontend/Vendor/theme/zh_Hans/js-translation.json搜索英文原文。没有的话先确认 CSV 编码为 UTF-8、引号正确,并位于主题或模块的 i18n/zh_Hans.csv。
前端 JS 必须这样调用:
define(['mage/translate'], function ($t) {
'use strict';
return $t('The requested quantity is not available.');
});字符串拼接会导致字典匹配失败,动态变量用占位符,不要先拼成完整英文。
删除当前locale的字典后重新部署
rm -f pub/static/frontend/Vendor/theme/zh_Hans/js-translation.json
php bin/magento setup:static-content:deploy -f --theme Vendor/theme zh_Hans
php bin/magento cache:clean translate full_page浏览器里还要清 mage-translation-storage 和 mage-translation-file-version,否则 Local Storage 会继续使用旧字典。刷新后在控制台执行 $.mage.__('英文原文') 或通过模块加载 mage/translate 验证返回值,再检查结账实际提示。

