web-apps/apps/spreadsheeteditor/main/app/view/FormulaLang.js

58 lines
1.5 KiB
JavaScript
Raw Normal View History

2016-03-11 00:48:53 +00:00
define([
], function () {
'use strict';
SSE.Views = SSE.Views || {};
SSE.Views.FormulaLang = new(function() {
var langJson = {};
var _createXMLHTTPObject = function() {
var xmlhttp;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
};
var _get = function(lang) {
if (!lang) return '';
lang = lang.toLowerCase() ;
if (langJson[lang])
return langJson[lang];
else if (lang == 'en')
return undefined;
else {
try {
var xhrObj = _createXMLHTTPObject();
if (xhrObj && lang) {
xhrObj.open('GET', 'resources/formula-lang/' + lang + '.json', false);
xhrObj.send('');
langJson[lang] = eval("(" + xhrObj.responseText + ")");
return langJson[lang];
}
}
catch (e) {
}
}
return null;
};
return {
get: _get
};
})();
});