From df167d87855f8b5e7bddc32ef3c3cd489027c7e1 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Mon, 13 May 2024 18:00:30 +0300 Subject: [PATCH] fix: load i18n for /error page --- src/lib/i18n/index.ts | 2 +- src/routes/+layout.svelte | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/lib/i18n/index.ts b/src/lib/i18n/index.ts index b0580345f..172c42f91 100644 --- a/src/lib/i18n/index.ts +++ b/src/lib/i18n/index.ts @@ -37,7 +37,7 @@ const createIsLoadingStore = (i18n: i18nType) => { return isLoading; }; -export const initI18n = (defaultLocale: string) => { +export const initI18n = (defaultLocale: string | undefined) => { let detectionOrder = defaultLocale ? ['querystring', 'localStorage'] : ['querystring', 'localStorage', 'navigator']; diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index db43a0312..5a8a8bba3 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -21,20 +21,22 @@ onMount(async () => { theme.set(localStorage.theme); - // Check Backend Status - const backendConfig = await getBackendConfig(); + let backendConfig = null; + try { + backendConfig = await getBackendConfig(); + console.log("Backend config:", backendConfig); + } catch (error) { + console.error("Error loading backend config:", error); + } + // Initialize i18n even if we didn't get a backend config, + // so `/error` can show something that's not `undefined`. + initI18n(backendConfig?.default_locale); if (backendConfig) { // Save Backend Status to Store await config.set(backendConfig); - if ($config.default_locale) { - initI18n($config.default_locale); - } else { - initI18n(); - } await WEBUI_NAME.set(backendConfig.name); - console.log(backendConfig); if ($config) { if (localStorage.token) {