addAppTranslations static method

void addAppTranslations(
  1. Map<String, Map<String, String>> translations
)

添加应用层的翻译

translations 应用层的翻译键值对,格式与GetX的translations相同

Implementation

static void addAppTranslations(
  Map<String, Map<String, String>> translations,
) {
  translations.forEach((locale, trans) {
    if (_appTranslations.containsKey(locale)) {
      _appTranslations[locale]!.addAll(trans);
    } else {
      _appTranslations[locale] = Map<String, String>.from(trans);
    }
  });

  // 如果已经初始化了GetX,则更新翻译
  if (Get.locale != null) {
    Get.clearTranslations();

    // 重新初始化翻译
    Get.addTranslations(IztroTranslationService.withAppTranslations().keys);

    // 更新当前语言
    final currentLocale = Get.locale;
    Get.updateLocale(currentLocale!);
  }
}