Comparing version 1.3.0 to 1.4.0
{ | ||
"name": "i18njs", | ||
"main": "i18njs.js", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"homepage": "https://github.com/yoannmoinet/i18njs", | ||
@@ -6,0 +6,0 @@ "authors": [ |
@@ -68,3 +68,3 @@ if (typeof exports === 'object' && typeof define !== 'function') { | ||
source += "';\n"; | ||
source = 'with(obj){\n' + source + '}\n'; | ||
source = 'with(obj||{}){\n' + source + '}\n'; | ||
source = "var __t,__p='',__j=Array.prototype.join," + | ||
@@ -97,3 +97,3 @@ "print=function(){__p+=__j.call(arguments,'');};\n" + | ||
this.lng = lng; | ||
this.string = {}; | ||
this.dico = {}; | ||
this.evaluate = /\{\{([\s\S]+?)\}\}/g; | ||
@@ -105,3 +105,3 @@ this.interpolate = /\{\{=([\s\S]+?)\}\}/g; | ||
var i; | ||
this.string[lang] = this.string[lang] || {}; | ||
this.dico[lang] = this.dico[lang] || {}; | ||
@@ -111,6 +111,6 @@ if (locales === undefined) { | ||
ns = undefined; | ||
obj = this.string[lang]; | ||
obj = this.dico[lang]; | ||
} else { | ||
this.string[lang][ns] = this.string[lang][ns] || {}; | ||
obj = this.string[lang][ns]; | ||
this.dico[lang][ns] = this.dico[lang][ns] || {}; | ||
obj = this.dico[lang][ns]; | ||
} | ||
@@ -124,7 +124,5 @@ for (i in locales) { | ||
this.has = function (key, lang) { | ||
var keyToParse = key; | ||
if (lang) { | ||
keyToParse = lang + '.' + keyToParse; | ||
} | ||
return parse(keyToParse, this.string) ? true : false; | ||
lang = lang || this.lng; | ||
var keyToParse = lang + '.' + key; | ||
return parse(keyToParse, this.dico) ? true : false; | ||
}; | ||
@@ -136,2 +134,3 @@ this.get = function (key, data, options, lang) { | ||
lng = data; | ||
data = undefined; | ||
} else if (typeof options === 'string') { | ||
@@ -141,5 +140,5 @@ lng = options; | ||
} | ||
var obj = parse(lng + '.' + key, this.string); | ||
var obj = parse(lng + '.' + key, this.dico); | ||
options = options || {}; | ||
if (obj && typeof data === 'object') { | ||
if (typeof obj === 'string') { | ||
var settings = { | ||
@@ -151,4 +150,5 @@ evaluate: options.evaluate || this.evaluate, | ||
obj = template(obj, settings)(data); | ||
return obj; | ||
} | ||
return obj || key; | ||
return key; | ||
}; | ||
@@ -155,0 +155,0 @@ }; |
{ | ||
"name": "i18njs", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "A simple i18n for Javascript with a templating feature.", | ||
"main": "i18njs.js", | ||
"scripts": { | ||
"test": "./node_modules/.bin/jasmine" | ||
}, | ||
"repository": { | ||
@@ -20,3 +23,6 @@ "type": "git", | ||
}, | ||
"homepage": "https://github.com/yoannmoinet/i18njs" | ||
"homepage": "https://github.com/yoannmoinet/i18njs", | ||
"devDependencies": { | ||
"jasmine": "^2.2.1" | ||
} | ||
} |
25743
9
256
1