AssetLocalizations class
Localization support using assets files.
Use translate to translate any text.
All translations should be put in the assets/lang/ folder as json files,
one for each local (e.g., en.jsonor da.json). Note that only the
languageCode of a Locale is used.
Remember to add the assets/lang/ folder to the list of assets in the
pubspec.yaml file like this:
flutter:
assets:
- assets/lang/
...
Translations may be nested, and are addressed with a dot-separated path. These two files are equivalent:
{ "pages": { "task_list": { "title": "Tasks" } } }
{ "pages.task_list.title": "Tasks" }
A translation can contain {{placeholder}} values, filled in from the
args of translate, and a key can be given per plural category using the
_zero, _one, _two, _few, _many and _other suffixes, selected by
the count of translate:
{
"greeting": "Hello {{name}}",
"tasks_one": "{{count}} task left",
"tasks_other": "{{count}} tasks left"
}
- Implementers
Constructors
- AssetLocalizations(Locale locale)
-
Create an assets localization based on
locale.
Properties
- filename → String
-
The file name of the localization asset.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- locale → Locale
-
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
translations
↔ Map<
String, String> -
A map of available translations for this locale.
getter/setter pair
Methods
-
canTranslate(
String key) → bool -
Can this
keybe translated by this localization? -
load(
) → Future< void> - Load the translations from filename based on the locale.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
translate(
String key, {Map< String, Object?> ? args, num? count}) → String -
Translate
keyto this locale.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
flatten(
Map< String, dynamic> translations) → Map<String, String> - Flattens a - possibly nested - map of translations into a flat map whose keys are dot-separated paths.
-
of(
BuildContext context) → AssetLocalizations? -
Returns the localized resources object of type AssetLocalizations for the
widget tree that corresponds to the given
context.
Constants
-
delegate
→ const LocalizationsDelegate<
AssetLocalizations> - A default LocalizationsDelegate for AssetLocalizations.