Skip to content

Commit

Permalink
Allow defaultLocale to be supplied with opts. #90 (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
wallali authored and gjuchault committed Jun 9, 2017
1 parent b99fd69 commit 28a93b5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var i18n = module.exports = function (opt) {
self.readFile(locale);
});

this.defaultLocale = opt.locales[0];
this.defaultLocale = opt.defaultLocale || opt.locales[0];
}

// Set the locale to the default locale
Expand Down
23 changes: 23 additions & 0 deletions test/i18n.configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,29 @@ module.exports = {
assert.equal('de', i18n.getLocale(), 'should return the new setting');
},

'check set defaultLocale when no default supplied': function () {
var i18n = new I18n({
locales: ['en', 'de'],
directory: './testlocales',
extension: '.json'
});

var loc = i18n.getLocale();
assert.equal('en', i18n.getLocale(), 'should return first locale setting from locales');
},

'check set defaultLocale when default supplied': function () {
var i18n = new I18n({
locales: ['en', 'de'],
directory: './testlocales',
extension: '.json',
defaultLocale: 'de'
});

var loc = i18n.getLocale();
assert.equal('de', i18n.getLocale(), 'should return default locale setting');
},

'check singular': function () {
var i18n = new I18n({
locales: ['en', 'de'],
Expand Down

0 comments on commit 28a93b5

Please sign in to comment.