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 <noreply@anthropic.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -94,7 +94,7 @@ class _LandingPageWidgetState extends State<LandingPageWidget> {
|
||||
routeToPage(
|
||||
context,
|
||||
LanguageSelectorPage(
|
||||
AppLocalizations.supportedLocales,
|
||||
appSupportedLocales,
|
||||
(locale) async {
|
||||
await setLocale(locale);
|
||||
EnteApp.setLocale(context, locale);
|
||||
|
||||
@@ -100,7 +100,7 @@ class GeneralSectionWidget extends StatelessWidget {
|
||||
await routeToPage(
|
||||
context,
|
||||
LanguageSelectorPage(
|
||||
AppLocalizations.supportedLocales,
|
||||
appSupportedLocales,
|
||||
(locale) async {
|
||||
await setLocale(locale);
|
||||
EnteApp.setLocale(context, locale);
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user