Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve language update settings #1838

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,18 @@ class SUpdateLanguage extends BaseViewModel {
}

Future<void> showLanguagesDialog(BuildContext parentContext) {
final ValueNotifier<String> selectedLanguageCode = ValueNotifier(
'${LocaleSettings.currentLocale.languageCode}-${LocaleSettings.currentLocale.countryCode}',
final ValueNotifier<AppLocale> selectedLanguageCode = ValueNotifier(
LocaleSettings.currentLocale,
);
LanguageCodes getLanguageCode(locale) {
return LanguageCodes.fromCode(
'${locale.languageCode}_${locale.countryCode}',
LanguageCodes getLanguageCode(Locale locale) {
return LanguageCodes.fromLocale(
locale,
orElse: () => LanguageCodes.fromCode(locale.languageCode),
);
}

final currentlyUsedLanguage = getLanguageCode(LocaleSettings.currentLocale);
final currentlyUsedLanguage =
getLanguageCode(LocaleSettings.currentLocale.flutterLocale);
// initLang();

// Return a dialog with list for each language supported by the application.
Expand All @@ -63,38 +64,34 @@ class SUpdateLanguage extends BaseViewModel {
child: ListBody(
children: [
RadioListTile(
// TODO(Someone): There must've been a better way to do this.
title: Text(currentlyUsedLanguage.englishName),
subtitle: Text(
'${currentlyUsedLanguage.nativeName} (${LocaleSettings.currentLocale.languageCode}${LocaleSettings.currentLocale.countryCode != null ? '-${LocaleSettings.currentLocale.countryCode}' : ''})',
'${currentlyUsedLanguage.nativeName}\n'
'(${LocaleSettings.currentLocale.languageTag})',
),
value:
'${LocaleSettings.currentLocale.languageCode}-${LocaleSettings.currentLocale.countryCode}' ==
selectedLanguageCode.value,
value: LocaleSettings.currentLocale ==
selectedLanguageCode.value,
groupValue: true,
onChanged: (value) {
selectedLanguageCode.value =
'${LocaleSettings.currentLocale.languageCode}-${LocaleSettings.currentLocale.countryCode}';
selectedLanguageCode.value = LocaleSettings.currentLocale;
},
),
...AppLocale.values
.where(
(locale) =>
locale.languageCode != currentlyUsedLanguage.code,
(locale) => locale != LocaleSettings.currentLocale,
)
.map((locale) {
final languageCode = getLanguageCode(locale);
final languageCode = getLanguageCode(locale.flutterLocale);
return RadioListTile(
title: Text(languageCode.englishName),
subtitle: Text(
'${languageCode.nativeName} (${locale.languageCode}${locale.countryCode != null ? '-${locale.countryCode}' : ''})',
'${languageCode.nativeName}\n'
'(${locale.languageTag})',
),
value: '${locale.languageCode}-${locale.countryCode}' ==
selectedLanguageCode.value,
value: locale == selectedLanguageCode.value,
groupValue: true,
onChanged: (value) {
selectedLanguageCode.value =
'${locale.languageCode}-${locale.countryCode}';
selectedLanguageCode.value = locale;
},
);
}),
Expand All @@ -113,7 +110,7 @@ class SUpdateLanguage extends BaseViewModel {
TextButton(
onPressed: () {
// TODO(nullcube): Translation will not update until we refresh the page.
updateLocale(selectedLanguageCode.value);
updateLocale(selectedLanguageCode.value.languageTag);
Navigator.of(context).pop();
},
child: Text(t.okButton),
Expand All @@ -133,7 +130,7 @@ class SUpdateLanguageUI extends StatelessWidget {
padding: const EdgeInsets.symmetric(horizontal: 20.0),
title: t.settingsView.languageLabel,
subtitle:
LanguageCodes.fromCode(LocaleSettings.currentLocale.languageCode)
LanguageCodes.fromLocale(LocaleSettings.currentLocale.flutterLocale)
.nativeName,
onTap: () =>
_settingViewModel.sUpdateLanguage.showLanguagesDialog(context),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dependencies:
injectable: ^2.1.1
intl: ^0.18.0
json_annotation: ^4.8.1
language_code: ^0.4.2
language_code: ^0.5.1
logcat:
git:
url: https://github.com/BenjaminHalko/logcat
Expand Down