move language selection to store to ensure alignment between different language selectors (mobile and desktop)
Some checks failed
CI / update (push) Failing after 1m9s

This commit is contained in:
2025-12-27 12:11:53 +01:00
parent 4356af4e0a
commit abc0d03e01
2 changed files with 37 additions and 9 deletions

View File

@@ -0,0 +1,28 @@
import { writable } from 'svelte/store';
type Language = 'de' | 'en';
function createLanguageStore() {
const { subscribe, set } = writable<Language>('de');
return {
subscribe,
set,
init: () => {
if (typeof window !== 'undefined') {
const path = window.location.pathname;
if (path.startsWith('/recipes')) {
set('en');
} else if (path.startsWith('/rezepte')) {
set('de');
} else if (path === '/') {
// On main page, read from localStorage
const preferredLanguage = localStorage.getItem('preferredLanguage');
set(preferredLanguage === 'en' ? 'en' : 'de');
}
}
}
};
}
export const languageStore = createLanguageStore();