React Native获取ios设备语言

React Native获取ios设备语言

问题描述:

我想从ios设备获取当前语言环境。React Native获取ios设备语言

我跟着this guide当我创建我的项目,我用博览会。

我尝试下面的代码

if (Platform.OS === "android") { 
    langRegionLocale = NativeModules.I18nManager.localeIdentifier || ""; 
} else if (Platform.OS === "ios") { 
    langRegionLocale = NativeModules.SettingsManager.settings.AppleLocale || ""; 
} 

它的工作为Android,但是当在iPhone上测试,它没有工作,说设置管理是不确定的当我登录它。

如何获取ios 的当前语言环境而不弹出或使用AlexanderZaytsev/react-native-i18n

如果可能的话,我想使用内置的东西。

下面是我的package.json

{ 
    "name": "demoapp", 
    "version": "0.1.0", 
    "private": true, 
    "devDependencies": { 
    "react-native-scripts": "1.5.0", 
    "jest-expo": "^21.0.2", 
    "react-test-renderer": "16.0.0-alpha.12" 
    }, 
    "main": "./node_modules/react-native-scripts/build/bin/crna-entry.js", 
    "scripts": { 
    "start": "react-native-scripts start", 
    "eject": "react-native-scripts eject", 
    "android": "react-native-scripts android", 
    "ios": "react-native-scripts ios", 
    "test": "node node_modules/jest/bin/jest.js --watch" 
    }, 
    "jest": { 
    "preset": "jest-expo" 
    }, 
    "dependencies": { 
    "expo": "^21.0.0", 
    "react": "16.0.0-alpha.12", 
    "react-native": "^0.48.4", 
    "react-navigation": "^1.0.0-beta.13", 
    "react-redux": "^5.0.6", 
    "redux": "^3.7.2", 
    "redux-thunk": "^2.2.0" 
    } 
} 

世博Util API有越来越装置语言环境的方法。

Expo.Util.getCurrentLocaleAsync()

返回当前设备 区域设置为一个字符串。