mirror of
https://github.com/revanced/revanced-manager
synced 2024-05-14 13:56:57 +02:00
feat: Improve language update settings (#1838)
This commit is contained in:
parent
e80ee09893
commit
f9e6ef3fd3
@ -34,17 +34,18 @@ class SUpdateLanguage extends BaseViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> showLanguagesDialog(BuildContext parentContext) {
|
Future<void> showLanguagesDialog(BuildContext parentContext) {
|
||||||
final ValueNotifier<String> selectedLanguageCode = ValueNotifier(
|
final ValueNotifier<AppLocale> selectedLanguageCode = ValueNotifier(
|
||||||
'${LocaleSettings.currentLocale.languageCode}-${LocaleSettings.currentLocale.countryCode}',
|
LocaleSettings.currentLocale,
|
||||||
);
|
);
|
||||||
LanguageCodes getLanguageCode(locale) {
|
LanguageCodes getLanguageCode(Locale locale) {
|
||||||
return LanguageCodes.fromCode(
|
return LanguageCodes.fromLocale(
|
||||||
'${locale.languageCode}_${locale.countryCode}',
|
locale,
|
||||||
orElse: () => LanguageCodes.fromCode(locale.languageCode),
|
orElse: () => LanguageCodes.fromCode(locale.languageCode),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final currentlyUsedLanguage = getLanguageCode(LocaleSettings.currentLocale);
|
final currentlyUsedLanguage =
|
||||||
|
getLanguageCode(LocaleSettings.currentLocale.flutterLocale);
|
||||||
// initLang();
|
// initLang();
|
||||||
|
|
||||||
// Return a dialog with list for each language supported by the application.
|
// Return a dialog with list for each language supported by the application.
|
||||||
@ -63,38 +64,34 @@ class SUpdateLanguage extends BaseViewModel {
|
|||||||
child: ListBody(
|
child: ListBody(
|
||||||
children: [
|
children: [
|
||||||
RadioListTile(
|
RadioListTile(
|
||||||
// TODO(Someone): There must've been a better way to do this.
|
|
||||||
title: Text(currentlyUsedLanguage.englishName),
|
title: Text(currentlyUsedLanguage.englishName),
|
||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
'${currentlyUsedLanguage.nativeName} (${LocaleSettings.currentLocale.languageCode}${LocaleSettings.currentLocale.countryCode != null ? '-${LocaleSettings.currentLocale.countryCode}' : ''})',
|
'${currentlyUsedLanguage.nativeName}\n'
|
||||||
|
'(${LocaleSettings.currentLocale.languageTag})',
|
||||||
),
|
),
|
||||||
value:
|
value: LocaleSettings.currentLocale ==
|
||||||
'${LocaleSettings.currentLocale.languageCode}-${LocaleSettings.currentLocale.countryCode}' ==
|
selectedLanguageCode.value,
|
||||||
selectedLanguageCode.value,
|
|
||||||
groupValue: true,
|
groupValue: true,
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
selectedLanguageCode.value =
|
selectedLanguageCode.value = LocaleSettings.currentLocale;
|
||||||
'${LocaleSettings.currentLocale.languageCode}-${LocaleSettings.currentLocale.countryCode}';
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
...AppLocale.values
|
...AppLocale.values
|
||||||
.where(
|
.where(
|
||||||
(locale) =>
|
(locale) => locale != LocaleSettings.currentLocale,
|
||||||
locale.languageCode != currentlyUsedLanguage.code,
|
|
||||||
)
|
)
|
||||||
.map((locale) {
|
.map((locale) {
|
||||||
final languageCode = getLanguageCode(locale);
|
final languageCode = getLanguageCode(locale.flutterLocale);
|
||||||
return RadioListTile(
|
return RadioListTile(
|
||||||
title: Text(languageCode.englishName),
|
title: Text(languageCode.englishName),
|
||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
'${languageCode.nativeName} (${locale.languageCode}${locale.countryCode != null ? '-${locale.countryCode}' : ''})',
|
'${languageCode.nativeName}\n'
|
||||||
|
'(${locale.languageTag})',
|
||||||
),
|
),
|
||||||
value: '${locale.languageCode}-${locale.countryCode}' ==
|
value: locale == selectedLanguageCode.value,
|
||||||
selectedLanguageCode.value,
|
|
||||||
groupValue: true,
|
groupValue: true,
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
selectedLanguageCode.value =
|
selectedLanguageCode.value = locale;
|
||||||
'${locale.languageCode}-${locale.countryCode}';
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
@ -113,7 +110,7 @@ class SUpdateLanguage extends BaseViewModel {
|
|||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
// TODO(nullcube): Translation will not update until we refresh the page.
|
// TODO(nullcube): Translation will not update until we refresh the page.
|
||||||
updateLocale(selectedLanguageCode.value);
|
updateLocale(selectedLanguageCode.value.languageTag);
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
child: Text(t.okButton),
|
child: Text(t.okButton),
|
||||||
@ -133,7 +130,7 @@ class SUpdateLanguageUI extends StatelessWidget {
|
|||||||
padding: const EdgeInsets.symmetric(horizontal: 20.0),
|
padding: const EdgeInsets.symmetric(horizontal: 20.0),
|
||||||
title: t.settingsView.languageLabel,
|
title: t.settingsView.languageLabel,
|
||||||
subtitle:
|
subtitle:
|
||||||
LanguageCodes.fromCode(LocaleSettings.currentLocale.languageCode)
|
LanguageCodes.fromLocale(LocaleSettings.currentLocale.flutterLocale)
|
||||||
.nativeName,
|
.nativeName,
|
||||||
onTap: () =>
|
onTap: () =>
|
||||||
_settingViewModel.sUpdateLanguage.showLanguagesDialog(context),
|
_settingViewModel.sUpdateLanguage.showLanguagesDialog(context),
|
||||||
|
@ -41,7 +41,7 @@ dependencies:
|
|||||||
injectable: ^2.1.1
|
injectable: ^2.1.1
|
||||||
intl: ^0.18.0
|
intl: ^0.18.0
|
||||||
json_annotation: ^4.8.1
|
json_annotation: ^4.8.1
|
||||||
language_code: ^0.4.2
|
language_code: ^0.5.1
|
||||||
logcat:
|
logcat:
|
||||||
git:
|
git:
|
||||||
url: https://github.com/BenjaminHalko/logcat
|
url: https://github.com/BenjaminHalko/logcat
|
||||||
|
Loading…
Reference in New Issue
Block a user