I18n.backend.store_translations
# Will add a key or overwrite the existing value
I18n.backend.store_translations("en", {cat: "cat"})
I18n.backend.store_translations("es", {cat: "gato"})
I18n.t(:cat, locale: "en") # => "cat"
I18n.t(:cat, locale: "es") # => "gato"
Note that you cannot add keys for arbitrary locales this way; you'll get I18n::InvalidLocale
. To determine available locales, you can use:
existing_locales = I18n.config.available_locales
new_locales = existing_locales + Set.new(["es", :es])
I18n.config.available_locales = new_locales
Finally, note that if you make a global change like that for testing, you'll probably want to change it back to cleanup after your test so that other tests aren't affected.