diff --git a/src/client/includes/utils.ts b/src/client/includes/utils.ts index e29c96b..fdfe24c 100644 --- a/src/client/includes/utils.ts +++ b/src/client/includes/utils.ts @@ -16,12 +16,12 @@ export function lower(str: string) { return str.toLocaleLowerCase() } -export function getGenericLocaleFrom(locale: string) { +export function getFallbackLocale(locale: string) { const index = locale.lastIndexOf('-') return index > 0 ? locale.slice(0, index) : null } -export function getLocalesFrom(locale: string) { +export function getAllFallbackLocales(locale: string) { return locale.split('-').map((_, i, arr) => arr.slice(0, i + 1).join('-')) } diff --git a/src/client/stores/locale.ts b/src/client/stores/locale.ts index 9855739..949ea87 100644 --- a/src/client/stores/locale.ts +++ b/src/client/stores/locale.ts @@ -1,6 +1,6 @@ import { writable } from 'svelte/store' -import { getGenericLocaleFrom, getLocalesFrom } from '../includes/utils' +import { getFallbackLocale, getAllFallbackLocales } from '../includes/utils' import { flushQueue, hasLocaleQueue } from '../includes/loaderQueue' import { getDictionary } from './dictionary' @@ -14,12 +14,12 @@ function getCurrentLocale() { function getAvailableLocale(locale: string): string | null { if (locale in getDictionary() || locale == null) return locale - return getAvailableLocale(getGenericLocaleFrom(locale)) + return getAvailableLocale(getFallbackLocale(locale)) } function loadLocale(localeToLoad: string) { return Promise.all( - getLocalesFrom(localeToLoad).map(localeItem => + getAllFallbackLocales(localeToLoad).map(localeItem => flushQueue(localeItem) .then(() => [localeItem, { err: undefined }]) .catch(e => [localeItem, { err: e }])