我希望我的应用程序支持多种语言,例如英语和中文。使用react native,我如何在手机上找到语言设置?
kqlmhetl1#
import { NativeModules, Platform } from 'react-native'; const deviceLanguage = Platform.OS === 'ios' ? NativeModules.SettingsManager.settings.AppleLocale || NativeModules.SettingsManager.settings.AppleLanguages[0] // iOS 13 : NativeModules.I18nManager.localeIdentifier; console.log(deviceLanguage); //en_US
pxyaymoc2#
尝试使用此库-〉https://github.com/AlexanderZaytsev/react-native-i18n
import I18n from 'react-native-i18n'; deviceLocale = I18n.currentLocale()
ssm49v7z3#
import { NativeModules, Platform } from 'react-native'; let deviceLanguage = Platform.OS === 'ios' ? NativeModules.SettingsManager.settings.AppleLocale: NativeModules.I18nManager.localeIdentifier; if (deviceLanguage === undefined) { // iOS 13 workaround, take first of AppleLanguages array deviceLanguage = NativeModules.SettingsManager.settings.AppleLanguages[0] if (deviceLanguage == undefined) { return defaultLocalization // default language } }
5anewei64#
您可以使用react-native-localize并获取当前用户的设备语言:
import * as RNLocalize from "react-native-localize"; console.log(RNLocalize.getLocales());
4条答案
按热度按时间kqlmhetl1#
pxyaymoc2#
尝试使用此库-〉https://github.com/AlexanderZaytsev/react-native-i18n
ssm49v7z3#
5anewei64#
您可以使用react-native-localize并获取当前用户的设备语言: