loadLocale static method

Future<void> loadLocale(
  1. String newLocale
)

Implementation

static Future<void> loadLocale(String newLocale) async {
  final inst = _instance;
  if (inst._currentLocale == newLocale &&
      inst._currentTranslations.isNotEmpty) return;

  try {
    if (newLocale == inst._baseLocale) {
      inst._currentTranslations = Map.from(inst._baseTranslations);
    } else {
      inst._currentTranslations = await inst._loadTranslationFile(newLocale);
    }
    inst._currentLocale = newLocale;
  } catch (e) {
    inst._currentTranslations = Map.from(inst._baseTranslations);
    inst._currentLocale = inst._baseLocale;
    if (kDebugMode) {
      print(
          'ToLn Warning: Could not load locale "$newLocale". Falling back to base locale "${inst._baseLocale}".');
    }
  }

  inst._updateTextDirection();
  localeNotifier.value = Locale(inst._currentLocale);

  if (kDebugMode) {
    print('ToLn Locale changed to: ${inst._currentLocale}');
  }
}