Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions packages/sdk/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"tsw": "yarn tsc --watch",
"start": "rimraf dist && yarn tsw",
"lint": "eslint . --ext .ts,.tsx",
"lint:fix": "eslint . --ext .ts,.tsx --fix",
"prettier": "prettier --write '**/*.@(js|ts|tsx|json|css)' --ignore-path ../../../.prettierignore",
"test": "jest",
"coverage": "yarn test --coverage",
Expand Down
20 changes: 13 additions & 7 deletions packages/sdk/react-native/src/platform/locale.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
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 localeIdentifier = Platform.select({
ios: () => {
const settings =
NativeModules.SettingsManager?.settings ??
NativeModules.SettingsManager?.getConstants()?.settings;
Copy link

Choose a reason for hiding this comment

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

Bug: Incorrect accessor path for getConstants() in Fabric

The fallback accessor NativeModules.SettingsManager?.getConstants()?.settings likely has an incorrect property path. In React Native's new Fabric architecture, getConstants() typically returns constants directly at the top level (e.g., {AppleLocale: 'en_US'}), not nested under a settings property. This means getConstants()?.settings would return undefined, causing AppleLocale to never be found even when available through getConstants(). The accessor likely needs to be getConstants()?.AppleLocale or getConstants() should replace the entire settings variable.

Fix in Cursor Fix in Web

return settings?.AppleLocale;
},
default: () => NativeModules.I18nManager?.localeIdentifier,
});

export default locale;
export default localeIdentifier();
Loading