kivitendo/js/kivi.js @ 3dc3b056
224291dd | Thomas Heck | namespace("kivi", function(ns) {
|
||
ns._localeLang = false;
|
||||
ns._locales = {};
|
||||
ns.t8 = function(text, params) {
|
||||
if( ns._localeLang ) {
|
||||
if( !ns._locales[ns._localeLang] ) {
|
||||
b0edfab2 | Thomas Heck | ns._locales[ns._localeLang] = {};
|
||
224291dd | Thomas Heck | jQuery.ajax({
|
||
65c30866 | Thomas Heck | url: "js/locale/"+ ns._localeLang +".js",
|
||
224291dd | Thomas Heck | async: false,
|
||
dataType: "json",
|
||||
success: function(res) {
|
||||
ns._locales[ns._localeLang] = res;
|
||||
},
|
||||
});
|
||||
}
|
||||
text = ns._locales[ns._localeLang][text] || text;
|
||||
}
|
||||
if( Object.prototype.toString.call( params ) === '[object Array]' ) {
|
||||
var len = params.length;
|
||||
for(var i=0; i<len; ++i) {
|
||||
var key = i + 1;
|
||||
var value = params[i];
|
||||
text = text.split("#"+ key).join(value);
|
||||
}
|
||||
}
|
||||
else if( typeof params == 'object' ) {
|
||||
for(var key in params) {
|
||||
var value = params[key];
|
||||
text = text.split("#{"+ key +"}").join(value);
|
||||
}
|
||||
}
|
||||
return text;
|
||||
};
|
||||
ns.initLocale = function(localeLang) {
|
||||
ns._localeLang = localeLang;
|
||||
};
|
||||
});
|