From 49e956289059b76495c49eb135bec6b201028c70 Mon Sep 17 00:00:00 2001 From: Christian Kaisermann Date: Thu, 21 Nov 2019 23:30:59 -0300 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20rename=20fallback=20?= =?UTF-8?q?locale=20methods?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/includes/utils.ts | 4 ++-- src/client/stores/locale.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) 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 }])