mirror of
https://gitlab.com/openlp/openlp-mobile-remote.git
synced 2024-12-22 20:02:53 +00:00
localization selection improvements
This commit is contained in:
parent
b15a40e400
commit
98481e1329
@ -1,3 +0,0 @@
|
||||
{
|
||||
"tab_service_label": "CULTO"
|
||||
}
|
@ -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(),
|
||||
|
@ -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);
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user