Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__(...) with locale specified comes to an error #68

Closed
kamikat opened this issue Jul 4, 2013 · 2 comments
Closed

__(...) with locale specified comes to an error #68

kamikat opened this issue Jul 4, 2013 · 2 comments
Assignees

Comments

@kamikat
Copy link

kamikat commented Jul 4, 2013

When I use __(...) with specified locale

i18n.__({phrase: 'Have you ever met %s?', locale: 'zh_CN'}, 'Ted');

Error occurred

TypeError: Object #<Object> has no method 'substring'
    at Function.str_format.parse (/opt/stub/node_modules/i18n/node_modules/sprintf/lib/sprintf.js:175:16)
    at str_format (/opt/stub/node_modules/i18n/node_modules/sprintf/lib/sprintf.js:75:48)
    at vsprintf (/opt/stub/node_modules/i18n/node_modules/sprintf/lib/sprintf.js:185:17)
    at Object.i18nTranslate [as __] (/opt/stub/node_modules/i18n/i18n.js:88:11)
    at repl:1:6
    at REPLServer.self.eval (repl.js:111:21)
    at rli.on.e (repl.js:260:20)
    at REPLServer.self.eval (repl.js:118:5)
    at Interface.<anonymous> (repl.js:250:12)
    at Interface.EventEmitter.emit (events.js:93:17)

Am I misunderstanding the document? or, shall I use the latest version from github instead of a package from npm?


Edit

Found that code in package from npm for __(...)

i18n.__ = function i18nTranslate(phrase) {
  // get translated message with locale from scope (deprecated) or object
  var msg = translate(getLocaleFromObject(this), phrase);

  // if we have extra arguments with strings to get replaced,
  // an additional substition injects those strings afterwards
  if (arguments.length > 1) {
    msg = vsprintf(msg, Array.prototype.slice.call(arguments, 1));
  }
  return msg;
};

and the package.json file

{
  "name": "i18n",
  "description": "lightweight simple translation module with dynamic json storage",
  "version": "0.4.0",
  "homepage": "http://github.com/mashpie/i18n-node",
  "repository": {
    "type": "git",
    "url": "http://github.com/mashpie/i18n-node.git"
  },  
  "author": {
    "name": "Marcus Spiegel",
    "email": "marcus.spiegel@gmail.com"
  },  
  "main": "./index",
  "keywords": [
    "template",
    "i18n",
    "l10n"
  ],  
  ...
}

Maybe the package on NPM is broken?

@mashpie
Copy link
Owner

mashpie commented Jul 4, 2013

npm version is quite outdated. Shame on me, I planed to release some more features to npm earlier. Time passed and I will publish current git version on friday after a a last review.

@ghost ghost assigned mashpie Jul 4, 2013
@kamikat
Copy link
Author

kamikat commented Jul 4, 2013

check out the latest version from github makes it work. Thanks : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants