I'm working on a feature in a Rails app that depends on a locale-specific piece of information. In testing, I want to show that some behavior depends on what the locale contains.
How can I dynamically add or edit translations to be used by I18n.t in testing?
I18n.backend.store_translations
Note that you cannot add keys for arbitrary locales this way; you'll get
I18n::InvalidLocale. To determine available locales, you can use: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.