Skip to content

Commit

Permalink
bugfix request for PR aissat#440
Browse files Browse the repository at this point in the history
allow loading base language fallback to continue if base language asset does not exist
  • Loading branch information
kyle-tbx committed Apr 5, 2022
1 parent b8acff4 commit 54f9205
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/src/easy_localization_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class EasyLocalizationController extends ChangeNotifier {
if (useFallbackTranslations && _fallbackLocale != null) {
Map<String, dynamic>? baseLangData;
if (_locale.countryCode != null && _locale.countryCode!.isNotEmpty) {
baseLangData = await loadTranslationData(Locale(locale.languageCode));
baseLangData = await loadBaseLangTranslationData(Locale(locale.languageCode));
}
data = await loadTranslationData(_fallbackLocale!);
if (baseLangData != null) {
Expand All @@ -97,6 +97,16 @@ class EasyLocalizationController extends ChangeNotifier {
}
}

Future<Map<String, dynamic>?> loadBaseLangTranslationData(Locale locale) async {
try {
return await loadTranslationData(Locale(locale.languageCode));
} on FlutterError catch (e) {
// Disregard asset not found FlutterError when attempting to load base language fallback
EasyLocalization.logger.warning(e.message);
}
return null;
}

Future loadTranslationData(Locale locale) async {
if (useOnlyLangCode) {
return assetLoader.load(path, Locale(locale.languageCode));
Expand Down

0 comments on commit 54f9205

Please sign in to comment.