Jonny Borges
Committed by GitHub

Merge pull request #394 from jasonlaw/master

Translation return null value when no entry found
... ... @@ -655,6 +655,16 @@ class GetImpl implements GetService {
translations.addAll(tr);
}
void appendTranslations(Map<String, Map<String, String>> tr) {
tr.forEach((key, map) {
if (Get.translations.containsKey(key)) {
Get.translations[key].addAll(map);
} else {
Get.translations[key] = map;
}
});
}
void changeTheme(ThemeData theme) {
getxController.setTheme(theme);
}
... ...
... ... @@ -257,15 +257,22 @@ abstract class Translations {
extension Trans on String {
String get tr {
// Returns the key if locale is null.
if (Get.locale?.languageCode == null) return this;
if (Get.translations
.containsKey("${Get.locale.languageCode}_${Get.locale.countryCode}")) {
// Checks whether the language code and country code are present, and whether the key is also present.
if (Get.translations.containsKey(
"${Get.locale.languageCode}_${Get.locale.countryCode}") &&
Get.translations["${Get.locale.languageCode}_${Get.locale.countryCode}"]
.containsKey(this)) {
return Get.translations[
"${Get.locale.languageCode}_${Get.locale.countryCode}"][this];
} else if (Get.translations.containsKey(Get.locale.languageCode)) {
// Checks if there is a callback language in the absence of the specific country, and if it contains that key.
} else if (Get.translations.containsKey(Get.locale.languageCode) &&
Get.translations[Get.locale.languageCode].containsKey(this)) {
return Get.translations[Get.locale.languageCode][this];
} else if (Get.translations.isNotEmpty) {
return Get.translations.values.first[this];
// If there is no corresponding language or corresponding key, return the key.
} else {
return this;
}
... ...