Showing
1 changed file
with
6 additions
and
0 deletions
| @@ -257,16 +257,22 @@ abstract class Translations { | @@ -257,16 +257,22 @@ abstract class Translations { | ||
| 257 | 257 | ||
| 258 | extension Trans on String { | 258 | extension Trans on String { |
| 259 | String get tr { | 259 | String get tr { |
| 260 | + // Returns the key if locale is null. | ||
| 260 | if (Get.locale?.languageCode == null) return this; | 261 | if (Get.locale?.languageCode == null) return this; |
| 262 | + | ||
| 263 | + // Checks whether the language code and country code are present, and whether the key is also present. | ||
| 261 | if (Get.translations.containsKey( | 264 | if (Get.translations.containsKey( |
| 262 | "${Get.locale.languageCode}_${Get.locale.countryCode}") && | 265 | "${Get.locale.languageCode}_${Get.locale.countryCode}") && |
| 263 | Get.translations["${Get.locale.languageCode}_${Get.locale.countryCode}"] | 266 | Get.translations["${Get.locale.languageCode}_${Get.locale.countryCode}"] |
| 264 | .containsKey(this)) { | 267 | .containsKey(this)) { |
| 265 | return Get.translations[ | 268 | return Get.translations[ |
| 266 | "${Get.locale.languageCode}_${Get.locale.countryCode}"][this]; | 269 | "${Get.locale.languageCode}_${Get.locale.countryCode}"][this]; |
| 270 | + | ||
| 271 | + // Checks if there is a callback language in the absence of the specific country, and if it contains that key. | ||
| 267 | } else if (Get.translations.containsKey(Get.locale.languageCode) && | 272 | } else if (Get.translations.containsKey(Get.locale.languageCode) && |
| 268 | Get.translations[Get.locale.languageCode].containsKey(this)) { | 273 | Get.translations[Get.locale.languageCode].containsKey(this)) { |
| 269 | return Get.translations[Get.locale.languageCode][this]; | 274 | return Get.translations[Get.locale.languageCode][this]; |
| 275 | + // If there is no corresponding language or corresponding key, return the key. | ||
| 270 | } else { | 276 | } else { |
| 271 | return this; | 277 | return this; |
| 272 | } | 278 | } |
-
Please register or login to post a comment