Skip to content

Commit b7c023a

Browse files
Aaron Griderfacebook-github-bot
Aaron Grider
authored andcommitted
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: #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
1 parent ab8dbdf commit b7c023a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nManagerModule.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package com.facebook.react.modules.i18nmanager;
99

1010
import android.content.Context;
11+
import android.os.Build;
1112
import com.facebook.fbreact.specs.NativeI18nManagerSpec;
1213
import com.facebook.react.bridge.NativeModule;
1314
import com.facebook.react.bridge.ReactApplicationContext;
@@ -36,7 +37,12 @@ public String getName() {
3637
@Override
3738
public Map<String, Object> getTypedExportedConstants() {
3839
final Context context = getReactApplicationContext();
39-
final Locale locale = context.getResources().getConfiguration().locale;
40+
final Locale locale;
41+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
42+
locale = context.getResources().getConfiguration().getLocales().get(0);
43+
} else {
44+
locale = context.getResources().getConfiguration().locale;
45+
}
4046

4147
final Map<String, Object> constants = MapBuilder.newHashMap();
4248
constants.put("isRTL", sharedI18nUtilInstance.isRTL(context));

0 commit comments

Comments
 (0)