Skip to content

Commit cd4a2bd

Browse files
alanleedevmeta-codesync[bot]
authored andcommitted
Use ConfigurationCompat for locale access in I18nManagerModule (#55663)
Summary: Pull Request resolved: #55663 Replace the direct `configuration.locales[0]` call with `ConfigurationCompat.getLocales()` from AndroidX, which handles the API level check internally. Falls back to `Locale.getDefault()` if the locale list is empty. Changelog: [Internal] ---- Reviewed By: mdvacca, NickGerleman Differential Revision: D93943818 fbshipit-source-id: 8dd1e700a4b50e0c02c76ca8dbd2358b247a5df4
1 parent 421de23 commit cd4a2bd

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

  • packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nManagerModule.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@
77

88
package com.facebook.react.modules.i18nmanager
99

10+
import androidx.core.os.ConfigurationCompat
1011
import com.facebook.fbreact.specs.NativeI18nManagerSpec
1112
import com.facebook.react.bridge.ReactApplicationContext
1213
import com.facebook.react.module.annotations.ReactModule
14+
import java.util.Locale
1315

1416
/** [com.facebook.react.bridge.NativeModule] that allows JS to set allowRTL and get isRTL status. */
1517
@ReactModule(name = NativeI18nManagerSpec.NAME)
1618
internal class I18nManagerModule(context: ReactApplicationContext?) :
1719
NativeI18nManagerSpec(context) {
1820
override fun getTypedExportedConstants(): Map<String, Any> {
1921
val context = reactApplicationContext
20-
val locale = context.resources.configuration.locales[0]
22+
val locale =
23+
ConfigurationCompat.getLocales(context.resources.configuration)[0] ?: Locale.getDefault()
2124

2225
return mapOf(
2326
"isRTL" to I18nUtil.instance.isRTL(context),

0 commit comments

Comments
 (0)