我有几个翻译隐藏在初始化程序中,如下所示:
GROUP_GOVERNANCE_STYLES = [
[I18n.t("constants.group_governance_styles.collective"), 1],
[I18n.t("constants.group_governance_styles.electoral_democracy"), 2],
[I18n.t("constants.group_governance_styles.dictatorship"), 3]
]
在我的 en.yml 文件中,我有:
en:
constants:
group_governance_styles:
collective: "collective"
electoral_democracy: "electoral democracy"
dictatorship: "dictatorship"
不幸的是,当我尝试在 View 中呈现这些翻译时,出现以下错误:
translation missing: en.constants.group_governance_styles.collective
translation missing: en.constants.group_governance_styles.electoral_democracy
translation missing: en.constants.group_governance_styles.dictatorship
我也试过删除范围,但翻译仍然丢失。有没有另一种方法来解决这个问题?也许我不知道初始值设定项的默认范围?
最佳答案
AFAIK,翻译在初始化程序之后加载。尝试将其放入 environment.rb
关于ruby-on-rails - rails : Translation in Initializer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15327019/