app fabric有没有什么东西可以直接支持数据转换(注意:我不想要React的Intl,因为它是为了在渲染之前本地化数据)。我需要本地化状态中存在的数据,并使用转换后的数据更新状态。
React的intl旨在与组件一起使用,我需要对组件外部存在的数据进行转换。我不想使用createIntl模块,因为它需要手动提供区域设置和消息。
这就是我正在处理的代码。它存在于组件外部。
export function func () {
client.get (url, {}).then (
response => {
// handle error
}).then(data => {
// This is where i want to translate the data based on the locale i am in
// so that the data this translated data is present in the state
}
// error-handling, more code ...
}发布于 2021-11-08 06:32:30
您可以使用i18next将数据转换为纯js格式。
基本示例:
import i18next from 'i18next';
i18next.init({
lng: 'en', // if you're using a language detector, do not define the lng option
debug: true,
resources: {
en: {
translation: {
"key": "hello world"
}
}
}
});
// initialized and ready to go!
// i18next is already initialized, because the translation resources where passed via init function
document.getElementById('output').innerHTML = i18next.t('key');顺便说一下,为什么不在服务器端转换数据呢?您可能会遇到像export excel这样的情况,它可能也需要翻译。
https://stackoverflow.com/questions/69879248
复制相似问题