diff options
| author | secondl1ght <[email protected]> | 2022-08-16 10:59:19 -0600 |
|---|---|---|
| committer | secondl1ght <[email protected]> | 2022-08-16 10:59:19 -0600 |
| commit | c26e004f4a05f231242587c1265a620b7fcd873a (patch) | |
| tree | 54ac64420712c0343d693b97988a940eda66257e /src/lib | |
| parent | 94bb8a163f2d1197544977bdbd3c225a815f9c0e (diff) | |
| download | coinos-ui-c26e004f4a05f231242587c1265a620b7fcd873a.tar.gz coinos-ui-c26e004f4a05f231242587c1265a620b7fcd873a.zip | |
run format
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/i18n.js | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/src/lib/i18n.js b/src/lib/i18n.js index fdf5de3c..3105c709 100644 --- a/src/lib/i18n.js +++ b/src/lib/i18n.js @@ -2,41 +2,40 @@ import { register, init, getLocaleFromNavigator } from 'svelte-i18n'; // The list of locales to look for // ADD ALL NEW LANGUAGE CODES TO THIS LIST -const localeCodes = ["en", "fr"]; +const localeCodes = ['en', 'fr']; // the default locale to use if none was found -const defaultLocale = "en"; +const defaultLocale = 'en'; // Adds a new locale based on its code function addLocale(localeCode) { - register(localeCode, () => import(`../locales/${localeCode}.json`)); + register(localeCode, () => import(`../locales/${localeCode}.json`)); } // 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; + // 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; - let languageCode; // navigator locale without the regional part - if (dashIndex === -1) { - languageCode = navigatorLocale; - } else { - languageCode = navigatorLocale.slice(0, dashIndex); - } + // determine langugage part of locale + // (e.g. if navigatorLocale is 'en-US', languageCode is 'en') + let dashIndex = navigatorLocale ? navigatorLocale.indexOf('-') : -1; + let languageCode; // navigator locale without the regional part + if (dashIndex === -1) { + languageCode = navigatorLocale; + } else { + languageCode = navigatorLocale.slice(0, dashIndex); + } - // get locale - if (availableLocales.includes(navigatorLocale)) { - return navigatorLocale; - } else if (availableLocales.includes(languageCode)) { - return languageCode; - } else { - return navigatorLocale; - } + // get locale + if (availableLocales.includes(navigatorLocale)) { + return navigatorLocale; + } else if (availableLocales.includes(languageCode)) { + return languageCode; + } else { + return navigatorLocale; + } } // add locales @@ -44,6 +43,6 @@ localeCodes.forEach(addLocale); let initialLocale = pickLocale(getLocaleFromNavigator(), localeCodes); init({ - fallbackLocale: defaultLocale, - initialLocale: initialLocale, + fallbackLocale: defaultLocale, + initialLocale: initialLocale }); |
