Browse files

basic testing, fix factory method

  • Loading branch information...
1 parent f49ab92 commit a64a977866a61380801b5e3162eb5ee4babe8b0c @OhaiBBQ committed Feb 9, 2011
Showing with 47 additions and 19 deletions.
  1. +5 −5 examples/templating.js
  2. +13 −14 lib/i18n.js
  3. +16 −0 test/locales/en.js
  4. +13 −0 test/test-i18n.js
View
10 examples/templating.js
@@ -5,13 +5,13 @@
* Time: 10:22:01 PM
* To change this template use File | Settings | File Templates.
*/
-
+/* TODO: Better examples */
var i18n = require("./../index").i18n,
instance = new i18n(__dirname + "/locales");
console.log(instance);
instance.load("en");
-console.log(instance.t("sup") === "hi"); // 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") === "testing hello"); // false
+console.log(instance.t("sup") === "hi"); // 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") === "testing hello"); // false
View
27 lib/i18n.js
@@ -10,9 +10,19 @@
var _ = require("underscore");
var I18n = function(path, language, locale) {
- this.path = path;
- this.language = language;
- this.locale = locale;
+ if(typeof arguments[0] === "object") {
+ arguments = Array.prototype.slice.call(arguments[0]);
+ }
+
+ 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) {
@@ -41,15 +51,4 @@ I18n.prototype.t = function(item, context) {
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;
View
16 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 %>"
+ }
+};
View
13 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.