Localino class
Json/Map based localization.
- Inheritance
-
- Object
- ChangeNotifier
- Localino
- Mixed in types
-
- PrefsProvider
Constructors
-
Localino.instance(String defaultLocale, List<
LocalinoAsset> assets) - Creates new localization instance.
Properties
-
availableLocales
→ Iterable<
String> -
Returns list of available locales based on given assets.
no setter
- currentCountry → String?
-
Returns best possible country code based on currentLocale and deviceLocale.
no setter
- currentLocale → Locale
-
Returns currently loaded locale.
no setter
- dataLoader ↔ LocalinoDataLoader?
-
Callback to load translations from local cache.
getter/setter pair
- debug ↔ bool
-
Enables debug mode for localization.
When localization key isn't found for given locale, then localize returns key and current locale (key_locale).
getter/setter pair
- defaultLocale ↔ String
-
Default locale.
This locale should be loaded first, because data can contains some shared/non translatable values (links, captions, etc.).
getter/setter pair
- delegate → LocalinoDelegate
-
Delegate of Localino to use this localization as LocalizationsDelegate.
no setter
- deviceLocale → Locale
-
The system-reported default locale of the device.
no setter
-
deviceLocales
→ List<
Locale> -
The full system-reported supported locales of the device.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- hasValidAsset → bool
-
Is
true
if any LocalinoAsset is valid.no setter - isActive → bool
-
Is
true
if any data are stored in localization map.no setter - isDirty → bool
-
Is
true
if localization can load default locale data.no setter - loading ↔ bool
-
Loading localization data is async, so check this to prevent concurrent loading.
getter/setter pair
- locale → String
-
Returns currently loaded locale.
no setter
- main ↔ bool
-
Checks if this localization is main and will broadcast LocalinoArgs changes with Localino key.
Only one localization should be main !
getter/setter pair
- prefs → ControlPrefs
-
no setterinherited
- 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
-
changeLocale(
String locale, {bool preferred = true}) → Future< LocalinoArgs> -
Changes localization data inside this object for given
locale
. Setpreferred
to store locale as system preferred into shared preferences. -
changeToSystemLocale(
{bool resetPreferred = false}) → Future< LocalinoArgs> - Changes localization to system preferred language.
-
clear(
) → void - Clears loaded data.
-
contains(
String key) → bool -
Checks if given
key
can be localized. -
containsOneOf(
List< String> keys) → bool -
Checks if one of given
keys
can be localized. -
dispose(
) → void -
Discards any resources used by the object. After this is called, the
object is not in a usable state and should be discarded (calls to
addListener will throw after the object is disposed).
override
-
extractLocalization(
dynamic data, {String? locale, String? defaultLocale}) → String - Tries to localize text by given locale. Set setCustomExtractor to provide custom parsing.
-
getAsset(
String? locale) → LocalinoAsset? -
Tries to find asset for given
locale
. Locale of 'en' and 'en_US' can point to same asset file. -
getAvailableAssetLocaleForDevice(
) → String? - Looks for best suited asset locale to device supported locale.
-
getLocale(
String? locale) → Locale? -
Tries to find Locale is assets for given
locale
. Locale of 'en' and 'en_US' can point to same asset file, so resulted Locale for 'en_US' can be Locale('en') if only 'en.json' file exists. -
getSystemLocale(
) → String - Either device locale or locale stored in preferences.
-
init(
{bool loadDefaultLocale = true, bool handleSystemLocale = false, bool handleRemoteLocale = false, String? stableLocale}) → Future< LocalinoArgs> - Should be called first. Loads initial localization data - getSystemLocale is used to get preferred locale.
-
instanceOf(
List< LocalinoAsset> assets) → Localino - Creates new localization instance based on current settings.
-
isLocaleEqual(
String? a, String? b) → bool -
Checks if
a
andb
is same or if this values points to same asset path. Comparing 'en' and 'en_US' can be true because they can point to same asset file. -
isLocalizationAvailable(
String locale) → bool -
Returns
true
if localization file is available and is possible to load it. Do not check physical existence of file ! -
isSystemLocaleActive(
{bool nullOk = true}) → bool - Checks if preferred locale is loaded.
-
loadDefaultLocalization(
{bool resetPreferred = false}) → Future< LocalinoArgs> - Changes localization to defaultLocale.
-
loadLocalizationData(
String locale) → Future< LocalinoArgs> -
Loads localization data of
locale
key. Can be used to load non-translatable data. Returns result of localization change LocalinoArgs. -
localize(
String key) → String -
Tries to localize text by given
key
. -
localizeDynamic(
String key, {LocalizationParser? parser, dynamic defaultValue}) → dynamic -
Tries to localize text by given
key
. -
localizeFormat(
String key, Map< String, String> params) → String -
Tries to localize text by given
key
. Then format string with givenparams
. -
localizeList(
String key) → Iterable< String> -
Tries to localize text by given
key
. -
localizeOr(
String key, List< String> alterKeys) → String -
Tries to localize text by given
key
. -
localizePlural(
String key, int plural, [Map< String, String> ? params]) → String -
Tries to localize text by given
key
andplural
. -
localizeValue(
String key, String value) → String -
Tries to localize text by given
key
andvalue
. -
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
-
resetPreferredLocale(
{bool loadSystemLocale = false}) → Future - Removes preferred locale stored in shared preferences.
-
set(
String key, dynamic value) → void - Updates value in current localization set. This update is only runtime and isn't stored to localization file.
-
setCustomExtractor(
LocalizationExtractor extractor) → void - Sets custom extractor for extractLocalization.
-
setCustomParamDecorator(
ParamDecoratorFormat decorator) → void - Sets custom decorator for string formatting
-
setData(
Map< String, dynamic> data, {bool notify = false}) → void - Updates data in current localization set. This update is only runtime and isn't stored to localization file.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
- preference_key → const String
- Key of shared preference where preferred locale is stored.
- preference_key_sync → const String
- Key of shared preference where config is stored.