JsonAssetLoader class

The JSON Asset Loader.

Loads translation files from assets/lang/{locale}.json.

Setup

  1. Create translation files in assets/lang/:

    • assets/lang/en.json
    • assets/lang/tr.json
  2. Register in pubspec.yaml:

    flutter:
      assets:
        - assets/lang/
    

JSON Format

Supports nested keys that will be flattened:

{
  "welcome": "Welcome, :name!",
  "auth": {
    "failed": "Login failed.",
    "throttle": "Too many attempts."
  }
}

Becomes: auth.failed, auth.throttle

Implemented types

Constructors

JsonAssetLoader({String basePath = 'assets/lang', String fallbackLocale = 'en'})
Create a new JSON asset loader.
const

Properties

basePath String
The base path for translation files.
final
fallbackLocale String
The fallback locale to use when the requested locale is not found.
final
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

load(Locale locale) Future<Map<String, dynamic>>
Reads locale's catalogue, falling back to fallbackLocale's whole file.
override
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