π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Fix date format in birthday date-picker
Neeraj Guptab721a848891c
diff --git a/mobile/lib/l10n/l10n.dart b/mobile/lib/l10n/l10n.dartindex 5154f8840c..ab8f9e2cc4 100644--- a/mobile/lib/l10n/l10n.dart+++ b/mobile/lib/l10n/l10n.dart@@ -29,21 +29,46 @@ const List<Locale> appSupportedLocales = <Locale>[Locale("zh", "CN"),];+List<Locale> _onDeviceLocales = [];Locale? autoDetectedLocale;-Locale localResolutionCallBack(locales, supportedLocales) {- for (Locale locale in locales) {+Locale localResolutionCallBack(deviceLocales, supportedLocales) {+ _onDeviceLocales = deviceLocales;+ debugPrint("onDeviceLocales: ${_onDeviceLocales.toString()}");+ for (Locale deviceLocale in deviceLocales) {for (Locale supportedLocale in appSupportedLocales) {- if (supportedLocale == locale) {+ if (supportedLocale == deviceLocale) {autoDetectedLocale = supportedLocale;return supportedLocale;- } else if (supportedLocale.languageCode == locale.languageCode) {+ } else if (supportedLocale.languageCode == deviceLocale.languageCode) {autoDetectedLocale = supportedLocale;return supportedLocale;}}}- return const Locale('en');+ return autoDetectedLocale ?? const Locale('en');+}++// This is used to get locale that should be used for various formatting+// operations like date, time, number etc. For common languages like english, different+// locale might have different formats. For example, en_US and en_GB have different+// formats for date and time. Use this method to find the best locale for formatting+// operations. This is not used for displaying text in the app.+Future<Locale> getFormatLocale() async {+ final Locale locale = (await getLocale())!;+ Locale? firstLanguageMatch;+ // see if exact matche is present in the device locales+ for (Locale deviceLocale in _onDeviceLocales) {+ if (deviceLocale.languageCode == locale.languageCode &&+ deviceLocale.countryCode == locale.countryCode) {+ return deviceLocale;+ }+ if (firstLanguageMatch == null &&+ deviceLocale.languageCode == locale.languageCode) {+ firstLanguageMatch = deviceLocale;+ }+ }+ return firstLanguageMatch ?? locale;}Future<Locale?> getLocale({diff --git a/mobile/lib/ui/common/date_input.dart b/mobile/lib/ui/common/date_input.dartindex 41fbccb76a..f7b1fbae0b 100644--- a/mobile/lib/ui/common/date_input.dart+++ b/mobile/lib/ui/common/date_input.dart@@ -121,8 +121,11 @@ class _DatePickerFieldState extends State<DatePickerField> {}Future<void> _showDatePicker() async {+ final Locale locale = await getFormatLocale();+ debugPrint("DatePicker: $locale");final DateTime? picked = await showDatePicker(context: context,+ locale: locale,initialDate: _selectedDate ?? DateTime.now(),firstDate: widget.firstDate ?? DateTime(1900),lastDate: widget.lastDate ?? DateTime(2100),