diff options
i18n helper fetchLocale handles 404 gracefully
Diffstat (limited to 'ui/i18n-helper.js')
-rw-r--r-- | ui/i18n-helper.js | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/ui/i18n-helper.js b/ui/i18n-helper.js index dc83f45c9..3ce24ddfb 100644 --- a/ui/i18n-helper.js +++ b/ui/i18n-helper.js @@ -25,10 +25,18 @@ const getMessage = (locale, key, substitutions) => { return phrase } -async function fetchLocale (localeName) { - const response = await fetch(`/_locales/${localeName}/messages.json`) - const locale = await response.json() - return locale +function fetchLocale (localeName) { + return new Promise((resolve, reject) => { + return fetch(`/_locales/${localeName}/messages.json`) + .then(response => response.json()) + .then( + locale => resolve(locale), + error => { + log.error(`failed to fetch ${localeName} locale because of ${error}`) + resolve({}) + } + ) + }) } module.exports = { |