i18n-js的Rails翻译问题

Rails translations issue with i18n-js

本文关键字:问题 翻译 Rails i18n-js      更新时间:2023-09-26

我使用http://github.com/fnando/i18n-js gem进行JavaScript翻译。这是我的翻译yml:

en:
  js:
    test: "<strong>%{name}</strong> created this board."

在我的JS中,我运行的"name"参数是"$&"

console.log(I18n.t('js.test', {name: "$&"}))

不幸的是,它将显示这样的消息:%{name}创建此板,而我期望消息应该是:$&创建此板。这颗宝石的特殊字符如"&"有什么问题吗?怎么解呢?

代码中的问题是,当您在翻译文件中使用%{name}时,您的插值不起作用。你必须使用:{{name}},而不是使插值工作。

所以,改变:

test: "<strong>%{name}</strong> created this board."

:

test: "<strong>{{name}}</strong> created this board."

,它应该工作!