react-i18nextfunction this.props.t('id',value)

问题描述 投票:0回答:1

我能够使用this.props.t('id')函数,该函数返回给定ID的字符串翻译。现在,我需要获取"Change value for " + (this.state !== null ? this.state.selectedData.length : 0) + " selected data"的字符串翻译。在此翻译中,我将不得不在字符串翻译中使用变量。有没有这样的方法:this.props.t('id',value)??

我如何使它工作?

预先感谢!

react-native localization i18next react-18next
1个回答
0
投票

阅读文档,此文件名为interpolation,您可以设置翻译值:

{
  ...
  "MY_KEY": "Change value for {{value}} selected data" 
  ..
}

然后致电

this.props.t('MY_KEY', { value: this.state !== null ? this.state.selectedData.length : 0 });
© www.soinside.com 2019 - 2024. All rights reserved.