From 98481e132991209c0b21b9449c345856b57a8b08 Mon Sep 17 00:00:00 2001 From: Daniel Borges Date: Thu, 8 Aug 2019 17:02:33 -0300 Subject: [PATCH] localization selection improvements --- {lang => assets/lang}/en.json | 0 lang/pt.json | 3 --- lib/main.dart | 12 ++++++++---- lib/src/configurations/app_localizations.dart | 4 ++-- pubspec.yaml | 3 +-- 5 files changed, 11 insertions(+), 11 deletions(-) rename {lang => assets/lang}/en.json (100%) delete mode 100644 lang/pt.json diff --git a/lang/en.json b/assets/lang/en.json similarity index 100% rename from lang/en.json rename to assets/lang/en.json diff --git a/lang/pt.json b/lang/pt.json deleted file mode 100644 index 5daaf16..0000000 --- a/lang/pt.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "tab_service_label": "CULTO" -} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 6ba7bef..4ee3b3e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -34,7 +34,6 @@ void main() => runApp( theme: appTheme, supportedLocales: [ Locale('en'), - Locale('pt'), ], localizationsDelegates: [ AppLocalizations.delegate, @@ -42,14 +41,19 @@ void main() => runApp( GlobalWidgetsLocalizations.delegate, ], localeResolutionCallback: (locale, supportedLocales) { + List sameLanguageLocales = []; for (var supportedLocale in supportedLocales) { if (supportedLocale.languageCode == locale.languageCode) { - // if (supportedLocale.countryCode == locale.countryCode) { + if (supportedLocale.countryCode == locale.countryCode) { return supportedLocale; - // } + } + sameLanguageLocales.add(supportedLocale); } } - return supportedLocales.first; + if (sameLanguageLocales.isNotEmpty) + return sameLanguageLocales.first; + else + return supportedLocales.first; }, routes: { '/': (context) => OpenLPMobileRemoteApp(), diff --git a/lib/src/configurations/app_localizations.dart b/lib/src/configurations/app_localizations.dart index b855cb1..b75889f 100644 --- a/lib/src/configurations/app_localizations.dart +++ b/lib/src/configurations/app_localizations.dart @@ -15,13 +15,13 @@ class AppLocalizations { Map _localizedString; Future load() async { - String jsonFileName = 'lang/${locale.languageCode}'; + String jsonFileName = 'assets/lang/${locale.languageCode}'; if (locale.countryCode != null) { jsonFileName += '_${locale.countryCode}'; } jsonFileName += '.json'; - String mainJsonString = await rootBundle.loadString('lang/en.json'); + String mainJsonString = await rootBundle.loadString('assets/lang/en.json'); Map jsonMap = json.decode(mainJsonString); String localizedJsonString = await rootBundle.loadString(jsonFileName); diff --git a/pubspec.yaml b/pubspec.yaml index fe02f4c..e376e87 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -63,8 +63,7 @@ flutter: # To add assets to your application, add an assets section, like this: assets: - - lang/en.json - - lang/pt.json + - assets/lang/en.json # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/assets-and-images/#resolution-aware.