mashpie / i18n-node

Lightweight simple translation module for node.js / express.js with dynamic json storage. Uses common __('...') syntax in app and templates.
MIT License
3.09k stars 420 forks source link

Problem when mixing sprintf / mustache #163

Closed rusel1989 closed 8 years ago

rusel1989 commented 9 years ago

i use object notation, but dunno if it's important, howewer i experienced some problems when mixing mustache / sprintf

If i call:

i18n.__.apply(null, ['errors.isLength', {path: 'something', value: 'interesting'}, 5, 90])

with following translation:

{
  "errors": {
    "isLength": "Length of field {{path}} ({{value}})  must be in range from %s to %s characters"
  }
}

i got following output:

"Length of field  ()  must be in range from [object Object] to 5 characters"
mashpie commented 9 years ago

@oliversalzburg: ever combined those features?

oliversalzburg commented 9 years ago

Humm, I have not. But I somewhat doubt that it's object notation related. Let's see if I can construct a small test case.

oliversalzburg commented 9 years ago

@rusel1989 In your scenario, you must place the mustache parameters as the last argument to __, like so:

var s = i18n.__.apply(null, ['errors.isLength', 5, 90, {path: 'something', value: 'interesting'}]);

I'm not sure if this is a documentation issue. But it doesn't seem like a bug. I wouldn't recommend mixing mustache and vsprintf though ;D

rusel1989 commented 9 years ago

Thank you very much for reply :+1: . Maybe u could mention that the order of arguments matters here: https://github.com/mashpie/i18n-node#mustache-support .

mashpie commented 9 years ago

@oliversalzburg: Thank you so much - I'll take care of doks :+1:

mashpie commented 8 years ago

It is (it was) a documentation issue, fixed that https://github.com/mashpie/i18n-node#mustache-support and added a test https://github.com/mashpie/i18n-node/blob/master/test/i18n.api.js#L94