Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions packages/sdk/react-native/src/platform/locale.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { NativeModules, Platform } from 'react-native';

/**
* Ripped from:
* https://dev.to/medaimane/localization-and-internationalization-in-react-native-reaching-global-audiences-3acj
* Apps opted into Fabric (the new architecture of React Native)
* may not have access to the SettingsManager.settings.AppleLocale property.
* It is now common to use the `getConstants` method to access these constant properties with Fabric enabled apps.
*/
const locale =
Platform.OS === 'ios'
? NativeModules.SettingsManager?.settings?.AppleLocale // iOS
: NativeModules.I18nManager?.localeIdentifier;
const getAppleLocale = () => {
const settings = NativeModules.SettingsManager?.settings ?? NativeModules.SettingsManager?.getConstants()?.settings;
return settings?.AppleLocale;
}

export default locale;
export default Platform.select({
ios: getAppleLocale(),
android: NativeModules.I18nManager?.localeIdentifier,
})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Platform Select Returns Undefined, Calls iOS Code Unnecessarily

The Platform.select implementation now returns undefined for non-iOS/Android platforms, removing the previous I18nManager?.localeIdentifier fallback. Additionally, getAppleLocale() is called immediately on module load for all platforms, causing iOS-specific native module code to execute unnecessarily.

Fix in Cursor Fix in Web