Skip to content

Commit

Permalink
Use localStorage to store lang (#38)
Browse files Browse the repository at this point in the history
Signed-off-by: jingyang <[email protected]>
  • Loading branch information
zjy365 authored May 24, 2024
1 parent bc58187 commit a8a6d33
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions projects/fastgpt/components/header/LangSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,21 @@ export const LangSwitcher = () => {
const router = useRouter();

const handleSwitchLanguage = (value: string) => {
localStorage.setItem('preferredLang', value);
if (value === defaultLocale) {
router.push('/');
return;
}
router.push(value);
};

useEffect(() => {
const storedLang = localStorage.getItem('preferredLang');
if (storedLang && storedLang !== lang) {
router.push(storedLang);
}
}, []);

return (
<Select value={langName} onValueChange={handleSwitchLanguage}>
<SelectTrigger className="w-fit">
Expand Down

0 comments on commit a8a6d33

Please sign in to comment.