mashpie/i18n-node — Issue #12: WARN: No locale found - check the context of the call to $__?
Author: Fuitad
Created: 2011-11-24 17:15:12+00:00
State: open

I'm using i18n-node in combinaison with expressjs and jade and I've been the warning "WARN: No locale found - check the context of the call to $__?" on every strings since I've upgraded to 0.3.3.

The message comes from:

function translate(locale, singular, plural) {
if (locale === undefined) {
console.warn("WARN: No locale found - check the context of the call to $__?");
locale = defaultLocale;
}

Which is called by:

i18n.__ = function() {
var locale;
if (this && this.scope) {
locale = this.scope.locale;
}
var msg = translate(locale, arguments[0]);

A quick debug allowed me to see that *this.scope* is undefined and *this* is:

{ version: '0.3.3',
configure: [Function],
init: [Function],
__: [Function],
__n: [Function],
setLocale: [Function],
getLocale: [Function],
overrideLocaleFromQuery: [Function] }

Thanksfully, defaultLocale is always set to the correct locale so strings end up being translated correctly but I still wonder what I'm doing wrong in my integration.

The locale is set using:

i18n.setLocale(req, locale);

And I call the translation using:

app.locals({
__i : i18n.__,
__n : i18n.__n,
});

Any help will be greatly appreciated! Thanks :D.