init static method

Future<void> init([
  1. Language? lang
])

Initializes this L10n with the default Locale of the device, or optionally with the provided Language.

Implementation

static Future<void> init([Language? lang]) async {
  await initializeDateFormatting();

  if (lang == null) {
    final Language? language = Language.fromLocale(
      basicLocaleListResolution(
        WidgetsBinding.instance.platformDispatcher.locales,
        L10n.languages.map((e) => e.locale),
      ),
    );

    if (language != null) {
      await set(language, refresh: false);
    }
  } else {
    await set(lang, refresh: false);
  }

  if (chosen.value == null) {
    await set(languages.first, refresh: false);
  }
}