i18n-tasks icon indicating copy to clipboard operation
i18n-tasks copied to clipboard

How to handle Rails I18n fallbacks

Open mattboldt opened this issue 3 years ago • 2 comments

According to these Rails docs, I have my i18n fallbacks configured in application.rb:

    config.i18n.fallbacks = {
      en_us: :en,
      fr_ca: :fr,
    }

The intent here is if your locale is :en_us, it will use U.S. specific formatting for dates, currency, etc. but for everything else, it should fall back to the standard english translations. I'd like to do the same for :fr_ca and :fr.

However, if I were to run i18n-tasks missing fr, it excludes keys in fr_ca.yml, so those come up missing. If I run i18n-tasks missing fr,fr_ca, then it thinks fr_ca is missing almost everything, since it's not "inheriting" from fr.

Are there any current solutions to configure this behavior? Like some kind of inherited hierarchy per locale key when searching for missing keys?

mattboldt avatar Mar 15 '21 17:03 mattboldt

I'd also be interested in this. We use fallbacks heavily for local variants of the same language, and without i18n-tasks being fallback aware, we can't really make use of it, which is a shame - great tool!

trusche avatar Jun 28 '21 12:06 trusche

Hey, if anyone's still dealing with this problem, here's a simple workaround:

module I18n::Tasks::MissingKeys
  def locale_key_missing?(locale, key)
    !I18n.exists?(key, locale)
  end
end

Obviously it depends on having already loaded Rails' I18n, but in the context of running the task inside your integration tests it works fine.

ariel-codes avatar Nov 10 '21 20:11 ariel-codes