martinandert / react-translate-component

A component for React that utilizes the Counterpart module to provide multi-lingual/localized text content.
MIT License
322 stars 31 forks source link

Problem when interpolating numbers #17

Closed maxmantz closed 8 years ago

maxmantz commented 8 years ago

Finally in the correct repo. Here is my issue. I have the following setup for a table footer with pagination info:

Translations:

app: {
  footer: 'Zeige Einträge %(start)s bis %(end)s von %(total)s'
}

I use the component like this:

<Translate content="app.footer"
  start={this.state.skip + 1}
  end={this.state.skip + this.state.top}
  total={this.state.total}
/>

The translation works perfectly on first load, but when I change the values for either top or skip the calculation fails, instead the numbers get concatenated like strings. See screenshot: screenshot

Am I missing something? Is there a possibility to interpolate as a number, like %(start)n instead of %(start)s?

maxmantz commented 8 years ago

The problem was simple: I've used an input to change the values. The input returns a string value. So instead of adding numbers I was always adding strings. Problem solved. Sorry for the troubles :)