mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-07-13 05:16:43 +02:00
Merge pull request #2130 from ImranR98/dev
Bugfix - app crashes when language set to zh_Hant_TW
This commit is contained in:
@ -23,7 +23,7 @@ import 'package:easy_localization/src/localization.dart';
|
||||
List<MapEntry<Locale, String>> supportedLocales = const [
|
||||
MapEntry(Locale('en'), 'English'),
|
||||
MapEntry(Locale('zh'), '简体中文'),
|
||||
MapEntry(Locale('zh_Hant_TW'), '臺灣話'),
|
||||
MapEntry(Locale('zh', 'Hant_TW'), '臺灣話'),
|
||||
MapEntry(Locale('it'), 'Italiano'),
|
||||
MapEntry(Locale('ja'), '日本語'),
|
||||
MapEntry(Locale('hu'), 'Magyar'),
|
||||
@ -61,11 +61,11 @@ Future<void> loadTranslations() async {
|
||||
var forceLocale = s.forcedLocale;
|
||||
final controller = EasyLocalizationController(
|
||||
saveLocale: true,
|
||||
forceLocale: forceLocale != null ? Locale(forceLocale) : null,
|
||||
forceLocale: forceLocale,
|
||||
fallbackLocale: fallbackLocale,
|
||||
supportedLocales: supportedLocales.map((e) => e.key).toList(),
|
||||
assetLoader: const RootBundleAssetLoader(),
|
||||
useOnlyLangCode: true,
|
||||
useOnlyLangCode: false,
|
||||
useFallbackTranslations: true,
|
||||
path: localeDir,
|
||||
onLoadError: (FlutterError e) {
|
||||
@ -119,7 +119,7 @@ void main() async {
|
||||
supportedLocales: supportedLocales.map((e) => e.key).toList(),
|
||||
path: localeDir,
|
||||
fallbackLocale: fallbackLocale,
|
||||
useOnlyLangCode: true,
|
||||
useOnlyLangCode: false,
|
||||
child: const Obtainium()),
|
||||
));
|
||||
BackgroundFetch.registerHeadlessTask(backgroundFetchHeadlessTask);
|
||||
@ -203,12 +203,9 @@ class _ObtainiumState extends State<Obtainium> {
|
||||
});
|
||||
}
|
||||
}
|
||||
if (!supportedLocales
|
||||
.map((e) => e.key.languageCode)
|
||||
.contains(context.locale.languageCode) ||
|
||||
if (!supportedLocales.map((e) => e.key).contains(context.locale) ||
|
||||
(settingsProvider.forcedLocale == null &&
|
||||
context.deviceLocale.languageCode !=
|
||||
context.locale.languageCode)) {
|
||||
context.deviceLocale != context.locale)) {
|
||||
settingsProvider.resetLocaleSafe(context);
|
||||
}
|
||||
}
|
||||
|
@ -262,14 +262,14 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
child: Text(tr('followSystem')),
|
||||
),
|
||||
...supportedLocales.map((e) => DropdownMenuItem(
|
||||
value: e.key.toLanguageTag(),
|
||||
value: e.key,
|
||||
child: Text(e.value),
|
||||
))
|
||||
],
|
||||
onChanged: (value) {
|
||||
settingsProvider.forcedLocale = value;
|
||||
if (value != null) {
|
||||
context.setLocale(Locale(value));
|
||||
context.setLocale(value);
|
||||
} else {
|
||||
settingsProvider.resetLocaleSafe(context);
|
||||
}
|
||||
|
@ -261,22 +261,24 @@ class SettingsProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
String? get forcedLocale {
|
||||
var fl = prefs?.getString('forcedLocale');
|
||||
return supportedLocales
|
||||
.where((element) => element.key.toLanguageTag() == fl)
|
||||
.isNotEmpty
|
||||
Locale? get forcedLocale {
|
||||
var flSegs = prefs?.getString('forcedLocale')?.split('-');
|
||||
var fl = flSegs != null && flSegs.isNotEmpty
|
||||
? Locale(flSegs[0], flSegs.length > 1 ? flSegs[1] : null)
|
||||
: null;
|
||||
var set = supportedLocales.where((element) => element.key == fl).isNotEmpty
|
||||
? fl
|
||||
: null;
|
||||
return set;
|
||||
}
|
||||
|
||||
set forcedLocale(String? fl) {
|
||||
set forcedLocale(Locale? fl) {
|
||||
if (fl == null) {
|
||||
prefs?.remove('forcedLocale');
|
||||
} else if (supportedLocales
|
||||
.where((element) => element.key.toLanguageTag() == fl)
|
||||
.where((element) => element.key == fl)
|
||||
.isNotEmpty) {
|
||||
prefs?.setString('forcedLocale', fl);
|
||||
prefs?.setString('forcedLocale', fl.toLanguageTag());
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
@ -285,9 +287,7 @@ class SettingsProvider with ChangeNotifier {
|
||||
a.length == b.length && a.union(b).length == a.length;
|
||||
|
||||
void resetLocaleSafe(BuildContext context) {
|
||||
if (context.supportedLocales
|
||||
.map((e) => e.languageCode)
|
||||
.contains(context.deviceLocale.languageCode)) {
|
||||
if (context.supportedLocales.contains(context.deviceLocale)) {
|
||||
context.resetLocale();
|
||||
} else {
|
||||
context.setLocale(context.fallbackLocale!);
|
||||
|
@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||
# In Windows, build-name is used as the major, minor, and patch parts
|
||||
# of the product and file versions while build-number is used as the build suffix.
|
||||
version: 1.1.42+2299
|
||||
version: 1.1.43+2300
|
||||
|
||||
environment:
|
||||
sdk: ^3.6.0
|
||||
|
Reference in New Issue
Block a user