Search code examples
ruby-on-railsrubyi18n-gem

How can I find out what locale-files are loaded by rails (including gems)?


I am introducing a new locale to my application, and copy all existing files in config/locales/.locale1.yml to config/locales/.locale2.yml.

At first I expect that I18n.backend.send(:translations)['locale1'] would equal I18n.backend.send(:translations)['locale2'], but when I diff both hashes I realise that my new new 'locale2' is missing a bunch of translations.

I figure that for locale1 additional translations have been loaded from gems like for instance the popular rails-i18n gem.

As there is no (easy) way to find out in which .yml file a translation was defined, I want to get a list of all locale-files loaded from any gems.

Any suggestions how to get that information?

Even more interesting would be if I could actually implement a way to figure out from which file a translation was loaded, but I guess that would require writing a custom i18n backend that somehow stores where each key was loaded from.


Solution

  • After phrasing the question, it became quite clear what I need to search for: 'rails i18n load paths'.

    By using:

    Rails.configuration.i18n.load_path.select { |path| path.match('bundle/gems') }

    I get close to what I need. Still not a list of what files are actually loaded or containing translations for the locale of interest, but at least a list of all gems that are considered by i18n.