Skip to content

Commit

Permalink
basic testing, fix factory method
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Hansen committed Feb 9, 2011
1 parent f49ab92 commit a64a977
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 19 deletions.
10 changes: 5 additions & 5 deletions examples/templating.js
Expand Up @@ -5,13 +5,13 @@
* Time: 10:22:01 PM * Time: 10:22:01 PM
* To change this template use File | Settings | File Templates. * To change this template use File | Settings | File Templates.
*/ */

/* TODO: Better examples */
var i18n = require("./../index").i18n, var i18n = require("./../index").i18n,
instance = new i18n(__dirname + "/locales"); instance = new i18n(__dirname + "/locales");
console.log(instance); console.log(instance);
instance.load("en"); instance.load("en");


console.log(instance.t("sup") === "hi"); // true console.log(instance.t("sup") === "hi"); // true
console.log(instance.t("object.what.is") === "new"); // true console.log(instance.t("object.what.is") === "new"); // true
console.log(instance.t("object.value", { hi: "hello"}) === "testing hello"); // true console.log(instance.t("object.value" === { hi: "hello"}), "testing hello"); // true
console.log(instance.t("object.value") === "testing hello"); // false console.log(instance.t("object.value") === "testing hello"); // false
27 changes: 13 additions & 14 deletions lib/i18n.js
Expand Up @@ -10,9 +10,19 @@
var _ = require("underscore"); var _ = require("underscore");


var I18n = function(path, language, locale) { var I18n = function(path, language, locale) {
this.path = path; if(typeof arguments[0] === "object") {
this.language = language; arguments = Array.prototype.slice.call(arguments[0]);
this.locale = locale; }

this.path = arguments[0];
this.language = arguments[1];
this.locale = arguments[2];
};

I18n.factory = function(path, language, locale, instance) {
return (typeof instance !== "undefined")
? instance
: new I18n(arguments);
}; };


I18n.prototype.load = function(language) { I18n.prototype.load = function(language) {
Expand Down Expand Up @@ -41,15 +51,4 @@ I18n.prototype.t = function(item, context) {
return ret; return ret;
}; };


I18n.prototype.factory = function(path, language, locale, instance) {
return (typeof instance !== "undefined")
? instance
: new I18n(
arguments.slice(
0,
arguments.length - 2
)
);
};

module.exports = I18n; module.exports = I18n;
16 changes: 16 additions & 0 deletions test/locales/en.js
@@ -0,0 +1,16 @@
/**
* Created by .
* User: dan
* Date: Feb 8, 2011
* Time: 10:20:06 PM
* To change this template use File | Settings | File Templates.
*/
exports.all = {
"sup": "hi",
"object": {
"what": {
"is": "new"
},
"value": "testing <%= hi %>"
}
};
13 changes: 13 additions & 0 deletions test/test-i18n.js
@@ -0,0 +1,13 @@
/**
* Created by .
* User: dan
* Date: Feb 8, 2011
* Time: 11:59:33 PM
* To change this template use File | Settings | File Templates.
*/

var i18n = require("./../index").i18n;
exports["load"]["it does stuff"] = function() {


}

0 comments on commit a64a977

Please sign in to comment.