diff options
| author | Adam Soltys <[email protected]> | 2022-08-22 15:49:08 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-08-22 15:49:08 -0700 |
| commit | 0ebb60f986682ad8d3538c2fd1d708a861e0b1fb (patch) | |
| tree | 7a824114c5fd70fe42758d35d215fefdec8a7599 /src/lib/i18n.js | |
| parent | b1843d46dd406f6f7a657ab680407644f096e2c3 (diff) | |
| download | coinos-ui-0ebb60f986682ad8d3538c2fd1d708a861e0b1fb.tar.gz coinos-ui-0ebb60f986682ad8d3538c2fd1d708a861e0b1fb.zip | |
migrate to sveltekit-i18n
Diffstat (limited to 'src/lib/i18n.js')
| -rw-r--r-- | src/lib/i18n.js | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/src/lib/i18n.js b/src/lib/i18n.js deleted file mode 100644 index 3105c709..00000000 --- a/src/lib/i18n.js +++ /dev/null @@ -1,48 +0,0 @@ -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']; - -// 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(`../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; - - // 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; - } -} - -// add locales -localeCodes.forEach(addLocale); - -let initialLocale = pickLocale(getLocaleFromNavigator(), localeCodes); -init({ - fallbackLocale: defaultLocale, - initialLocale: initialLocale -}); |
