Committed by
GitHub
Update root_widget.dart
with fallbacklocale
Showing
1 changed file
with
18 additions
and
1 deletions
| 1 | -import 'package:flutter/foundation.dart'; | 1 | +iimport 'package:flutter/foundation.dart'; |
| 2 | import 'package:flutter/material.dart'; | 2 | import 'package:flutter/material.dart'; |
| 3 | import 'package:get/get.dart'; | 3 | import 'package:get/get.dart'; |
| 4 | import 'package:get/src/instance/get_instance.dart'; | 4 | import 'package:get/src/instance/get_instance.dart'; |
| @@ -30,6 +30,7 @@ class GetMaterialApp extends StatelessWidget { | @@ -30,6 +30,7 @@ class GetMaterialApp extends StatelessWidget { | ||
| 30 | this.darkTheme, | 30 | this.darkTheme, |
| 31 | this.themeMode = ThemeMode.system, | 31 | this.themeMode = ThemeMode.system, |
| 32 | this.locale, | 32 | this.locale, |
| 33 | + this.fallbackLocale, | ||
| 33 | this.localizationsDelegates, | 34 | this.localizationsDelegates, |
| 34 | this.localeListResolutionCallback, | 35 | this.localeListResolutionCallback, |
| 35 | this.localeResolutionCallback, | 36 | this.localeResolutionCallback, |
| @@ -83,6 +84,7 @@ class GetMaterialApp extends StatelessWidget { | @@ -83,6 +84,7 @@ class GetMaterialApp extends StatelessWidget { | ||
| 83 | final Map<String, Map<String, String>> translationsKeys; | 84 | final Map<String, Map<String, String>> translationsKeys; |
| 84 | final Translations translations; | 85 | final Translations translations; |
| 85 | final Locale locale; | 86 | final Locale locale; |
| 87 | + final Locale fallbackLocale; | ||
| 86 | final Iterable<LocalizationsDelegate<dynamic>> localizationsDelegates; | 88 | final Iterable<LocalizationsDelegate<dynamic>> localizationsDelegates; |
| 87 | final LocaleListResolutionCallback localeListResolutionCallback; | 89 | final LocaleListResolutionCallback localeListResolutionCallback; |
| 88 | final LocaleResolutionCallback localeResolutionCallback; | 90 | final LocaleResolutionCallback localeResolutionCallback; |
| @@ -186,6 +188,10 @@ class GetMaterialApp extends StatelessWidget { | @@ -186,6 +188,10 @@ class GetMaterialApp extends StatelessWidget { | ||
| 186 | Get.locale = locale; | 188 | Get.locale = locale; |
| 187 | } | 189 | } |
| 188 | 190 | ||
| 191 | + if (fallbackLocale != null) { | ||
| 192 | + Get.fallbackLocale = fallbackLocale; | ||
| 193 | + } | ||
| 194 | + | ||
| 189 | if (translations != null) { | 195 | if (translations != null) { |
| 190 | Get.translations = translations.keys; | 196 | Get.translations = translations.keys; |
| 191 | } else if (translationsKeys != null) { | 197 | } else if (translationsKeys != null) { |
| @@ -234,6 +240,7 @@ class GetMaterialApp extends StatelessWidget { | @@ -234,6 +240,7 @@ class GetMaterialApp extends StatelessWidget { | ||
| 234 | darkTheme: darkTheme, | 240 | darkTheme: darkTheme, |
| 235 | themeMode: _.themeMode ?? themeMode ?? ThemeMode.system, | 241 | themeMode: _.themeMode ?? themeMode ?? ThemeMode.system, |
| 236 | locale: Get.locale ?? locale, | 242 | locale: Get.locale ?? locale, |
| 243 | + fallbackLocale: Get.fallbackLocale ?? fallbackLocale, | ||
| 237 | localizationsDelegates: localizationsDelegates, | 244 | localizationsDelegates: localizationsDelegates, |
| 238 | localeListResolutionCallback: localeListResolutionCallback, | 245 | localeListResolutionCallback: localeListResolutionCallback, |
| 239 | localeResolutionCallback: localeResolutionCallback, | 246 | localeResolutionCallback: localeResolutionCallback, |
| @@ -275,6 +282,16 @@ extension Trans on String { | @@ -275,6 +282,16 @@ extension Trans on String { | ||
| 275 | Get.translations[Get.locale.languageCode].containsKey(this)) { | 282 | Get.translations[Get.locale.languageCode].containsKey(this)) { |
| 276 | return Get.translations[Get.locale.languageCode][this]; | 283 | return Get.translations[Get.locale.languageCode][this]; |
| 277 | // If there is no corresponding language or corresponding key, return the key. | 284 | // If there is no corresponding language or corresponding key, return the key. |
| 285 | + } else if (Get.translations.containsKey( | ||
| 286 | + "${Get.fallbackLocale.languageCode}_${Get.fallbackLocale.countryCode}") && | ||
| 287 | + Get.translations[ | ||
| 288 | + "${Get.fallbackLocale.languageCode}_${Get.fallbackLocale.countryCode}"] | ||
| 289 | + .containsKey(this)) { | ||
| 290 | + return Get.translations[ | ||
| 291 | + "${Get.fallbackLocale.languageCode}_${Get.fallbackLocale.countryCode}"] | ||
| 292 | + [this]; | ||
| 293 | + | ||
| 294 | + // Checks if there is a callback language in the absence of the specific country, and if it contains that key. | ||
| 278 | } else { | 295 | } else { |
| 279 | return this; | 296 | return this; |
| 280 | } | 297 | } |
-
Please register or login to post a comment