如何通过I18Next传递参数?
我想翻译我的颜色,但是我是如何做的。
const Item = memo(({ color, index, lastIndex, translateName, style, activeColor, onPress }: IColorItem) => {
return (
<Text>{translateName}</Text>
)
// @ts-ignore
}, isEq);
const Colors = ({ colors, style, activeColor, onPress }: IColors) => {
const { t } = useTranslation();
const renderItem: ListRenderItem<ColorsType> = ({ item, index }) => (
<Item
color={item}
translateName={t('colors.color', { color: item })}
index={index}
style={style}
activeColor={activeColor}
lastIndex={colors.length - 1}
onPress={onPress}
/>
)
return (
<View style={s.container}>
<FlatList
data={colors as ColorsType[]}
renderItem={renderItem}
style={s.flatList}
keyExtractor={(item, i) => i.toString()}
horizontal
showsHorizontalScrollIndicator={false}
/>
</View>
)
}
transl.json
"colors": {
"color": "{{color, COLORS}}"
},
没什么可用。我怎么说“红色” = ...,“蓝色” = ...?
................................................................................. ................................................................................. ....................................................................................
I want to translate my colors but idk how I do it.
const Item = memo(({ color, index, lastIndex, translateName, style, activeColor, onPress }: IColorItem) => {
return (
<Text>{translateName}</Text>
)
// @ts-ignore
}, isEq);
const Colors = ({ colors, style, activeColor, onPress }: IColors) => {
const { t } = useTranslation();
const renderItem: ListRenderItem<ColorsType> = ({ item, index }) => (
<Item
color={item}
translateName={t('colors.color', { color: item })}
index={index}
style={style}
activeColor={activeColor}
lastIndex={colors.length - 1}
onPress={onPress}
/>
)
return (
<View style={s.container}>
<FlatList
data={colors as ColorsType[]}
renderItem={renderItem}
style={s.flatList}
keyExtractor={(item, i) => i.toString()}
horizontal
showsHorizontalScrollIndicator={false}
/>
</View>
)
}
transl.json
"colors": {
"color": "{{color, COLORS}}"
},
Nothing works. How can I say "red" = ..., "blue" = ... ?
................................................................................................................................................
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在I18N文档中看到插值:“ noreferrer”> https://www.i18next.com/translation-function.com/translation-function.com/translation-function.com/translation-function. /插值
You can see in the i18n documentation the interpolation: https://www.i18next.com/translation-function/interpolation
您可以使用这种方式:
在您的JSON中,
输出应为:
我的颜色是蓝色
you can use this way:
and in your json
the output should be:
my color is blue