Committed by
GitHub
Merge pull request #493 from thaihuynhxyz/master
Fix fallback locale not working if missing country code
Showing
1 changed file
with
8 additions
and
4 deletions
| @@ -261,6 +261,7 @@ abstract class Translations { | @@ -261,6 +261,7 @@ abstract class Translations { | ||
| 261 | Map<String, Map<String, String>> get keys; | 261 | Map<String, Map<String, String>> get keys; | 
| 262 | } | 262 | } | 
| 263 | 263 | ||
| 264 | + | ||
| 264 | extension Trans on String { | 265 | extension Trans on String { | 
| 265 | String get tr { | 266 | String get tr { | 
| 266 | // Returns the key if locale is null. | 267 | // Returns the key if locale is null. | 
| @@ -279,8 +280,8 @@ extension Trans on String { | @@ -279,8 +280,8 @@ extension Trans on String { | ||
| 279 | Get.translations[Get.locale.languageCode].containsKey(this)) { | 280 | Get.translations[Get.locale.languageCode].containsKey(this)) { | 
| 280 | return Get.translations[Get.locale.languageCode][this]; | 281 | return Get.translations[Get.locale.languageCode][this]; | 
| 281 | // If there is no corresponding language or corresponding key, return the key. | 282 | // If there is no corresponding language or corresponding key, return the key. | 
| 282 | - } else if (Get.fallbackLocale != null && | ||
| 283 | - Get.translations.containsKey( | 283 | + } else if (Get.fallbackLocale != null) { | 
| 284 | + if (Get.translations.containsKey( | ||
| 284 | "${Get.fallbackLocale.languageCode}_${Get.fallbackLocale.countryCode}") && | 285 | "${Get.fallbackLocale.languageCode}_${Get.fallbackLocale.countryCode}") && | 
| 285 | Get.translations[ | 286 | Get.translations[ | 
| 286 | "${Get.fallbackLocale.languageCode}_${Get.fallbackLocale.countryCode}"] | 287 | "${Get.fallbackLocale.languageCode}_${Get.fallbackLocale.countryCode}"] | 
| @@ -288,8 +289,11 @@ extension Trans on String { | @@ -288,8 +289,11 @@ extension Trans on String { | ||
| 288 | return Get.translations[ | 289 | return Get.translations[ | 
| 289 | "${Get.fallbackLocale.languageCode}_${Get.fallbackLocale.countryCode}"] | 290 | "${Get.fallbackLocale.languageCode}_${Get.fallbackLocale.countryCode}"] | 
| 290 | [this]; | 291 | [this]; | 
| 291 | - | ||
| 292 | - // Checks if there is a callback language in the absence of the specific country, and if it contains that key. | 292 | + } | 
| 293 | + if (Get.translations.containsKey(Get.fallbackLocale.languageCode) && | ||
| 294 | + Get.translations[Get.fallbackLocale.languageCode].containsKey(this)) { | ||
| 295 | + return Get.translations[Get.fallbackLocale.languageCode][this]; | ||
| 296 | + } | ||
| 293 | } else { | 297 | } else { | 
| 294 | return this; | 298 | return this; | 
| 295 | } | 299 | } | 
- 
Please register or login to post a comment