Skip to content

scriptCode #3465

Description

@jnckjian

String get tr {
if (Get.locale == null) return this;

final locale = Get.locale!;

final keys = <String>[
  // zh_Hans
  if (locale.scriptCode != null)
    '${locale.languageCode}_${locale.scriptCode}',

  // zh_CN
  if (locale.countryCode != null)
    '${locale.languageCode}_${locale.countryCode}',

  // zh
  locale.languageCode,
];

for (final key in keys) {
  final map = Get.translations[key];

  if (map != null && map.containsKey(this)) {
    return map[this]!;
  }
}

if (Get.fallbackLocale != null) {
  final fallback = Get.fallbackLocale!;

  final fallbackKeys = <String>[
    if (fallback.scriptCode != null)
      '${fallback.languageCode}_${fallback.scriptCode}',

    if (fallback.countryCode != null)
      '${fallback.languageCode}_${fallback.countryCode}',

    fallback.languageCode,
  ];

  for (final key in fallbackKeys) {
    final map = Get.translations[key];

    if (map != null && map.containsKey(this)) {
      return map[this]!;
    }
  }
}

return this;

}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions