i18n-tasks
i18n-tasks copied to clipboard
How to handle Rails I18n fallbacks
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?
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!
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.