From 7a3ec33fa71a909acb226578c2c10b17a6feafe1 Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Wed, 27 Nov 2024 11:27:18 -0500 Subject: [PATCH] Fix locale fallback logic: ensure valid fallback locale from navigator language or default to 'en' --- frontend/src/routes/+layout.svelte | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frontend/src/routes/+layout.svelte b/frontend/src/routes/+layout.svelte index 4834290..90bfe74 100644 --- a/frontend/src/routes/+layout.svelte +++ b/frontend/src/routes/+layout.svelte @@ -14,9 +14,13 @@ register('nl', () => import('../locales/nl.json')); register('sv', () => import('../locales/sv.json')); + let locales = ['en', 'es', 'fr', 'de', 'it', 'zh', 'nl', 'sv']; + if (browser) { init({ - fallbackLocale: navigator.language.split('-')[0], + fallbackLocale: locales.includes(navigator.language.split('-')[0]) + ? navigator.language.split('-')[0] + : 'en', initialLocale: data.locale }); // get the locale cookie if it exists and set it as the initial locale if it exists