Skip to content

Commit

Permalink
Fixed: test can be run only from its own directory
Browse files Browse the repository at this point in the history
  • Loading branch information
naholyr committed Jan 31, 2011
1 parent ed3acae commit f634601
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 27 deletions.
21 changes: 10 additions & 11 deletions index.js
@@ -1,7 +1,13 @@
var http = require('http');

function defaultCallback(err) {
if (err) {
throw err;
}
}

function runCallback(err, callback) {
setTimeout(function() { callback(err, exports); }, 0);
setTimeout(function() { (callback || defaultCallback)(err, exports); }, 0);
return typeof err == 'undefined';
}

Expand Down Expand Up @@ -90,19 +96,12 @@ exports.setStore = function(store, config, callback) {
this.store = store;
}
if (typeof config != 'undefined') {
this.store.configure(config, callback);
return true;
return this.store.configure(config, callback || defaultCallback);
}
} catch (e) {
if (typeof callback != 'undefined') {
callback(e, this);
return false;
} else {
throw e;
}
return (callback || defaultCallback)(e, this.store);
}
callback(undefined, this);
return true;
return (callback || function(){return true;})(undefined, this);
};

function replaceParams(string, replacements) {
Expand Down
2 changes: 1 addition & 1 deletion stores/module.js
Expand Up @@ -88,7 +88,7 @@ exports.configure = function configure(options, callback) {
modules[name] = options.paths[name];
}
}
return callback(err, this);
return callback(undefined, this);
};

exports.locales = function locales(prefix, catalogue, callback) {
Expand Down
37 changes: 22 additions & 15 deletions test/index.js
@@ -1,23 +1,30 @@
var i18n = require('..');
var i18n = require(__dirname + '/..');

i18n.defaultLocale = 'fr';
i18n.debug();

i18n.load("messages", function(err, locales) {
i18n.setStore('module', {paths: {__default__: __dirname + '/i18n-data'}}, function(err) {
if (err) {
throw err;
}
console.log("Loaded locales", locales);
console.log(i18n.translate('x')); // x (en français)
console.log(i18n.translate('y')); // [T]y[/T]
i18n.debug(false);
console.log(i18n.translate('y')); // y
i18n.debug(true);
console.log(i18n.translate('x', 'en')); // x (in English)
for (var n=0; n<6; n++) {
console.log(i18n.plural('You have {n} messages', n, 'fr'));
}
console.log(i18n.translate('Hello, {name}', {name:'Jones', context:'male'})); // Bonjour, monsieur Jones
console.log(i18n.translate('Hello, {name}', {name:'Jones', context:'female'})); // Bonjour, mademoiselle Jones
console.log(i18n.translate('Hello, {name}', {name:'Jones', context:'unknown'})); // Bonjour, Jones
console.log("Configured store");
i18n.load("messages", function(err, locales) {
if (err) {
throw err.ALL || err;
}
console.log("Loaded locales", locales);
console.log(i18n.translate('x')); // x (en français)
console.log(i18n.translate('y')); // [T]y[/T]
i18n.debug(false);
console.log(i18n.translate('y')); // y
i18n.debug(true);
console.log(i18n.translate('x', 'en')); // x (in English)
for (var n=0; n<6; n++) {
console.log(i18n.plural('You have {n} messages', n, 'fr'));
}
console.log(i18n.translate('Hello, {name}', {name:'Jones', context:'male'})); // Bonjour, monsieur Jones
console.log(i18n.translate('Hello, {name}', {name:'Jones', context:'female'})); // Bonjour, mademoiselle Jones
console.log(i18n.translate('Hello, {name}', {name:'Jones', context:'unknown'})); // Bonjour, Jones
});
});

0 comments on commit f634601

Please sign in to comment.