martinandert / counterpart

A translation and localization library for Node.js and the browser.
MIT License
242 stars 25 forks source link

Issue when using interpolation with numbers #33

Closed maxmantz closed 8 years ago

maxmantz commented 8 years ago

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

Whoops wrong repo.. will move it.

yanndinendal commented 8 years ago

@maxmantz :

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

Yes: try 'Zeige Einträge %(start)d bis %(end)d von %(total)d'.

See: https://en.wikipedia.org/wiki/Printf_format_string#Type_field