Localizer class final

Translated text for a form: the itext engine.

Port of org.javarosa.core.services.locale.Localizer. A text id may carry a form after a semicolon (id;short, id;image, id;audio, id;video, id;big-image, id;guidance). Lookups can fall back to the form-less id (fallbackDefaultForm) and to the default locale (fallbackDefaultLocale); see getTextForLocale.

Constructors

Localizer({bool fallbackDefaultLocale = false, bool fallbackDefaultForm = false})
Creates an empty localizer; both fallback modes are off by default.

Properties

availableLocales → List<String>
The defined locales, in the order they were added.
no setter
defaultLocale ↔ String?
The default locale, or null.
getter/setter pair
fallbackDefaultForm → bool
Whether lookups of id;form fall back to id.
final
fallbackDefaultLocale → bool
Whether lookups fall back to the default locale.
final
hashCode → int
The hash code for this object.
no setterinherited
locale ↔ String?
The current locale, or null if none is set.
getter/setter pair
nextLocale → String?
The locale after the current one (cycling), the default locale if none is current, or null.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

addAvailableLocale(String locale) → bool
Defines locale (with no mappings); returns false if it already exists.
destroyLocale(String locale) → bool
Removes locale and its data; clears the default locale if it was locale. Returns whether it existed.
getLocaleData(String? locale) → Map<String, String>?
All mappings of locale (with the default locale's underneath when fallbackDefaultLocale is on), or null if locale isn't defined.
getLocaleMap(String? locale) → Map<String, String>
Like getLocaleData, but throws UnregisteredLocaleException for an undefined locale.
getLocalizedText(String textId) → String
Like getText, but throws NoLocalizedTextException if there is no text.
getRawText(String? locale, String textId) → String?
The text for exactly textId in locale, without fallbacks.
getText(String textId) → String?
The text for textId in the current locale with fallbacks, or null.
getTextForLocale(String textId, String? locale) → String?
The text for textId in locale, searching in order:
getTextWithArgs(String textId, List<String> args) → String
The text for textId in the current locale with ${0}, ${1}… replaced by args. Throws NoLocalizedTextException if missing.
getTextWithNamedArgs(String textId, Map<String, String> args) → String
The text for textId in the current locale with ${name} replaced from args. Throws NoLocalizedTextException if missing.
hasLocale(String? locale) → bool
Whether locale is defined (false for null).
hasMapping(String? locale, String? textId) → bool
Whether locale's own sources map textId (no fallbacks). Throws UnregisteredLocaleException if locale isn't defined.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
registerLocaleResource(String locale, LocaleDataSource resource) → void
Adds resource as a source of text for locale (which need not have been defined with addAvailableLocale).
registerLocalizable(Localizable localizable) → void
Registers localizable (once); it is told the current locale at once if one is set.
setToDefault() → void
Makes the default locale current. Throws StateError if there is no default locale.
toString() → String
A string representation of this object.
inherited
unregisterAll() → void
Unregisters all Localizables.
unregisterLocalizable(Localizable localizable) → void
Unregisters localizable.

Operators

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

Static Methods

clearArguments(String text) → String
text with every ${...} placeholder removed.
getArgs(String text) → List<String>
The distinct ${...} argument names in text, in order.
processArguments(String text, List<String> args, [int currentArg = 0]) → String
Replaces ${...} placeholders in text with args: ${n} takes args[n] when n is a valid index, any other placeholder takes the next unused argument. Substituted text is not processed again.
processNamedArguments(String text, Map<String, String> args) → String
Replaces ${name} in text with values from args; unknown names are left as is. Substituted text is not processed again.