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
13
packages/node_modules/@node-red/util/lib/i18n.js
vendored
13
packages/node_modules/@node-red/util/lib/i18n.js
vendored
@ -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(() => {
|
||||
// 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));
|
||||
.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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user