localization selection improvements

This commit is contained in:
Daniel Borges 2019-08-08 17:02:33 -03:00
parent b15a40e400
commit 98481e1329
5 changed files with 11 additions and 11 deletions

View File

@ -1,3 +0,0 @@
{
"tab_service_label": "CULTO"
}

View File

@ -34,7 +34,6 @@ void main() => runApp(
theme: appTheme, theme: appTheme,
supportedLocales: [ supportedLocales: [
Locale('en'), Locale('en'),
Locale('pt'),
], ],
localizationsDelegates: [ localizationsDelegates: [
AppLocalizations.delegate, AppLocalizations.delegate,
@ -42,13 +41,18 @@ void main() => runApp(
GlobalWidgetsLocalizations.delegate, GlobalWidgetsLocalizations.delegate,
], ],
localeResolutionCallback: (locale, supportedLocales) { localeResolutionCallback: (locale, supportedLocales) {
List<Locale> sameLanguageLocales = [];
for (var supportedLocale in supportedLocales) { for (var supportedLocale in supportedLocales) {
if (supportedLocale.languageCode == locale.languageCode) { if (supportedLocale.languageCode == locale.languageCode) {
// if (supportedLocale.countryCode == locale.countryCode) { if (supportedLocale.countryCode == locale.countryCode) {
return supportedLocale; return supportedLocale;
// } }
sameLanguageLocales.add(supportedLocale);
} }
} }
if (sameLanguageLocales.isNotEmpty)
return sameLanguageLocales.first;
else
return supportedLocales.first; return supportedLocales.first;
}, },
routes: <String, WidgetBuilder>{ routes: <String, WidgetBuilder>{

View File

@ -15,13 +15,13 @@ class AppLocalizations {
Map<String, String> _localizedString; Map<String, String> _localizedString;
Future<void> load() async { Future<void> load() async {
String jsonFileName = 'lang/${locale.languageCode}'; String jsonFileName = 'assets/lang/${locale.languageCode}';
if (locale.countryCode != null) { if (locale.countryCode != null) {
jsonFileName += '_${locale.countryCode}'; jsonFileName += '_${locale.countryCode}';
} }
jsonFileName += '.json'; jsonFileName += '.json';
String mainJsonString = await rootBundle.loadString('lang/en.json'); String mainJsonString = await rootBundle.loadString('assets/lang/en.json');
Map<String, dynamic> jsonMap = json.decode(mainJsonString); Map<String, dynamic> jsonMap = json.decode(mainJsonString);
String localizedJsonString = await rootBundle.loadString(jsonFileName); String localizedJsonString = await rootBundle.loadString(jsonFileName);

View File

@ -63,8 +63,7 @@ flutter:
# To add assets to your application, add an assets section, like this: # To add assets to your application, add an assets section, like this:
assets: assets:
- lang/en.json - assets/lang/en.json
- lang/pt.json
# An image asset can refer to one or more resolution-specific "variants", see # An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware. # https://flutter.dev/assets-and-images/#resolution-aware.