LitLocalizationServiceDelegate constructor

const LitLocalizationServiceDelegate({
  1. required String jsonAssetURL,
  2. required List<String> supportedLanguages,
  3. bool debug = false,
})

Creates a LitLocalizationServiceDelegate.

This delegate is required to initialize the localizations. The localizations are extracted from the JSON file on the provided directory. This I/O operation will take a while, therefore the localized string will remain empty for about one second. This could be irritating to some users. To avoid empty text being displayed on startup, it's recommended to use constant values as localized strings inside a .dart file without using this package. LitLocalizations are used best when your app already requires I/O oparations on startup e.g. when accessing a database. This can then be covered up on a splash or loading screen.

Keep in mind, that the LitLocalizations instance is stored on the BuildContext. So in order to access the LitLocalizations.of(context) instance, you need to wrap your localized strings inside at least one custom StatelessWidget/ StatefulWidget to avoid the context not being available.

The JSON file containing your localizations should be formatted as stated below:

{
 "hello": {
   "en": "hello",
   "de": "Hallo"
 },
 "world": {
   "en": "world",
   "de": "Welt"
 }
}
  • jsonAssetURL provides the file's location relative to the app's directory.

  • supportedLanguages lists all languages that have been implemented in the JSON file. This list should match the localizationsDelegates's supportedLocales list specified on your MaterialApp/CupertinoApp.

Implementation

const LitLocalizationServiceDelegate({
  required this.jsonAssetURL,
  required this.supportedLanguages,
  this.debug = false,
});