Search code examples
ruby-on-railstranslationinitializer

Rails: Translation in Initializer


I have several translations tucked away into an initializer like so:

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]
]

In my en.yml file I have:

en:
  constants:
    group_governance_styles:
      collective: "collective"
      electoral_democracy: "electoral democracy"
      dictatorship: "dictatorship"

Unfortunately, when I try to render these translations in a view, I get the following errors:

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

I've also tried removing the scope, but the translations still come up as missing. Is there another way to approach this? Perhaps there's a default scope for initializers that I don't know about?


Solution

  • AFAIK, translations get loaded after the initializers. Try putting it in environment.rb