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,
supportedLocales: [
Locale('en'),
Locale('pt'),
],
localizationsDelegates: [
AppLocalizations.delegate,
@ -42,14 +41,19 @@ void main() => runApp(
GlobalWidgetsLocalizations.delegate,
],
localeResolutionCallback: (locale, supportedLocales) {
List<Locale> 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: <String, WidgetBuilder>{
'/': (context) => OpenLPMobileRemoteApp(),

View File

@ -15,13 +15,13 @@ class AppLocalizations {
Map<String, String> _localizedString;
Future<void> 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<String, dynamic> jsonMap = json.decode(mainJsonString);
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:
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.