只是想知道是否有任何方法可以根据用户选择(而不是设备语言)使用 typescript 更改 expo 应用程序的语言。 我通读了世博会上的文档 https://docs.expo.io/versions/latest/sdk/localization/但上面似乎没有任何东西。
以下是我目前拥有的,它仅适用于设备设置语言。
import * as Localization from 'expo-localization';
import I18n from 'i18n-js';
// import translations
import en from './en.json'
import zh from './zh.json'
// bind translations to i18n
I18n.translations = {
en,
zh
}
// set phones language
const getLanguage = async() => {
try {
const choice = Localization.locale
I18n.locale = choice.substr(0, 2)
I18n.initAsync()
} catch (error) {
console.log(error)
}
}
getLanguage()
// export function
export function t(name: string) {
return I18n.t(name)
}
现在唯一的问题是我不知道如何根据用户输入传递语言。
最佳答案
尝试使用 i18next .它有 changeLanguage可用的 API。
关于typescript - 根据世博会上的用户选择更改语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63084398/