Skip to content

Commit

Permalink
intl working, testing almost done
Browse files Browse the repository at this point in the history
  • Loading branch information
luiseduardobrito committed Sep 25, 2013
1 parent a12e48d commit f4f1aed
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
26 changes: 20 additions & 6 deletions language/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
var config = require("../config/general");
var fs = require("fs");
var path = require("path");
var vsprintf = require("format").vsprintf;

var Language = function(default_lang) {

var exports = {};
var lang = null;

var get = function(lang) {
var get = function(_lang) {

try {

dict = require("./" + lang);
lang = _lang;

if(fs.existsSync(path.join(__dirname, lang + ".js")))
dict = require("./" + lang);

else if(fs.existsSync(path.join(__dirname, lang + ".json")))
dict = require("./" + lang + ".json");

else
throw new Error();
}
catch(e) {

Expand Down Expand Up @@ -51,27 +63,29 @@ var Language = function(default_lang) {

var getDefault = function() {

var lang = config.language ||
var _lang = config.language ||
config.lang ||
config.i18n ||
config.locale;

try {

if(!lang)
if(!_lang)
throw new Error();

return require("./" + lang);
lang = _lang;
return get(lang);
}

catch(e) {

throw new Error("The default language could not be found or is not specified.");
throw e;
}

}; exports.getDefault = getDefault;

var init = function() {
lang = default_lang || getDefault();
return exports;
}

Expand Down
3 changes: 3 additions & 0 deletions language/simple.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"response": "success"
}

0 comments on commit f4f1aed

Please sign in to comment.