make main landing page bilingual and eliminate language switcher flicker
All checks were successful
CI / update (push) Successful in 1m11s
All checks were successful
CI / update (push) Successful in 1m11s
Replace window.location.reload() with custom event dispatching to avoid flicker when switching languages on main page. Add bilingual labels for all content including welcome message and link grid.
This commit is contained in:
@@ -18,6 +18,10 @@
|
||||
currentLang = 'en';
|
||||
} else if (path.startsWith('/rezepte')) {
|
||||
currentLang = 'de';
|
||||
} else if (path === '/') {
|
||||
// On main page, read from localStorage
|
||||
const preferredLanguage = localStorage.getItem('preferredLanguage');
|
||||
currentLang = preferredLanguage === 'en' ? 'en' : 'de';
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -44,6 +48,12 @@
|
||||
// Get the current path directly from window
|
||||
const path = typeof window !== 'undefined' ? window.location.pathname : currentPath;
|
||||
|
||||
// If on main page, dispatch event instead of reloading
|
||||
if (path === '/') {
|
||||
window.dispatchEvent(new CustomEvent('languagechange', { detail: { lang } }));
|
||||
return;
|
||||
}
|
||||
|
||||
// If we have recipe translation data from store, use the correct short names
|
||||
const recipeData = $recipeTranslationStore;
|
||||
if (recipeData) {
|
||||
@@ -62,8 +72,8 @@
|
||||
newPath = path.replace('/rezepte', '/recipes');
|
||||
} else if (lang === 'de' && path.startsWith('/recipes')) {
|
||||
newPath = path.replace('/recipes', '/rezepte');
|
||||
} else if (path === '/' || (!path.startsWith('/rezepte') && !path.startsWith('/recipes'))) {
|
||||
// On main page or other pages, go to recipe home
|
||||
} else if (!path.startsWith('/rezepte') && !path.startsWith('/recipes')) {
|
||||
// On other pages (glaube, cospend, etc), go to recipe home
|
||||
newPath = lang === 'en' ? '/recipes' : '/rezepte';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user