mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-26 06:08:40 +01:00
fix: brazillian localle bug that makes app unresponsive
This commit is contained in:
@@ -1,7 +1,20 @@
|
||||
import 'package:cake_wallet/generated/locales.dart';
|
||||
import 'package:devicelocale/devicelocale.dart';
|
||||
import "package:flutter/widgets.dart";
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
// This will turn stored language code into Flutter Locale.
|
||||
// Some of our language codes uses an underscore (like "pt_BR") and this must be split into language
|
||||
// and country subtags, if we pass the whole string as the languageCode, GlobalMaterialLocalizations
|
||||
// would reject it as an invalid ISO 639-1 code and crash the app on locale switch
|
||||
Locale localeFromLanguageCode(String code) {
|
||||
final parts = code.split("_");
|
||||
if (parts.length == 2 && parts[0].isNotEmpty && parts[1].isNotEmpty) {
|
||||
return Locale(parts[0], parts[1]);
|
||||
}
|
||||
return Locale(code);
|
||||
}
|
||||
|
||||
class LanguageService {
|
||||
static const Map<String, String> supportedLocales = {
|
||||
'en': 'English',
|
||||
|
||||
+1
-1
@@ -426,7 +426,7 @@ class AppState extends State<App> with SingleTickerProviderStateMixin {
|
||||
themeMode: themeMode,
|
||||
localizationsDelegates: localizationDelegates,
|
||||
supportedLocales: S.delegate.supportedLocales,
|
||||
locale: Locale(appStore.settingsStore.languageCode),
|
||||
locale: localeFromLanguageCode(appStore.settingsStore.languageCode),
|
||||
onGenerateRoute: (settings) => Router.createRoute(settings),
|
||||
initialRoute: initialRoute,
|
||||
scrollBehavior: AppScrollBehavior(),
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'dart:io';
|
||||
import 'dart:convert';
|
||||
import './print_verbose_dummy.dart';
|
||||
|
||||
import 'localization/localization_constants.dart';
|
||||
import 'utils/utils.dart';
|
||||
@@ -49,7 +48,7 @@ Future<void> main(List<String> args) async {
|
||||
return;
|
||||
}
|
||||
|
||||
final localePath = <String, dynamic>{};
|
||||
final arbFiles = <String, dynamic>{};
|
||||
await dir.list(recursive: false).forEach((element) {
|
||||
// Parse the locale from the file name (e.g. strings_pt_br.arb -> pt_BR),
|
||||
// normalizing the case so keys match LanguageService.supportedLocales.
|
||||
@@ -63,9 +62,12 @@ Future<void> main(List<String> args) async {
|
||||
final locale = parts.length > 1
|
||||
? '${parts.first.toLowerCase()}_${parts.sublist(1).join('_').toUpperCase()}'
|
||||
: parts.first.toLowerCase();
|
||||
localePath[locale] = element.path;
|
||||
arbFiles[locale] = element.path;
|
||||
});
|
||||
|
||||
final sortedLocales = arbFiles.keys.toList()..sort();
|
||||
final localePath = <String, dynamic>{for (final key in sortedLocales) key: arbFiles[key]};
|
||||
|
||||
if (!localePath.keys.contains(defaultLocale)) {
|
||||
print("Locale list doesn't contain $defaultLocale");
|
||||
return;
|
||||
@@ -103,8 +105,14 @@ Future<void> main(List<String> args) async {
|
||||
|
||||
output += classDeclaration;
|
||||
|
||||
// for handling keys like pt_BR so entry becomes Locale("pt", "BR") and doesn't crash app
|
||||
localePath.keys.forEach((key) {
|
||||
output += ' Locale("$key", ""),' + '\n';
|
||||
final parts = key.split("_");
|
||||
if (parts.length == 2) {
|
||||
output += " Locale(\"${parts[0]}\", \"${parts[1]}\"),\n";
|
||||
} else {
|
||||
output += " Locale(\"$key\", \"\"),\n";
|
||||
}
|
||||
});
|
||||
|
||||
output += part2;
|
||||
|
||||
Reference in New Issue
Block a user