π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][auth] Fix: respect system local preference
Neeraj Guptac812b8088713
diff --git a/auth/lib/locale.dart b/auth/lib/locale.dartindex 8f0e0659c3..03b9e294d2 100644--- a/auth/lib/locale.dart+++ b/auth/lib/locale.dart@@ -38,28 +38,28 @@ const List<Locale> appSupportedLocales = <Locale>[];Locale? autoDetectedLocale;-Locale localResolutionCallBack(locales, supportedLocales) {- Locale? languageCodeMatch;- final Map<String, Locale> languageCodeToLocale = {- for (Locale supportedLocale in appSupportedLocales)- supportedLocale.languageCode: supportedLocale,- };-- for (Locale locale in locales) {+// This function takes device locales and supported locales as input+// and returns the best matching locale.+// The device locales are sorted by priority, so the first one is the most preferred.+Locale localResolutionCallBack(onDeviceLocales, supportedLocales) {+ final Set<String> languageSupport = {};+ for (Locale supportedLocale in appSupportedLocales) {+ languageSupport.add(supportedLocale.languageCode);+ }+ for (Locale locale in onDeviceLocales) {+ // check if exact local is supported, if yes, return itif (appSupportedLocales.contains(locale)) {autoDetectedLocale = locale;return locale;}-- if (languageCodeMatch == null &&- languageCodeToLocale.containsKey(locale.languageCode)) {- languageCodeMatch = languageCodeToLocale[locale.languageCode];- autoDetectedLocale = languageCodeMatch;+ // check if language code is supported, if yes, return it+ if (languageSupport.contains(locale.languageCode)) {+ autoDetectedLocale = locale;+ return locale;}}-// Return the first language code match or default to 'en'- return languageCodeMatch ?? const Locale('en');+ return autoDetectedLocale ?? const Locale('en');}Future<Locale?> getLocale({diff --git a/mobile/lib/l10n/l10n.dart b/mobile/lib/l10n/l10n.dartindex 09ad1d5d06..4ed4ff7fe3 100644--- a/mobile/lib/l10n/l10n.dart+++ b/mobile/lib/l10n/l10n.dart@@ -34,22 +34,23 @@ Locale? autoDetectedLocale;Locale localResolutionCallBack(deviceLocales, supportedLocales) {_onDeviceLocales = deviceLocales;- Locale? firstLangeuageMatch;- for (Locale deviceLocale in deviceLocales) {- for (Locale supportedLocale in appSupportedLocales) {- if (supportedLocale == deviceLocale) {- autoDetectedLocale = supportedLocale;- return supportedLocale;- }- if (firstLangeuageMatch == null &&- supportedLocale.languageCode == deviceLocale.languageCode) {- firstLangeuageMatch = deviceLocale;- }- }+ final Set<String> languageSupport = {};+ for (Locale supportedLocale in appSupportedLocales) {+ languageSupport.add(supportedLocale.languageCode);}- if (firstLangeuageMatch != null) {- autoDetectedLocale = firstLangeuageMatch;+ for (Locale locale in deviceLocales) {+ // check if exact local is supported, if yes, return it+ if (appSupportedLocales.contains(locale)) {+ autoDetectedLocale = locale;+ return locale;+ }+ // check if language code is supported, if yes, return it+ if (languageSupport.contains(locale.languageCode)) {+ autoDetectedLocale = locale;+ return locale;+ }}+ // Return the first language code match or default to 'en'return autoDetectedLocale ?? const Locale('en');}