1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Avoid unnecessary i18n catalog load if base lng provided

This commit is contained in:
Nick O'Leary 2019-11-21 10:42:40 +00:00
parent fc93e502b8
commit 3088115aba
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -83,6 +83,7 @@ function mergeCatalog(fallback,catalog) {
function readFile(lng, ns) {
console.log(lng,ns);
return new Promise((resolve, reject) => {
if (resourceCache[ns] && resourceCache[ns][lng]) {
resolve(resourceCache[ns][lng]);
@ -120,10 +121,14 @@ var MessageFileLoader = {
read: function (lng, ns, callback) {
readFile(lng, ns)
.then(data => callback(null, data))
.catch(() => {
.catch(err => {
if (/-/.test(lng)) {
// if reading language file fails -> try reading base language (e. g. 'fr' instead of 'fr-FR' or 'de' for 'de-DE')
var baseLng = lng.split('-')[0];
readFile(baseLng, ns).then(baseData => callback(null, baseData)).catch(err => callback(err));
} else {
callback(err);
}
});
}
}