Skip to content

Commit

Permalink
Do not set default locale when a request is given as an argument.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlongley committed Aug 7, 2012
1 parent 5df241c commit d773772
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 7 additions & 3 deletions i18n.js
Expand Up @@ -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]) {
Expand All @@ -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);
};
Expand Down
2 changes: 2 additions & 0 deletions test/i18n.test.js
Expand Up @@ -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 () {
Expand Down

1 comment on commit d773772

@mashpie
Copy link

@mashpie mashpie commented on d773772 Aug 7, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point... but changes behavior and thus might break some implementations. let's rethink this a bit

Please sign in to comment.