gpt4 book ai didi

translation - 如何使用 i18next 在嵌套翻译中应用格式化程序

转载 作者:行者123 更新时间:2023-12-04 11:04:19 27 4
gpt4 key购买 nike

我想用 i18next 格式化嵌套翻译
鉴于资源:

{
translation: {
en: {
food: 'bread',
food_is_good: "$t(food), that's not bad",
},
},
}
和格式化功能:
function format(value, format, lng) {
if (value == undefined) return value;
switch (format) {
case 'capitalize':
return _.capitalize(value);
default:
return value;
}
}
用于 i18next 的初始化:
...
interpolation: { format: format },
...
我希望输出是“面包,还不错”。
所以我希望是这样的:
{
...
"food_is_good_1" : "$t(food,capitalize), that's not bad",
"food_is_good_2" : "{{$t(food),capitalize}}, that's not bad",
"food_is_good_3" : "{{food,capitalize}}, that's not bad",
...
}
会做的伎俩。
第一个选项显示错误: "failed parsing options string in nesting"最后两个选项警告: missed to pass in variable food,capitalize for interpolating {{food,capitalize}}

最佳答案

您的第一个选项适用于最新的 i18next (v19)。
https://codesandbox.io/s/react-i18next-forked-g1d47?file=/src/i18n.js

关于translation - 如何使用 i18next 在嵌套翻译中应用格式化程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38867564/

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