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

Make register option works with parameters other than `object` types #101

Open acrodrig opened 7 years ago

acrodrig commented 7 years ago

Hi, I am using Loopback and I am trying to incorporate this module to my server. I was trying to use the register option to attach i18n functions to the application object (normally called app).

It did not work. Looking at the source code I found the following lines in the code:

// you may register helpers in global scope, up to you
if (typeof this.register === "object") {
    i18n.resMethods.forEach(function (method) {
        self.register[method] = self[method].bind(self);
    });
}

The I printed out typeof(app) and it turns out it's a function. Couple of comments/questions:

  1. Why should the module care that the this.register is an object?
  2. The code should not fail silently, it should give a warning so that we know what's going on