set static method

Future<void> set(
  1. Language? lang, {
  2. bool refresh = true,
})

Sets the chosen language to the provided Language.

Implementation

static Future<void> set(Language? lang, {bool refresh = true}) async {
  if (lang == chosen.value || lang == null) {
    return;
  }

  if (languages.contains(lang)) {
    Intl.defaultLocale = lang.locale.toString();
    chosen.value = lang;
    _bundle =
        FluentBundle(lang.toString())
          ..addMessages(await rootBundle.loadString('assets/l10n/$lang.ftl'))
          ..addMessages(
            _phrases.entries.map((e) => '${e.key} = ${e.value}').join('\n'),
          );
    if (refresh) {
      await Get.forceAppUpdate();
    }
  } else {
    throw ArgumentError.value(lang);
  }
}