i18n_extension library

Classes

ConstTranslations<TKEY extends String, TRANbyLOCALE extends Map<StringLocale, StringTranslated>, TRANbyTKEY extends Map<TKEY, StringTranslated>, ADDEDMAP extends TRANbyLOCALE>
The ConstTranslations class allows you to define the translations as a const object, all at once. This is a little bit more efficient, and also better for "hot reload", since a const variable will respond to hot reloads, while final variables will not.
I18n
Setup
TranslatedString
This class represents missing translations. They are recorded in Translations.missingTranslations and Translations.recordMissingKeys.
Translations<TKEY, TRANbyLOCALE extends Map<StringLocale, StringTranslated>, TRANbyTKEY extends Map<TKEY, StringTranslated>, ADDEDMAP>
A Translations object is where you provide the translated strings. Given a "translation-key", it returns a map of translations: { locale : translated strings }. The translation-key may be the string itself that you want to translate, or an identifier.
TranslationsException
All translation exceptions are of type TranslationsException.

Extensions

I18nBuildContextExtension on BuildContext
I18nLocaleExtension on Locale
I18nMainExtension on String
I18nModifierLocalization on String
String extension which allows you to add plural modifiers to a string.
I18nStringExtension on String
I18nTranslationsExtension on Translations<dynamic, Map<StringLocale, StringTranslated>, Map<dynamic, StringTranslated>, dynamic>

Functions

localize(Object? key, Translations<dynamic, Map<StringLocale, StringTranslated>, Map<dynamic, StringTranslated>, dynamic> translations, {String? languageTag}) String
The localize function localizes a "translatable string" to the given languageTag. You must provide the key, which is usually the string you want to translate, and also the translations object which holds the translations.
localizeAllVersions(Object? key, Translations<dynamic, Map<StringLocale, StringTranslated>, Map<dynamic, StringTranslated>, dynamic> translations, {String? languageTag}) Map<String?, String>
Use the localizeAllVersions method to return a Map of all translated strings, where modifiers are the keys. In special, the unversioned text is indexed with a null key.
localizeArgs(Object? text, Object p1, [Object? p2, Object? p3, Object? p4, Object? p5, Object? p6, Object? p7, Object? p8, Object? p9, Object? p10, Object? p11, Object? p12, Object? p13, Object? p14, Object? p15]) String
The localizeArgs function applies interpolations on text with the given params, p1, p2, p3, ..., p15.
localizeFill(Object? text, Object p1, [Object? p2, Object? p3, Object? p4, Object? p5, Object? p6, Object? p7, Object? p8, Object? p9, Object? p10, Object? p11, Object? p12, Object? p13, Object? p14, Object? p15]) String
The localizeFill function applies a sprintf on the text with the given params, p1, p2, p3, ..., p15.
localizePlural(Object? modifier, Object? key, Translations<dynamic, Map<StringLocale, StringTranslated>, Map<dynamic, StringTranslated>, dynamic> translations, {String? languageTag}) String
The localizePlural function returns the translated version for the plural modifier. After getting the version, substring %d will be replaced with the modifier.
localizeVersion(Object modifier, Object? key, Translations<dynamic, Map<StringLocale, StringTranslated>, Map<dynamic, StringTranslated>, dynamic> translations, {String? languageTag}) String
The localizeVersion function localizes a "translatable string" to the given languageTag. You must provide the key (which is usually the string you want to translate), a modifier, and the translations object which holds the translations.
recordMissingKey(Object? key) String
Function recordMissingKey simply records the given key as a missing translation with unknown locale. It returns the same key provided, unaffected.

Typedefs

MissingTranslationCallback = bool Function({required Object? key, required StringLocale locale, required Iterable<String> supportedLocales, required Translations<dynamic, Map<StringLocale, StringTranslated>, Map<dynamic, StringTranslated>, dynamic> translations})