Translator class
Translator to return dynamic strings loaded through various loaders.
Constructors
-
Translator({required String language, required Map<
String, List< loaders})TranslationLoader> > - Constructs the Translator with mapping of supported languages codes to the respective list of TranslationLoader instances to laod the values for each supported language.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- language → String
-
Returns the currently set language.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
supportedLanguages
→ List<
String> -
Returns the list of language codes this instance has been set up to
support.
no setter
-
translationsStream
→ Stream<
void> ? -
Returns a Stream that can be listened to when the translation values
change. Applications may choose to listen to this to be notified when
lazy loaded translations are applied so the UI can be updated
appropriately.
no setter
Methods
-
apply(
String language, Map< String, String> ? values) → void -
Applies the given set of translated strings to the translator. This will
no-op if the given
language
is not the currently set language. -
dispose(
) → void - Disposes the Translator and releases all associated resources. Once called, future calls to this instance will result in errors.
-
initialize(
) → Future< void> -
Initializes the Translator by calling, and
await
-ing all loaders for the this was constructed with. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setLanguage(
String language) → Future< void> -
Sets the
language
to the given value. While the language should be one in the supportedLanguages list, that is not actually a requirement. Setting thelanguage
to one that is not part of the supportedLanguages will result in the cached values being cleared and default strings being used until / unless the application applies the new translation values via the apply function. -
toString(
) → String -
A string representation of this object.
inherited
-
translate(
TranslationEntry entry, [Map< String, dynamic> ? args]) → String - Translates the given entry. Dynamic args must be surrounded in curley braces.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
of(
[BuildContext? context]) → Translator -
Finds the Translator that was added to the widget tree via
Provider
. If no Translator is found on the widget tree then this will return a default, empty, instance.