Skip to content

Commit 240cdc0

Browse files
d-looseashuntu
andauthored
fix(ubuntu_localizations): use fallback if locale is 'POSIX' or 'und' (#476)
If `Intl.defaultLocale` is initialized with `und` (undefined) or `POSIX` localizing a `DateTime` with `DateFormat` (and possibly other things) will throw an exception. See ubuntu/app-center#1659 for more details. A simple workaround has been suggested [here](ubuntu/app-center#1884 (comment)). --------- Co-authored-by: ashuntu <ashton.nelson@canonical.com>
1 parent eb3a19a commit 240cdc0

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/ubuntu_localizations/lib/src/localizations.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ class GlobalUbuntuLocalizations {
3030
/// * [Intl.defaultLocale]
3131
/// * [Intl.systemLocale]
3232
Future<void> initDefaultLocale([String? locale]) async {
33-
Intl.defaultLocale = locale ?? await findSystemLocale();
33+
Intl.defaultLocale = locale ??
34+
await findSystemLocale()
35+
// Fallback to 'en' if the system locale is 'POSIX' or undefined.
36+
.then((l) => l == 'POSIX' || l == 'und' ? 'en' : l);
3437
}
3538

3639
/// A localized language and its locale.

0 commit comments

Comments
 (0)