Skip to content

Commit

Permalink
Saving option to local storage (bug)
Browse files Browse the repository at this point in the history
This way, even when the page is refreshed, it will:

>First check localStorage for a saved language
>If found, use that language
>If not found, save the current language (or 'en' as fallback) to localStorage

This ensures the language preference persists across page refreshes.
  • Loading branch information
NeroxTGC committed Dec 27, 2024
1 parent d225a8a commit 1d2b048
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions template/app/src/client/components/LanguageSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ interface LanguageSelectorProps {
export default function LanguageSelector({ isLandingPage, className }: LanguageSelectorProps) {
const { i18n } = useTranslation();

// Initialize language from localStorage or default to 'en'
React.useEffect(() => {
const savedLanguage = localStorage.getItem('language') || 'en';
i18n.changeLanguage(savedLanguage);
}, [i18n]);

const changeLanguage = (lng: string) => {
localStorage.setItem('language', lng);
i18n.changeLanguage(lng);
};

Expand Down

0 comments on commit 1d2b048

Please sign in to comment.