Rails I18n 不替换变量
Rails I18n not replacing variable
我遇到了一些问题,我的一些翻译没有用我提供的文本替换它们的变量替换,而只是按字面输出翻译。
翻译示例
formats:
view_all_other: "View all other %{format_title}"
使用示例 (HAML)
= link_to t('formats.view_all_other', format_title: @format.title.downcase), "/#{@format.to_param}/all"
输出什么
我一直在网上搜索,但我没有看到任何人有这个问题。这是我第一次使用 i18n,但看起来我没有任何设置错误,其他翻译工作正常(包括带有变量替换的翻译)。
您的翻译应按语言等级排列。让我们看看en.yml,那么翻译应该是这样的:
en:
formats:
view_all_other: "View all other %{format_title}"
facepalm 我有另一个翻译的问题,我最初调用变量 'format',我怀疑它可能是一个保留字或类似的东西所以我将所有翻译更改为使用 format_title 并忘记更新视图。
我遇到了一些问题,我的一些翻译没有用我提供的文本替换它们的变量替换,而只是按字面输出翻译。
翻译示例
formats:
view_all_other: "View all other %{format_title}"
使用示例 (HAML)
= link_to t('formats.view_all_other', format_title: @format.title.downcase), "/#{@format.to_param}/all"
输出什么
我一直在网上搜索,但我没有看到任何人有这个问题。这是我第一次使用 i18n,但看起来我没有任何设置错误,其他翻译工作正常(包括带有变量替换的翻译)。
您的翻译应按语言等级排列。让我们看看en.yml,那么翻译应该是这样的:
en:
formats:
view_all_other: "View all other %{format_title}"
facepalm 我有另一个翻译的问题,我最初调用变量 'format',我怀疑它可能是一个保留字或类似的东西所以我将所有翻译更改为使用 format_title 并忘记更新视图。