aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/i18n.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/i18n.js')
-rw-r--r--src/lib/i18n.js10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/lib/i18n.js b/src/lib/i18n.js
index 0600a2a8..4cbb9a5d 100644
--- a/src/lib/i18n.js
+++ b/src/lib/i18n.js
@@ -6,6 +6,9 @@ const localeCodes = ['en', 'fr'];
// The directory where locale files are stored
const localeDirectory = "../locales";
+// the default locale to use if none was found
+const defaultLocale = "en";
+
// Adds a new locale based on its code
function addLocale(localeCode) {
register(localeCode, () => import(`${localeDirectory}/${localeCode}.json`));
@@ -13,6 +16,11 @@ function addLocale(localeCode) {
// Picks the default locale based on navigator locale and the list of available locales
function pickLocale(navigatorLocale, availableLocales) {
+ // locale can be null the first time you load this
+ // return the default locale in that case - reloading should fix this
+ if (!navigatorLocale)
+ return defaultLocale;
+
// determine langugage part of locale
// (e.g. if navigatorLocale is 'en-US', languageCode is 'en')
let dashIndex = navigatorLocale ? navigatorLocale.indexOf("-") : -1;
@@ -38,6 +46,6 @@ localeCodes.forEach(addLocale);
let initialLocale = pickLocale(getLocaleFromNavigator(), localeCodes);
init({
- fallbackLocale: 'en',
+ fallbackLocale: defaultLocale,
initialLocale: initialLocale,
});