From 4aa80edbcf2b8d3ccb7bd54371fe19750a8b9eff Mon Sep 17 00:00:00 2001 From: Prateek Sunal Date: Mon, 1 Sep 2025 17:02:15 +0530 Subject: [PATCH] fix: resolve unsupported locales appearing in language selector Replace AppLocalizations.supportedLocales with a curated list of properly translated locales in the Photos app. This fixes the issue where unsupported language codes (Bg, Be, Ca, Cs, etc.) were appearing in the language selector without proper language name formatting. - Add custom appSupportedLocales list with only >90% translated languages - Update all references throughout Photos app to use the custom locale list - Ensures only properly supported languages appear in the language picker Co-authored-by: Claude --- mobile/apps/photos/lib/app.dart | 4 +-- mobile/apps/photos/lib/l10n/l10n.dart | 31 ++++++++++++++++--- .../lib/ui/home/landing_page_widget.dart | 2 +- .../ui/settings/general_section_widget.dart | 2 +- mobile/apps/photos/lib/ui/tools/app_lock.dart | 2 +- 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/mobile/apps/photos/lib/app.dart b/mobile/apps/photos/lib/app.dart index a5b5178356..16986790dd 100644 --- a/mobile/apps/photos/lib/app.dart +++ b/mobile/apps/photos/lib/app.dart @@ -142,7 +142,7 @@ class _EnteAppState extends State 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 with WidgetsBindingObserver { debugShowCheckedModeBanner: false, builder: EasyLoading.init(), locale: locale, - supportedLocales: AppLocalizations.supportedLocales, + supportedLocales: appSupportedLocales, localeListResolutionCallback: localResolutionCallBack, localizationsDelegates: const [ ...AppLocalizations.localizationsDelegates, diff --git a/mobile/apps/photos/lib/l10n/l10n.dart b/mobile/apps/photos/lib/l10n/l10n.dart index 02f81becb2..1130d79536 100644 --- a/mobile/apps/photos/lib/l10n/l10n.dart +++ b/mobile/apps/photos/lib/l10n/l10n.dart @@ -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 appSupportedLocales = [ + 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 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 getLocale({ } else { savedLocale = Locale(savedValue); } - if (AppLocalizations.supportedLocales.contains(savedLocale)) { + if (appSupportedLocales.contains(savedLocale)) { return savedLocale; } } @@ -81,7 +104,7 @@ Future getLocale({ } Future 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); diff --git a/mobile/apps/photos/lib/ui/home/landing_page_widget.dart b/mobile/apps/photos/lib/ui/home/landing_page_widget.dart index b3044e60d1..0768614948 100644 --- a/mobile/apps/photos/lib/ui/home/landing_page_widget.dart +++ b/mobile/apps/photos/lib/ui/home/landing_page_widget.dart @@ -94,7 +94,7 @@ class _LandingPageWidgetState extends State { routeToPage( context, LanguageSelectorPage( - AppLocalizations.supportedLocales, + appSupportedLocales, (locale) async { await setLocale(locale); EnteApp.setLocale(context, locale); diff --git a/mobile/apps/photos/lib/ui/settings/general_section_widget.dart b/mobile/apps/photos/lib/ui/settings/general_section_widget.dart index d6d757605b..8f8f2a0032 100644 --- a/mobile/apps/photos/lib/ui/settings/general_section_widget.dart +++ b/mobile/apps/photos/lib/ui/settings/general_section_widget.dart @@ -100,7 +100,7 @@ class GeneralSectionWidget extends StatelessWidget { await routeToPage( context, LanguageSelectorPage( - AppLocalizations.supportedLocales, + appSupportedLocales, (locale) async { await setLocale(locale); EnteApp.setLocale(context, locale); diff --git a/mobile/apps/photos/lib/ui/tools/app_lock.dart b/mobile/apps/photos/lib/ui/tools/app_lock.dart index a4ca859a0e..19d6a356ec 100644 --- a/mobile/apps/photos/lib/ui/tools/app_lock.dart +++ b/mobile/apps/photos/lib/ui/tools/app_lock.dart @@ -114,7 +114,7 @@ class _AppLockState extends State with WidgetsBindingObserver { darkTheme: widget.darkTheme, locale: widget.locale, debugShowCheckedModeBanner: false, - supportedLocales: AppLocalizations.supportedLocales, + supportedLocales: appSupportedLocales, localeListResolutionCallback: localResolutionCallBack, localizationsDelegates: const [ ...AppLocalizations.localizationsDelegates,