From e7ee282276ff5decd1f3a2b2e7c14d17b264cb1a Mon Sep 17 00:00:00 2001 From: Skye Date: Sun, 20 Oct 2024 22:03:39 +0900 Subject: [PATCH] fix: properly do language fallback --- src/lib/i18n.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/i18n.ts b/src/lib/i18n.ts index d31a1f1..b94e5d6 100644 --- a/src/lib/i18n.ts +++ b/src/lib/i18n.ts @@ -1,16 +1,19 @@ import { writable, derived } from 'svelte/store'; import { langs } from './lang'; +const defaultLocale = 'en'; + function determineLocale(locale: string): string { if (langs[locale.toLowerCase()] != undefined) { return locale.toLowerCase(); - } else { + } else if (langs[locale.toLowerCase().split('-')[0]] != undefined) { return locale.toLowerCase().split('-')[0]; + } else { + return defaultLocale; } } export const locale = writable(determineLocale(navigator.language)); -const defaultLocale = 'en'; export const trans = derived( locale,