gpt4 book ai didi

typescript - 根据世博会上的用户选择更改语言

转载 作者:行者123 更新时间:2023-12-05 07:03:54 24 4
gpt4 key购买 nike

只是想知道是否有任何方法可以根据用户选择(而不是设备语言)使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com