define static method
To change the current locale:
I18n.define(Locale("pt", "BR"));
To return the current locale to the system default:
I18n.define(null);
Note: This will change the current locale only for the i18n_extension, and not for Flutter as a whole.
IMPORTANT: This should be used in tests ONLY. The real app, you should
instead do: I18n.of(context).locale = Locale("en", "US");
Implementation
@visibleForTesting
static void define(Locale? locale) {
Locale oldLocale = I18n.locale;
_forcedLocale = locale;
Locale newLocale = I18n.locale;
_checkLanguageCode(newLocale);
if (oldLocale != newLocale) I18n.observeLocale(oldLocale: oldLocale, newLocale: newLocale);
}