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:
parent
fc93e502b8
commit
3088115aba
@ -83,6 +83,7 @@ function mergeCatalog(fallback,catalog) {
|
|||||||
|
|
||||||
|
|
||||||
function readFile(lng, ns) {
|
function readFile(lng, ns) {
|
||||||
|
console.log(lng,ns);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (resourceCache[ns] && resourceCache[ns][lng]) {
|
if (resourceCache[ns] && resourceCache[ns][lng]) {
|
||||||
resolve(resourceCache[ns][lng]);
|
resolve(resourceCache[ns][lng]);
|
||||||
@ -120,10 +121,14 @@ var MessageFileLoader = {
|
|||||||
read: function (lng, ns, callback) {
|
read: function (lng, ns, callback) {
|
||||||
readFile(lng, ns)
|
readFile(lng, ns)
|
||||||
.then(data => callback(null, data))
|
.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')
|
// 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];
|
var baseLng = lng.split('-')[0];
|
||||||
readFile(baseLng, ns).then(baseData => callback(null, baseData)).catch(err => callback(err));
|
readFile(baseLng, ns).then(baseData => callback(null, baseData)).catch(err => callback(err));
|
||||||
|
} else {
|
||||||
|
callback(err);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user