localize function
String
localize(
- Object? key,
- Translations<
dynamic, Map< translations, {StringLocale, StringTranslated> , Map<dynamic, StringTranslated> , dynamic> - String? locale,
Use the localize method to localize a "translatable string" to the given locale
.
You must provide the key
(which is usually the string you want to translate)
and the translations
object which holds the translations.
If locale
is not provided (it's null
), the method will use the default locale
in I18n.localeStr.
Fallback order:
- If the translation to the exact locale is found, this will be returned.
- Otherwise, it tries to return a translation for the general language of the locale.
- Otherwise, it tries to return a translation for any locale with that language.
- Otherwise, it tries to return the key itself (which is the translation for the default locale).
Example 1: If "pt_br" is asked, and "pt_br" is available, return for "pt_br".
Example 2: If "pt_br" is asked, "pt_br" is not available, and "pt" is available, return for "pt".
Example 3: If "pt_mo" is asked, "pt_mo" and "pt" are not available, but "pt_br" is, return for "pt_br".
This class is visible only from the i18_exception_core
package.
The i18_exception
package uses a different function with the same name.
Implementation
String localize(
Object? key,
Translations translations, {
String? locale,
}) =>
core.localize(key, translations, locale: locale ?? I18n.localeStr);