From 683c6a748ee510efb52848f37fd2018511f4f63d Mon Sep 17 00:00:00 2001 From: tot92 Date: Mon, 18 Nov 2019 20:45:48 +0100 Subject: [PATCH] switched loading order --- .../node_modules/@node-red/util/lib/i18n.js | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/packages/node_modules/@node-red/util/lib/i18n.js b/packages/node_modules/@node-red/util/lib/i18n.js index 39e4a2c1a..236b66306 100644 --- a/packages/node_modules/@node-red/util/lib/i18n.js +++ b/packages/node_modules/@node-red/util/lib/i18n.js @@ -118,19 +118,12 @@ var MessageFileLoader = { type: "backend", init: function (services, backendOptions, i18nextOptions) { }, read: function (lng, ns, callback) { - // there are two languages to consider: - // 1) the actual language lng (e. g. 'en-US' or 'de-DE', 'fr-FR',...) - // 2) the base language (e. g. 'en', 'de', 'fr',...) - var baseLng = lng.split('-')[0]; - // read base language (e. g. 'de'), then actual language (e. g. 'de-DE') - readFile(baseLng, ns).then( - baseData => { - // scenario 1: reading base language was successful -> read actual language -> if this fails, return base language data - readFile(lng, ns).then(data => callback(null, data), () => callback(null, baseData)) - }, - () => { - // scenario 2: reading base language failed -> read actual language -> if this fails too, return error - readFile(lng, ns).then(data => callback(null, data), err => callback(err)) + 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)); }); } }