我将几个翻译放在一个初始化程序中,如下所示:
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"不幸的是,当我试图在视图中呈现这些翻译时,我得到了以下错误:
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我也试过删除作用域,但翻译仍然缺失。有没有其他方法来解决这个问题呢?也许有一个我不知道的初始化器的默认作用域?
发布于 2013-03-11 04:57:35
AFAIK,翻译在初始化器之后加载。试着把它放到environment.rb中
发布于 2018-12-25 08:26:17
如果您希望能够在其他初始化器文件中使用您的转换文件,则可以添加I18n初始化器。
config/initializers/i18n.rb
# Load application custom translations in order to use them in other initializers
I18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}').to_s]https://stackoverflow.com/questions/15327019
复制相似问题