質問

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?

役に立ちましたか?

解決

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

他のヒント

If you want to be able to use your translation files in other initializer files you can add an I18n initializer.

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]
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top