jeresig / i18n-node-2

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

Error Condition: Detecting when the ID is blank/undefined #93

Open dortamur opened 8 years ago

dortamur commented 8 years ago

I use Handlebars for templates, and in a few places, I use the syntax: {{__ stateid}}

The idea being that, whatever the value of stateid is, it looks up the i18n string. In some instances, stateid is undefined, and when encountered, it throws the error:

TypeError: /path/app/views/template.hbs: Cannot read property 'length' of undefined at dotNotation (/path/app/node_modules/i18n-2/i18n.js:23:15) at Object.i18n.translate (/path/app/node_modules/i18n-2/i18n.js:336:5) .....

Could a check be added to dotNotation(), such that if "is" is undefined, it fails more gracefully?

Thanks.

gjuchault commented 8 years ago

I don't really get the problem. Could you post a subset of your localization file and also explain a bit more?