TranslationManager class abstract final

Process-wide owner of the active translation FileConfig that String.tr() looks up against.

This is intentionally a static API — there is one active translation per process at any time, and apps swap it when the user changes locale. Writes serialise on an internal Future chain so two rapid setConfig calls cannot leave the active config in an inconsistent half-written state.

Typical use:

await TranslationManager.setConfig(
  FileConfig(
    mapper: (textResult) => translations[textResult.key],
  ),
);
'Hello||greeting'.tr();

For life-critical applications, install an onError sink to be notified of any internal error swallowed by String.tr() or any other error path. Without it, failures are completely silent — which is fine for non-critical UI but unacceptable when a wrong string could cause patient harm.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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

Static Properties

config FileConfig
The currently active translation config. Reads are cheap and synchronous; writes go through setConfig which serialises them.
no setter
onError TranslationErrorSink?
Optional sink called when an internal error is caught (by String.tr() or by setConfig's error-recovery path).
getter/setter pair

Static Methods

reportError(String source, Object error, StackTrace stack) → void
Forwards error to onError without throwing if the sink itself misbehaves. Intended for use by internals that swallow errors and want to expose them for diagnostics.
resetForTesting() → void
Reset the active config, the write chain, and the onError sink. Intended for tests and for hosts that need to clear translation state between sessions (e.g. between integration runs).
setConfig(FileConfig fileConfig) Future<FileConfig>
Install fileConfig as the active translation config.