i18n-node
i18n-node copied to clipboard
When user's locale is not in the supported locales, and setLocale(req,locale) is called, default locale is not loaded to the request
Example: Let's say the supported languages are ['en', 'fr'], and setLocale(req, 'he') is called.
The first condition won't apply (since locales[locale] isn't defined):
// called like setLocale(req, 'en')
if (locale_or_request && typeof locale === 'string' && locales[locale]) {
request = locale_or_request;
target_locale = locale;
}
And neither the second condition:
if (locale === undefined && typeof this.locale === 'string' && typeof locale_or_request === 'string') {
request = this;
target_locale = locale_or_request;
console.log("here2");
}
So target_locale will actually point to req, and request will be undefined.
And even if target_locale and request were defined correctly, the next part won't load the default_locale to the request (since locales[target_locale] is not defined):
if (locales[target_locale]) {
// called like setLocale('en')
if (request === undefined) {
defaultLocale = target_locale;
}
else {
request.locale = target_locale;
}
}
correct, defaultLocale get's applied in
function translate(locale, singular, plural) {
if (locale === undefined) {
logWarn("WARN: No locale found - check the context of the call to __(). Using " + defaultLocale + " as current locale");
locale = defaultLocale;
}
[...]
Can I suggest that it will set the locale for the request? That way you can tell which locale is actually being used, and use it in other places in the app. The behaviour is a bit inconsistent. If you use setLocale(req, locale) you expect the locale to be set in the request. Also, it's not very elegant that getLocale(request) is called with undefined.
sure, thx :)
mobil beantwortet
Am 27.04.2014 um 13:49 schrieb Itamar Weiss [email protected]:
Can I suggest that it will set the locale for the request? That way you can tell which locale is actually being used, and use it in other places in the app.
— Reply to this email directly or view it on GitHub.
+1