From c279bffcafb71e503436ad4ecaee1ebc4d098ce7 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Pasquier Date: Wed, 21 Oct 2020 17:19:02 +0200 Subject: [PATCH] i18n: fallback to french --- src/locales/{en.json => fr.json} | 0 src/scripts/intl.js | 15 +++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) rename src/locales/{en.json => fr.json} (100%) diff --git a/src/locales/en.json b/src/locales/fr.json similarity index 100% rename from src/locales/en.json rename to src/locales/fr.json diff --git a/src/scripts/intl.js b/src/scripts/intl.js index 1b085b4..167794d 100644 --- a/src/scripts/intl.js +++ b/src/scripts/intl.js @@ -16,7 +16,7 @@ class JsI18n { this.setLocale(localStorage.getItem('language') || window.navigator.language.slice(0, 2)); } else { console.error('Language not found'); - this.setLocale('en'); + this.setLocale('fr'); } }; @@ -105,14 +105,21 @@ class JsI18n { result.json().then(e => { this.addLocale(locale, e); this.processPage(); + }).catch(() => { + if (locale != "fr") { + console.warn(`Locale not found: ${locale}, fallback to french`); + this.setLocale("fr"); + } else { + console.error("Language not found"); + } }); } }); this.locale = locale; } catch { - if (locale != "en") { - console.warn(`Locale not found: ${locale}, fallback to english`); - this.setLocale("en"); + if (locale != "fr") { + console.warn(`Locale not found: ${locale}, fallback to french`); + this.setLocale("fr"); } else { console.error("Language not found"); }