ruby-on-rails - rails : Translation in Initializer

标签 ruby-on-rails translation initializer

我有几个翻译隐藏在初始化程序中,如下所示:

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/

相关文章:

ruby-on-rails - wicked_pdf 字体大小在生产中太大

machine-learning - 与候选人一起翻译 API

django - 查看 django 模板中的翻译(例如 - 使其工作)

localization - 翻译错误信息是 "right"吗?

java - 为什么在静态 block 中不允许使用 return 和 throw 关键字

ruby-on-rails - Rails 服务器未以 HTTP 解析错误、格式错误的请求 () 开头:#<Puma::HttpParserError:

ruby-on-rails - 构建从belongs_to关联中提取的属性列表

ruby-on-rails - 如何建模多博客网站?

ios - Swift 中变量声明和定义的区别

c++ - 我可以在 C++ 中创建一个匿名的、大括号初始化的聚合吗?