Localizer class
Localizer allows you to manage your application's localizations.
Add new localizations using the load methods.
Get locales using the getLocales
method.
Get translations directly with the get method.
Constructors
- Localizer([String defaultLocale = 'en'])
- Create a new Localizer instance. defaultLocale is the default locale to use when a specific locale has not been found.
Properties
- defaultLocale → String
-
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
supportedLocales
→ Iterable<
String> -
Get all supported locales that you can get using the getLocale method.
no setter
Methods
-
clear(
) → void -
get(
String locale, String key, [List args = const []]) → String - Get the translation for the given key. If the key is not found, it returns the key. Read more at LocalizerLocale.get.
-
getDefaultLocale(
) → LocalizerLocale - Get the default locale specified by defaultLocale.
-
getLocale(
String name) → LocalizerLocale - Get the locale object for the given locale.
-
getLocaleOrNull(
String name) → LocalizerLocale? - Get the locale object for the given locale. If the locale is not supported, it returns null.
-
getOrDefault(
String locale, String key, String defaultValue, [List args = const []]) → String - Get the translation for the given key. If the key is not found, it returns the message in the defaultLocale locale. If the key is not found in the defaultLocale locale, it returns the key. Read more at LocalizerLocale.getOrDefault.
-
hasLocale(
String name) → bool - Test if a locale is supported.
-
loadDirectory(
String path) → Future< void> - Load locales from a specific directory. All files in the directory will be loaded. The method will be skipped if the application is running in a web environment. Read more at loadFile.
-
loadFile(
String path, {String? locale}) → Future< void> -
Load locale from a specific file.
The file must be a valid YAML or JSON file.
The name of the file will be used as the locale name if
locale
is null. For example, if the file is nameden.yaml
, the locale name will been
. If a locale with the same name already exists, it will be overwritten. The method will be skipped if the application is running in a web environment. -
loadJson(
String locale, String data) → void -
Load locale
locale
from a specific string. The string must be a valid JSON string. If a locale with the same name already exists, it will be overwritten. -
loadMap(
String locale, Map< String, dynamic> map) → void -
Load locale
locale
from a specific map. If a locale with the same name already exists, it will be overwritten. The map must be a valid JSON map. -
loadYaml(
String locale, String data) → void -
Load locale
locale
from a specific string. The string must be a valid YAML string. If a locale with the same name already exists, it will be overwritten. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
removeLocale(
String name) → void - Remove a locale.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited