aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAdrien Hopkins <[email protected]>2022-08-04 12:32:13 -0500
committerAdrien Hopkins <[email protected]>2022-08-04 12:32:13 -0500
commit7031160fd2c093ca43205db543dd75b90581da4d (patch)
treea323d43824e96e0652fdee09bdb9eebc0424de16 /src
parentc21ee41b206db79b2157d8743b0473a094448dfb (diff)
downloadcoinos-ui-7031160fd2c093ca43205db543dd75b90581da4d.tar.gz
coinos-ui-7031160fd2c093ca43205db543dd75b90581da4d.zip
Possible fix for the page breaking the first time you open iti18n
Diffstat (limited to 'src')
-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,
});