[SSE] asynchronous load translation for formulas
This commit is contained in:
parent
2a085c01c8
commit
325667e072
|
@ -64,6 +64,12 @@ define([
|
||||||
'FileMenu': {
|
'FileMenu': {
|
||||||
'settings:apply': function() {
|
'settings:apply': function() {
|
||||||
me.needUpdateFormula = true;
|
me.needUpdateFormula = true;
|
||||||
|
|
||||||
|
var lang = Common.localStorage.getItem("sse-settings-func-locale");
|
||||||
|
Common.Utils.InternalSettings.set("sse-settings-func-locale", lang);
|
||||||
|
|
||||||
|
me.formulasGroups.reset();
|
||||||
|
me.reloadTranslations(lang);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -73,7 +79,8 @@ define([
|
||||||
this.api = api;
|
this.api = api;
|
||||||
|
|
||||||
if (this.formulasGroups && this.api) {
|
if (this.formulasGroups && this.api) {
|
||||||
this.loadingFormulas();
|
this.reloadTranslations(
|
||||||
|
Common.localStorage.getItem("sse-settings-func-locale") || this.appOptions.lang );
|
||||||
|
|
||||||
var me = this;
|
var me = this;
|
||||||
|
|
||||||
|
@ -82,7 +89,7 @@ define([
|
||||||
toolclose : 'hide',
|
toolclose : 'hide',
|
||||||
formulasGroups : this.formulasGroups,
|
formulasGroups : this.formulasGroups,
|
||||||
handler : function (func) {
|
handler : function (func) {
|
||||||
if (func && me.api) {
|
if (func) {
|
||||||
me.api.asc_insertFormula(func, Asc.c_oAscPopUpSelectorType.Func);
|
me.api.asc_insertFormula(func, Asc.c_oAscPopUpSelectorType.Func);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,10 +97,8 @@ define([
|
||||||
|
|
||||||
this.formulas.on({
|
this.formulas.on({
|
||||||
'hide': function () {
|
'hide': function () {
|
||||||
if (me.api) {
|
|
||||||
me.api.asc_enableKeyEvents(true);
|
me.api.asc_enableKeyEvents(true);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,19 +106,48 @@ define([
|
||||||
},
|
},
|
||||||
|
|
||||||
setMode: function(mode) {
|
setMode: function(mode) {
|
||||||
this.mode = mode;
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
onLaunch: function () {
|
onLaunch: function () {
|
||||||
this.formulasGroups = this.getApplication().getCollection('FormulaGroups');
|
this.formulasGroups = this.getApplication().getCollection('FormulaGroups');
|
||||||
|
|
||||||
|
Common.Gateway.on('init', this.loadConfig.bind(this));
|
||||||
|
},
|
||||||
|
|
||||||
|
loadConfig: function(data) {
|
||||||
|
this.appOptions = {};
|
||||||
|
this.appOptions.lang = data.config.lang;
|
||||||
|
},
|
||||||
|
|
||||||
|
reloadTranslations: function (lang) {
|
||||||
|
var me = this;
|
||||||
|
lang = (lang || 'en').split(/[\-_]/)[0].toLowerCase();
|
||||||
|
|
||||||
|
if ( lang != 'en' ) {
|
||||||
|
Common.Utils.InternalSettings.set("sse-settings-func-locale", lang);
|
||||||
|
Common.Utils.loadConfig('resources/formula-lang/' + lang + '.json',
|
||||||
|
function (config) {
|
||||||
|
if ( config != 'error' )
|
||||||
|
me.api.asc_setLocalization(config);
|
||||||
|
});
|
||||||
|
} else me.api.asc_setLocalization(undefined);
|
||||||
|
|
||||||
|
Common.Utils.loadConfig('resources/formula-lang/' + lang + '_desc.json',
|
||||||
|
function (config) {
|
||||||
|
if ( config != 'error' )
|
||||||
|
me.loadingFormulas(config);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
showDialog: function () {
|
showDialog: function () {
|
||||||
if (this.formulas) {
|
if (this.formulas) {
|
||||||
if (this.needUpdateFormula)
|
if ( this.needUpdateFormula ) {
|
||||||
this.updateFormulas();
|
|
||||||
this.needUpdateFormula = false;
|
this.needUpdateFormula = false;
|
||||||
|
|
||||||
|
this.formulas.fillFormulasGroups();
|
||||||
|
this.formulas.fillFunctions('All');
|
||||||
|
}
|
||||||
this.formulas.show();
|
this.formulas.show();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -123,7 +157,7 @@ define([
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
loadingFormulas: function () {
|
loadingFormulas: function (descrarr) {
|
||||||
var i = 0, j = 0,
|
var i = 0, j = 0,
|
||||||
ascGroupName,
|
ascGroupName,
|
||||||
ascFunctions,
|
ascFunctions,
|
||||||
|
@ -137,8 +171,6 @@ define([
|
||||||
allFunctionsGroup = null;
|
allFunctionsGroup = null;
|
||||||
|
|
||||||
if (store) {
|
if (store) {
|
||||||
var value = SSE.Views.FormulaLang.getDescription(Common.Utils.InternalSettings.get("sse-settings-func-locale"));
|
|
||||||
|
|
||||||
allFunctionsGroup = new SSE.Models.FormulaGroup ({
|
allFunctionsGroup = new SSE.Models.FormulaGroup ({
|
||||||
name : 'All',
|
name : 'All',
|
||||||
index : index,
|
index : index,
|
||||||
|
@ -172,8 +204,8 @@ define([
|
||||||
index : funcInd,
|
index : funcInd,
|
||||||
group : ascGroupName,
|
group : ascGroupName,
|
||||||
name : ascFunctions[j].asc_getLocaleName(),
|
name : ascFunctions[j].asc_getLocaleName(),
|
||||||
args : (value && value[funcname]) ? value[funcname].a : '',
|
args : (descrarr && descrarr[funcname]) ? descrarr[funcname].a : '',
|
||||||
desc : (value && value[funcname]) ? value[funcname].d : ''
|
desc : (descrarr && descrarr[funcname]) ? descrarr[funcname].d : ''
|
||||||
});
|
});
|
||||||
|
|
||||||
funcInd += 1;
|
funcInd += 1;
|
||||||
|
@ -190,15 +222,6 @@ define([
|
||||||
_.sortBy(allFunctions, function (model) {return model.get('name'); }));
|
_.sortBy(allFunctions, function (model) {return model.get('name'); }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
updateFormulas: function () {
|
|
||||||
this.formulasGroups.reset();
|
|
||||||
this.loadingFormulas();
|
|
||||||
if (this.formulas.$window) {
|
|
||||||
this.formulas.fillFormulasGroups();
|
|
||||||
this.formulas.fillFunctions('All');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -375,11 +375,6 @@ define([
|
||||||
this.api.asc_setAutoSaveGap(value);
|
this.api.asc_setAutoSaveGap(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
value = Common.localStorage.getItem("sse-settings-func-locale");
|
|
||||||
Common.Utils.InternalSettings.set("sse-settings-func-locale", value);
|
|
||||||
if (value) value = SSE.Views.FormulaLang.get(value);
|
|
||||||
if (value!==null) this.api.asc_setLocalization(value);
|
|
||||||
|
|
||||||
value = Common.localStorage.getItem("sse-settings-reg-settings");
|
value = Common.localStorage.getItem("sse-settings-reg-settings");
|
||||||
if (value!==null) this.api.asc_setLocale(parseInt(value));
|
if (value!==null) this.api.asc_setLocale(parseInt(value));
|
||||||
|
|
||||||
|
|
|
@ -54,8 +54,7 @@ define([
|
||||||
'spreadsheeteditor/main/app/collection/ShapeGroups',
|
'spreadsheeteditor/main/app/collection/ShapeGroups',
|
||||||
'spreadsheeteditor/main/app/collection/TableTemplates',
|
'spreadsheeteditor/main/app/collection/TableTemplates',
|
||||||
'spreadsheeteditor/main/app/collection/EquationGroups',
|
'spreadsheeteditor/main/app/collection/EquationGroups',
|
||||||
'spreadsheeteditor/main/app/controller/FormulaDialog',
|
'spreadsheeteditor/main/app/controller/FormulaDialog'
|
||||||
'spreadsheeteditor/main/app/view/FormulaLang'
|
|
||||||
], function () {
|
], function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
@ -318,18 +317,6 @@ define([
|
||||||
this.api.asc_setLocale((this.editorConfig.lang) ? parseInt(Common.util.LanguageInfo.getLocalLanguageCode(this.editorConfig.lang)) : 0x0409);
|
this.api.asc_setLocale((this.editorConfig.lang) ? parseInt(Common.util.LanguageInfo.getLocalLanguageCode(this.editorConfig.lang)) : 0x0409);
|
||||||
}
|
}
|
||||||
|
|
||||||
value = Common.localStorage.getItem("sse-settings-func-locale");
|
|
||||||
if (value===null) {
|
|
||||||
var lang = ((this.editorConfig.lang) ? this.editorConfig.lang : 'en').split(/[\-\_]/)[0].toLowerCase();
|
|
||||||
Common.Utils.InternalSettings.set("sse-settings-func-locale", lang);
|
|
||||||
if (lang !== 'en')
|
|
||||||
value = SSE.Views.FormulaLang.get(lang);
|
|
||||||
} else {
|
|
||||||
Common.Utils.InternalSettings.set("sse-settings-func-locale", value);
|
|
||||||
value = SSE.Views.FormulaLang.get(value);
|
|
||||||
}
|
|
||||||
if (value) this.api.asc_setLocalization(value);
|
|
||||||
|
|
||||||
value = Common.localStorage.getBool("sse-settings-r1c1");
|
value = Common.localStorage.getBool("sse-settings-r1c1");
|
||||||
Common.Utils.InternalSettings.set("sse-settings-r1c1", value);
|
Common.Utils.InternalSettings.set("sse-settings-r1c1", value);
|
||||||
this.api.asc_setR1C1Mode(value);
|
this.api.asc_setR1C1Mode(value);
|
||||||
|
|
|
@ -1,123 +0,0 @@
|
||||||
/*
|
|
||||||
*
|
|
||||||
* (c) Copyright Ascensio System SIA 2010-2019
|
|
||||||
*
|
|
||||||
* This program is a free software product. You can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
|
||||||
* version 3 as published by the Free Software Foundation. In accordance with
|
|
||||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
|
||||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
|
||||||
* of any third-party rights.
|
|
||||||
*
|
|
||||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
|
||||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
|
||||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
|
||||||
*
|
|
||||||
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
|
|
||||||
* street, Riga, Latvia, EU, LV-1050.
|
|
||||||
*
|
|
||||||
* The interactive user interfaces in modified source and object code versions
|
|
||||||
* of the Program must display Appropriate Legal Notices, as required under
|
|
||||||
* Section 5 of the GNU AGPL version 3.
|
|
||||||
*
|
|
||||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
|
||||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
|
||||||
* grant you any rights under trademark law for use of our trademarks.
|
|
||||||
*
|
|
||||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
|
||||||
* well as technical writing content are licensed under the terms of the
|
|
||||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
|
||||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
define([
|
|
||||||
], function () {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
SSE.Views = SSE.Views || {};
|
|
||||||
|
|
||||||
SSE.Views.FormulaLang = new(function() {
|
|
||||||
var langJson = {},
|
|
||||||
langDescJson = {};
|
|
||||||
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
var _getDescription = function(lang) {
|
|
||||||
if (!lang) return '';
|
|
||||||
lang = lang.toLowerCase() ;
|
|
||||||
|
|
||||||
if (langDescJson[lang])
|
|
||||||
return langDescJson[lang];
|
|
||||||
else {
|
|
||||||
try {
|
|
||||||
var xhrObj = _createXMLHTTPObject();
|
|
||||||
if (xhrObj && lang) {
|
|
||||||
xhrObj.open('GET', 'resources/formula-lang/' + lang + '_desc.json', false);
|
|
||||||
xhrObj.send('');
|
|
||||||
if (xhrObj.status==200 ||
|
|
||||||
(xhrObj.status==0 && !!xhrObj.responseURL && xhrObj.responseURL.startsWith('file://')))
|
|
||||||
langDescJson[lang] = eval("(" + xhrObj.responseText + ")");
|
|
||||||
else {
|
|
||||||
xhrObj.open('GET', 'resources/formula-lang/en_desc.json', false);
|
|
||||||
xhrObj.send('');
|
|
||||||
langDescJson[lang] = eval("(" + xhrObj.responseText + ")");
|
|
||||||
}
|
|
||||||
return langDescJson[lang];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
get: _get,
|
|
||||||
getDescription: _getDescription
|
|
||||||
};
|
|
||||||
})();
|
|
||||||
});
|
|
Loading…
Reference in a new issue