martinandert / counterpart

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

Update so local can override global interpolate #20

Closed agirton-twitter closed 9 years ago

agirton-twitter commented 9 years ago

In our application 99% of the strings we are using are static. In these strings there are percent signs, if we set interpolation to false globally we don't have a problem. However if we set it to true even the strings without interpolation are trying to be parsed so 27% throws an error from sprintf.

Our fix is to have a few of the function calls that need interpolation to set the option to true. So we can still have it globally turned off.

Also fixed a test on line 329 in that the second assert should be interpolated if the local is set to true.

Love to know your thoughts on this.

martinandert commented 9 years ago

Counterpart uses the sprintf module for interpolation. Sprintf allows you to use two percent signs (%%) as escape sequence for a percent sign. So this works:

sprintf = require('sprintf').sprintf;
sprintf("foo %(name)s bar 27%% bam", { name: "baz" }); // => 'foo baz bar 27% bam'

Does that help?

agirton-twitter commented 9 years ago

That works for me. Thanks!