martinandert / counterpart

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

Interpolations not working #11

Closed brian-c closed 9 years ago

brian-c commented 9 years ago

Seems to be unable to interpret %(key) here:

https://github.com/maritz/node-sprintf/blob/master/lib/sprintf.js#L199

I noticed that npm's sprintf module is deprecated in favor of sprintf-js. Haven't tried swapping it in, but it's probably worth a look.

To reproduce in Node,

counterpart = require('counterpart');
counterpart.registerTranslations('en', {foo: 'Foo is %(what).'});
counterpart('foo', {what: 'cool'});

results in

Error: [sprintf] %(what).
    at Function.str_format.parse (/node_modules/counterpart/node_modules/sprintf/lib/sprintf.js:231:11)
    at str_format (/node_modules/counterpart/node_modules/sprintf/lib/sprintf.js:75:48)
    at Counterpart._interpolate (/node_modules/counterpart/index.js:233:10)
    at Counterpart.translate (/node_modules/counterpart/index.js:129:18)
    at translate (/node_modules/counterpart/index.js:286:29)
    at repl:1:2
    at REPLServer.self.eval (repl.js:110:21)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.emit (events.js:95:17)
    at Interface._onLine (readline.js:202:10)
martinandert commented 9 years ago

You are using the wrong placeholder format. Instead of %(key) you have to use %(key)s. Notice the s at the end.

brian-c commented 9 years ago

Totally missed that. Works fine. Thanks!