From b774babfb991df4187c649e8d7500deac139e177 Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Tue, 8 Jan 2019 17:48:47 -0500 Subject: [PATCH] Reworking i18n error logging to make it less noisy Also changing locale loading error handling to make the backend retry on failure --- src/i18n.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/i18n.js b/src/i18n.js index 4aac2c3..7bb4e10 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -18,6 +18,10 @@ i18n saveMissing: true, saveMissingTo: 'current', missingKeyHandler: (lng, ns, key, fallback) => { + if (!i18n.getResourceBundle(lng)) { + return; // Don't bother logging if the resource bundle isn't loaded + } + const escapedKey = key.replace(/\\/g, '\\\\').replace(/"/g, '\\"'); // eslint-disable-next-line no-console if (console && console.group && console.log) { @@ -35,14 +39,14 @@ i18n backend: { loadPath: '{{lng}}', parse: data => data, - ajax: (lng, options, callback) => { + ajax: async (lng, options, callback) => { try { - import(`locales/${ lng }.yaml`).then( - locale => callback(locale, { status: '200' }), - () => callback(null, { status: '404' })); + const { default: locale } = await import(`locales/${ lng }.yaml`); + + callback(locale, { status: '200' }); } catch (e) { - callback(null, { status: '404' }); + callback(null, { status: '500' }); } } }