init static method

Future<void> init(
  1. Locale? locale,
  2. List<Locale> supportedLocale
)

Only for internal call. AppLocalization.init is a static function used to initialize the appLocalization instance in Karee framework.

Implementation

static Future<void> init(Locale? locale, List<Locale> supportedLocale) async {
  if (_init) return;
  KareeInternationalization._appLocalization =
      Of.tag(AppLocalization(), KareeConstants.kApplicationLocalizationTag);
  var appL = KareeInternationalization._appLocalization.value;

  appL._currentLanguage = Of.tag(
      locale == null
          ? AppLanguage.internal()
          : AppLanguage(locale.languageCode),
      KareeConstants.kApplicationLocalizationTag);
  if (locale != null) {
    if (!supportedLocale.contains(locale)) {
      supportedLocale.add(locale);
    }
    appL._currentLanguage!.value = AppLanguage.fromLocale(locale);
    try {
      await appL._readTranslationFile(locale);
      KareeInternationalization._appLocalization.refresh();
    } on FlutterError {
      throw TranslationFileNotExists(locale);
    }
  }
  _init = true;
}