From 27f034b216e6ee9a1d9d0d17b8efffe97bd209c8 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sun, 26 May 2024 00:17:20 -0700 Subject: [PATCH] feat: auto detect user language --- src/routes/+layout.svelte | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index d4a3f0811..c0ede634f 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -13,7 +13,7 @@ import 'tippy.js/dist/tippy.css'; import { WEBUI_BASE_URL } from '$lib/constants'; - import i18n, { initI18n } from '$lib/i18n'; + import i18n, { initI18n, getLanguages } from '$lib/i18n'; setContext('i18n', i18n); @@ -43,7 +43,14 @@ } // Initialize i18n even if we didn't get a backend config, // so `/error` can show something that's not `undefined`. - initI18n(backendConfig?.default_locale); + + const languages = await getLanguages(); + + const browserLanguage = navigator.languages + ? navigator.languages[0] + : navigator.language || navigator.userLanguage; + + initI18n(languages.includes(browserLanguage) ? browserLanguage : backendConfig?.default_locale); if (backendConfig) { // Save Backend Status to Store