en:
activemodel:
attributes:
firm:
status:
active: active
trial: trial
trial-expired: trial is expired
delinquent: delinquent
inactive: inactive
在我的 config/locals/en.yml 中,我使用以下内容来使用语言文件中的内容覆盖firm.status 的值,但我收到此错误:
translation missing: en.trial
最佳答案
在您看来,您正在调用 I18N.translate(@firm.status)
(好吧,您可能只是在调用 t @firm.status
>,因为它看起来更漂亮,对吧?)
在本例中,由于状态为“Trial”,因此与调用 t“Trial”
相同,这就是它寻找顶级翻译“en.Trial”的原因。如果您想为其命名空间,最简单的方法是调用 t "activemodel.attributes.firm.status.#{@firm.status}"
,尽管这很快就会变得烦人,而且您'您需要一些辅助方法来为您完成此操作。我也不相信您应该将“activemodel.attributes”作为范围的一部分。
考虑阅读http://guides.rubyonrails.org/i18n.html ,特别是有关范围的第 4.1.1 节和有关组织区域设置文件的第 3.5 节。
关于ruby-on-rails - 在 View 中转换模型值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9541663/