Skip to content

Commit

Permalink
feat: Improve language distinguishness and resolve language-specific …
Browse files Browse the repository at this point in the history
…issues (#1706)
  • Loading branch information
Ushie authored Feb 26, 2024
1 parent f4dea6e commit 6d866d4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// ignore_for_file: use_build_context_synchronously

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:language_code/language_code.dart';
import 'package:revanced_manager/app/app.locator.dart';
Expand Down Expand Up @@ -35,8 +34,9 @@ class SUpdateLanguage extends BaseViewModel {
}

Future<void> showLanguagesDialog(BuildContext parentContext) {
final ValueNotifier<String> selectedLanguageCode =
ValueNotifier(LocaleSettings.currentLocale.languageCode);
final ValueNotifier<String> selectedLanguageCode = ValueNotifier(
'${LocaleSettings.currentLocale.languageCode}-${LocaleSettings.currentLocale.countryCode}',
);
// initLang();

// Return a dialog with list for each language supported by the application.
Expand All @@ -55,30 +55,24 @@ class SUpdateLanguage extends BaseViewModel {
child: ListBody(
children: AppLocale.values.map(
(locale) {
LanguageCodes? languageCode;
Text? languageNativeName;

try {
languageCode =
LanguageCodes.fromCode(locale.languageCode);
} catch (e) {
if (kDebugMode) {
print(e);
}
}
if (languageCode != null) {
languageNativeName = Text(languageCode.nativeName);
}
final LanguageCodes languageCode = LanguageCodes.fromCode(
'${locale.languageCode}_${locale.countryCode}',
orElse: () => LanguageCodes.fromCode(locale.languageCode),
);

return RadioListTile(
title: Text(
languageCode?.englishName ?? locale.languageCode,
languageCode.englishName,
),
subtitle: Text(
'${languageCode.nativeName} (${locale.languageCode}${locale.countryCode != null ? '-${locale.countryCode}' : ''})',
),
subtitle: languageNativeName,
value: locale.languageCode == selectedLanguageCode.value,
value: '${locale.languageCode}-${locale.countryCode}' ==
selectedLanguageCode.value,
groupValue: true,
onChanged: (value) {
selectedLanguageCode.value = locale.languageCode;
selectedLanguageCode.value =
'${locale.languageCode}-${locale.countryCode}';
},
);
},
Expand Down
9 changes: 5 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -562,10 +562,11 @@ packages:
language_code:
dependency: "direct main"
description:
name: language_code
sha256: ca1e026cc5d4ceeeb03beb73c6fc695ff091e00cec76e089394a365917a37909
url: "https://pub.dev"
source: hosted
path: "."
ref: "21b71892d1ce07fb8ea51ac2b474e435360fb6f7"
resolved-ref: "21b71892d1ce07fb8ea51ac2b474e435360fb6f7"
url: "https://github.com/Ushie/language_code"
source: git
version: "0.4.0"
leak_tracker:
dependency: transitive
Expand Down
5 changes: 4 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ dependencies:
injectable: ^2.1.1
intl: ^0.18.0
json_annotation: ^4.8.1
language_code: ^0.4.0
language_code:
git:
url: https://github.com/Ushie/language_code
ref: 21b71892d1ce07fb8ea51ac2b474e435360fb6f7 # Branch: feat/add-Filipino, Upstream PR: https://github.com/lamnhan066/language_code/pull/1
logcat:
git:
url: https://github.com/BenjaminHalko/logcat
Expand Down

0 comments on commit 6d866d4

Please sign in to comment.