Trip
Trip

Reputation: 27114

How to use I18n in a Rails' helper via a frozen class string

My Helper..

module WatableHelper

  # binding.pry

  ANALYTICS_MEMBERS_FORMAT_COLS = {
    email:  {
      index:    1,
      type:     'string',
      friendly: I18n.t('system_roles.email'),
      unique:   true
    },
    name:   {
      index:    2,
      type:     'string',
      friendly: I18n.t('admin_courses.th.name'),
      filter:   ''
    },
    status: {
      index:    3,
      type:     'string',
      friendly: I18n.t('admin_courses.th.status'),
      filter:   false
    }
  }.freeze

When this class is loaded it will return :

translation missing: en.system_roles.email

The reason being is that if I run I18n.load_path, I can see that none of my locales have been loaded yet. I'm guessing this is because Rails will boot the Rails helpers before the locales, and after that string gets set, it gets frozen as translation missing.

If I run reload! in my console, this class will load as expected, and my locales are then located within the load path.

Anyone have any idea what the proper way to load those I18n translations?

Thanks!

Upvotes: 0

Views: 583

Answers (1)

morissetcl
morissetcl

Reputation: 564

Maybe can you try to require your locale, in this way it will loaded before:

require_relative 'your_path/until/your_locale

Upvotes: 1

Related Questions