Skip to content

Commit d69b38c

Browse files
committed
refactor: handling getDeviceLanguage
1 parent 6b20a0e commit d69b38c

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

lib/helpers/device/DeviceInfo.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import { Platform, Dimensions, NativeModules } from "react-native";
22

33
// i.e: en_US
4-
const getDeviceLanguage =
5-
Platform.OS === "ios"
6-
? NativeModules.SettingsManager.settings.AppleLocale ||
7-
NativeModules.SettingsManager.settings.AppleLanguages[0] //iOS 13
8-
: NativeModules.I18nManager.localeIdentifier;
4+
const getDeviceLanguage = () => {
5+
if (Platform.OS === "ios") {
6+
const settings = NativeModules.SettingsManager?.settings;
7+
const language = settings?.AppleLocale || settings?.AppleLanguages?.[0]; // iOS 13 and above
8+
return language ? language.replace("_", "-") : "en_US";
9+
} else if (Platform.OS === "android") {
10+
const locale = NativeModules.I18nManager?.localeIdentifier;
11+
return locale ? locale.replace("_", "-") : "en_US";
12+
}
13+
return "en_US";
14+
};
915

1016
// ? Screen Constants
1117
const Screen = Dimensions.get("screen");

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@freakycoder/react-native-helpers",
3-
"version": "2.3.0",
3+
"version": "2.4.0",
44
"description": "All helpers in one; iPhone series support, dimensions helper, hasNotch helper, normalize text helper and text helpers for React Native with very easy use",
55
"keywords": [
66
"ios",

0 commit comments

Comments
 (0)