Amit Kumar
Amit Kumar

Reputation: 417

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

I am able to this.props.t('id') function which return string translation for given id. Now, I have a requirement to get string translation for "Change value for " + (this.state !== null ? this.state.selectedData.length : 0) + " selected data". In this translation, I'll have to use a variable inside string translation. Is there any method such as : this.props.t('id', value)??

How can I get this working?

Thanks in Advance!

Upvotes: 0

Views: 796

Answers (1)

felixmosh
felixmosh

Reputation: 35573

Read docs, this called interpolation, you can set in your translation value:

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

And then call

this.props.t('MY_KEY', { value: this.state !== null ? this.state.selectedData.length : 0 });

Upvotes: 1

Related Questions