mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
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.
This commit is contained in:
committed by
Nathan Walker
parent
c9f77a0a22
commit
ad01e6b990
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user