Skip to content

Commit

Permalink
moved reading json to end of configure
Browse files Browse the repository at this point in the history
  • Loading branch information
mashpie committed Nov 26, 2011
1 parent 771e001 commit 7adef71
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 30 deletions.
17 changes: 10 additions & 7 deletions i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ var i18n = exports;
i18n.version = '0.3.4';

i18n.configure = function(opt) {
if (typeof opt.locales === 'object') {
opt.locales.forEach(function(l) {
read(l);
});
}

// you may register helpers in global scope, up to you
if (typeof opt.register === 'object') {
opt.register.__ = i18n.__;
Expand All @@ -47,12 +41,21 @@ i18n.configure = function(opt) {
// where to store json files
if (typeof opt.directory === 'string') {
directory = opt.directory;
}
}else{
directory = './locales';
}

// enabled some debug output
if (opt.debug) {
debug = opt.debug;
}

// implicitly read all locales
if (typeof opt.locales === 'object') {
opt.locales.forEach(function(l) {
read(l);
});
}
}

i18n.init = function(request, response, next) {
Expand Down
38 changes: 15 additions & 23 deletions test/i18n.configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,18 @@ var i18n = require('../i18n'),
debug: true
});

fs.rmdirSync('./testlocales');

// module.exports = {
// 'check set/getLocale': function(){
// var loc = i18n.getLocale();
// 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');
// },
//
// 'check singular': function(){
// i18n.setLocale('en');
// assert.equal(__('Hello'), 'Hello');
// assert.equal(__('Hello %s, how are you today?', 'Marcus'), 'Hello Marcus, how are you today?');
// assert.equal(__('Hello %s, how are you today? How was your %s.', 'Marcus', __('weekend')), 'Hello Marcus, how are you today? How was your weekend.');
// },
//
// 'check_directory': function(){
// fs.stat('./testlocales/de.js', function(err, stat) {
// assert.isNull(err, './testlocales/de.js should exist');
// });
// }
// };
module.exports = {
'check set/getLocale': function(){
var loc = i18n.getLocale();
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');
},

'check singular': function(){
i18n.setLocale('en');
assert.equal(__('Hello'), 'Hello');
assert.equal(__('Hello %s, how are you today?', 'Marcus'), 'Hello Marcus, how are you today?');
assert.equal(__('Hello %s, how are you today? How was your %s.', 'Marcus', __('weekend')), 'Hello Marcus, how are you today? How was your weekend.');
}
};

0 comments on commit 7adef71

Please sign in to comment.