Provide single endpoint to load all node message catalogs

Replaces potentially dozens of http requests with one or two.
This commit is contained in:
Nick O'Leary
2017-04-21 11:49:35 +01:00
parent bb2649d063
commit 7bd0943412
5 changed files with 46 additions and 22 deletions

View File

@@ -19,7 +19,7 @@ RED.i18n = (function() {
return {
init: function(done) {
i18n.init({
resGetPath: 'locales/__ns__',
resGetPath: 'locales/__ns__?lng=__lng__',
dynamicLoad: false,
load:'current',
ns: {
@@ -38,6 +38,31 @@ RED.i18n = (function() {
},
loadCatalog: function(namespace,done) {
i18n.loadNamespace(namespace,done);
},
loadNodeCatalogs: function(done) {
var languageList = i18n.functions.toLanguages(i18n.detectLanguage());
var toLoad = languageList.length;
languageList.forEach(function(lang) {
$.ajax({
headers: {
"Accept":"application/json"
},
cache: false,
url: 'locales/nodes?lng='+lang,
success: function(data) {
var namespaces = Object.keys(data);
namespaces.forEach(function(ns) {
i18n.addResourceBundle(lang,ns,data[ns]);
});
toLoad--;
if (toLoad === 0) {
done();
}
}
});
})
}
}
})();

View File

@@ -24,22 +24,7 @@
url: 'nodes',
success: function(data) {
RED.nodes.setNodeList(data);
var nsCount = 0;
for (var i=0;i<data.length;i++) {
var ns = data[i];
if (ns.module != "node-red") {
nsCount++;
RED.i18n.loadCatalog(ns.id, function() {
nsCount--;
if (nsCount === 0) {
loadNodes();
}
});
}
}
if (nsCount === 0) {
loadNodes();
}
RED.i18n.loadNodeCatalogs(loadNodes);
}
});
}