[mob][photos] fix unsupported locales in language selector (#7029)

This commit is contained in:
Neeraj
2025-09-01 17:24:32 +05:30
committed by GitHub
6 changed files with 35 additions and 17 deletions

View File

@@ -142,7 +142,7 @@ class _EnteAppState extends State<EnteApp> with WidgetsBindingObserver {
debugShowCheckedModeBanner: false,
builder: EasyLoading.init(),
locale: locale,
supportedLocales: AppLocalizations.supportedLocales,
supportedLocales: appSupportedLocales,
localeListResolutionCallback: localResolutionCallBack,
localizationsDelegates: const [
...AppLocalizations.localizationsDelegates,
@@ -164,7 +164,7 @@ class _EnteAppState extends State<EnteApp> with WidgetsBindingObserver {
debugShowCheckedModeBanner: false,
builder: EasyLoading.init(),
locale: locale,
supportedLocales: AppLocalizations.supportedLocales,
supportedLocales: appSupportedLocales,
localeListResolutionCallback: localResolutionCallBack,
localizationsDelegates: const [
...AppLocalizations.localizationsDelegates,

View File

@@ -2,6 +2,29 @@ import "package:flutter/widgets.dart";
import 'package:photos/generated/intl/app_localizations.dart';
import "package:shared_preferences/shared_preferences.dart";
// list of locales which are enabled for photos app.
// Add more language to the list only when at least 90% of the strings are
// translated in the corresponding language.
const List<Locale> appSupportedLocales = <Locale>[
Locale('en'),
Locale('es'),
Locale('de'),
Locale('fr'),
Locale('it'),
Locale('ja'),
Locale("nl"),
Locale("no"),
Locale("pl"),
Locale("pt", "BR"),
Locale('pt', 'PT'),
Locale("ro"),
Locale("ru"),
Locale("tr"),
Locale("uk"),
Locale("vi"),
Locale("zh", "CN"),
];
extension AppLocalizationsX on BuildContext {
AppLocalizations get l10n => AppLocalizations.of(this);
}
@@ -12,12 +35,12 @@ Locale? autoDetectedLocale;
Locale localResolutionCallBack(deviceLocales, supportedLocales) {
_onDeviceLocales = deviceLocales;
final Set<String> languageSupport = {};
for (Locale supportedLocale in AppLocalizations.supportedLocales) {
for (Locale supportedLocale in appSupportedLocales) {
languageSupport.add(supportedLocale.languageCode);
}
for (Locale locale in deviceLocales) {
// check if exact local is supported, if yes, return it
if (AppLocalizations.supportedLocales.contains(locale)) {
if (appSupportedLocales.contains(locale)) {
autoDetectedLocale = locale;
return locale;
}
@@ -67,7 +90,7 @@ Future<Locale?> getLocale({
} else {
savedLocale = Locale(savedValue);
}
if (AppLocalizations.supportedLocales.contains(savedLocale)) {
if (appSupportedLocales.contains(savedLocale)) {
return savedLocale;
}
}
@@ -81,7 +104,7 @@ Future<Locale?> getLocale({
}
Future<void> setLocale(Locale locale) async {
if (!AppLocalizations.supportedLocales.contains(locale)) {
if (!appSupportedLocales.contains(locale)) {
throw Exception('Locale $locale is not supported by the app');
}
final StringBuffer out = StringBuffer(locale.languageCode);

View File

@@ -94,7 +94,7 @@ class _LandingPageWidgetState extends State<LandingPageWidget> {
routeToPage(
context,
LanguageSelectorPage(
AppLocalizations.supportedLocales,
appSupportedLocales,
(locale) async {
await setLocale(locale);
EnteApp.setLocale(context, locale);

View File

@@ -100,7 +100,7 @@ class GeneralSectionWidget extends StatelessWidget {
await routeToPage(
context,
LanguageSelectorPage(
AppLocalizations.supportedLocales,
appSupportedLocales,
(locale) async {
await setLocale(locale);
EnteApp.setLocale(context, locale);

View File

@@ -159,16 +159,11 @@ class _ItemsWidgetState extends State<ItemsWidget> {
return 'Русский';
case 'tr':
return 'Türkçe';
case 'fi':
return 'Suomi';
case 'zh':
if (locale.countryCode == 'CN') {
return '中文 (简体)';
}
return '中文';
case 'zh-CN':
return '中文';
case 'ko':
return '한국어';
case 'ar':
return 'العربية';
case 'uk':
return 'Українська';
case 'vi':

View File

@@ -114,7 +114,7 @@ class _AppLockState extends State<AppLock> with WidgetsBindingObserver {
darkTheme: widget.darkTheme,
locale: widget.locale,
debugShowCheckedModeBanner: false,
supportedLocales: AppLocalizations.supportedLocales,
supportedLocales: appSupportedLocales,
localeListResolutionCallback: localResolutionCallBack,
localizationsDelegates: const [
...AppLocalizations.localizationsDelegates,