Permalink
Browse files

Do not set default locale when a request is given as an argument.

  • Loading branch information...
1 parent 5df241c commit d773772b90e727043d191df57e1e4fafea42485d @dlongley dlongley committed Aug 7, 2012
Showing with 9 additions and 3 deletions.
  1. +7 −3 i18n.js
  2. +2 −0 test/i18n.test.js
View
10 i18n.js
@@ -110,7 +110,7 @@ i18n.__n = function () {
// setLocale('en') or like
// setLocale(req, 'en')
i18n.setLocale = function (arg1, arg2) {
- var request = {},
+ var request = undefined,
target_locale = arg1;
if (arg2 && locales[arg2]) {
@@ -119,8 +119,12 @@ i18n.setLocale = function (arg1, arg2) {
}
if (locales[target_locale]) {
- request.locale = target_locale;
- defaultLocale = target_locale;
+ if (request === undefined) {
+ defaultLocale = target_locale;
+ }
+ else {
+ request.locale = target_locale;
+ }
}
return i18n.getLocale(request);
};
View
2 test/i18n.test.js
@@ -20,6 +20,8 @@ module.exports = {
assert.equal('en', i18n.getLocale(), 'should return default setting');
assert.equal('de', i18n.setLocale('de'), 'should return the new setting');
assert.equal('de', i18n.getLocale(), 'should return the new setting');
+ assert.equal('en', i18n.setLocale({}, 'en'), 'should return the request setting');
+ assert.equal('de', i18n.getLocale(), 'should return the previous default setting');
},
'check singular': function () {

0 comments on commit d773772

Please sign in to comment.