Translator class

A Flutter ChangeNotifier that manages translations and caching. Supports background translation, fallback locales, and sequential task queuing.

Inheritance

Constructors

Translator.create({TranslatorDelegate? delegate, Locale? defaultLocale, Locale? fallbackLocale})

Properties

cache Map<String, Map<String, String>>
Internal cache of translations: locale -> key -> translated string
no setter
currentLocale Locale
Currently active locale.
no setter
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
locale Locale
Change the current active locale.
no getter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
dispose() → void
Save cached translations to the delegate before disposal.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
toString() String
A string representation of this object.
inherited
tr(String key, [Locale? locale]) String
Returns the translated string for the given key and optional locale. If translation is not immediately available, returns key and translates in background.
translate(String input, Locale locale) Future<String?>
translateAll(Locale locale, {bool changeLocale = true, ValueChanged<double>? onProgress}) Future<void>
Translates all cached keys into the given locale. Calls onProgress with values between 0.0 and 1.0 as translation progresses.

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

cached Translator
Access the singleton cached instance.
no setter
shared Translator
Access the singleton shared instance.
no setter

Static Methods

init({required TranslatorDelegate delegate, Locale? defaultLocale, Locale? fallbackLocale}) → void
Initialize the singleton Translator instance. translator must implement TranslatorDelegate.