From b65658d83d8b70b1650a2f019cef162e5600c2b3 Mon Sep 17 00:00:00 2001 From: Dimitris-Rafail Katsampas Date: Sat, 9 Jul 2022 19:17:19 +0300 Subject: [PATCH] fix(android): device language and region from system configuration. (#9868) BREAKING CHANGE: Exposes language and region values from android system configuration. If you were working around locale handling because this wasn't originally the case you can likely remove extra conditions as this should reflect more accurately now. --- packages/core/platform/index.android.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/core/platform/index.android.ts b/packages/core/platform/index.android.ts index 547ead8db..ac9656204 100644 --- a/packages/core/platform/index.android.ts +++ b/packages/core/platform/index.android.ts @@ -128,11 +128,23 @@ class DeviceRef { } get language(): string { - return java.util.Locale.getDefault().getLanguage().replace('_', '-'); + let defaultNativeLocale; + if (android.os.Build.VERSION.SDK_INT >= 24) { + defaultNativeLocale = android.content.res.Resources.getSystem().getConfiguration().getLocales().get(0); + } else { + defaultNativeLocale = android.content.res.Resources.getSystem().getConfiguration().locale; + } + return defaultNativeLocale.getLanguage().replace('_', '-'); } get region(): string { - return java.util.Locale.getDefault().getCountry(); + let defaultNativeLocale; + if (android.os.Build.VERSION.SDK_INT >= 24) { + defaultNativeLocale = android.content.res.Resources.getSystem().getConfiguration().getLocales().get(0); + } else { + defaultNativeLocale = android.content.res.Resources.getSystem().getConfiguration().locale; + } + return defaultNativeLocale.getCountry(); } }