From b7c023a8c1122500c6ceb7de2547569b3b9251ba Mon Sep 17 00:00:00 2001 From: Aaron Grider Date: Wed, 8 Sep 2021 16:31:30 -0700 Subject: [PATCH] Use Updated Android Locale API (#30701) Summary: This change migrates fetching locale information from the deprecated Android locale api to the new locale api on sdk version 30+. The old api was deprecated some time ago and should not be used. https://developer.android.com/reference/android/content/res/Configuration#locale ## Changelog [Android] [Changed] - Use new Locale API on Android 11 (API 30)+ Pull Request resolved: https://github.com/facebook/react-native/pull/30701 Test Plan: ```js if (Platform.OS === 'android') { locale = NativeModules.I18nManager.localeIdentifier; // returns ex. 'EN_us' } ``` Reviewed By: mdvacca Differential Revision: D30821396 Pulled By: lunaleaps fbshipit-source-id: 31622cd9c71c6057ff98ab5245898bc687b5ac60 --- .../react/modules/i18nmanager/I18nManagerModule.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nManagerModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nManagerModule.java index 767900d3d0012e..c2c54b93df4bb7 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nManagerModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nManagerModule.java @@ -8,6 +8,7 @@ package com.facebook.react.modules.i18nmanager; import android.content.Context; +import android.os.Build; import com.facebook.fbreact.specs.NativeI18nManagerSpec; import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactApplicationContext; @@ -36,7 +37,12 @@ public String getName() { @Override public Map getTypedExportedConstants() { final Context context = getReactApplicationContext(); - final Locale locale = context.getResources().getConfiguration().locale; + final Locale locale; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + locale = context.getResources().getConfiguration().getLocales().get(0); + } else { + locale = context.getResources().getConfiguration().locale; + } final Map constants = MapBuilder.newHashMap(); constants.put("isRTL", sharedI18nUtilInstance.isRTL(context));