2025-06-08 09:25:38 +03:30
|
|
|
'use client';
|
|
|
|
|
|
2025-06-08 15:52:05 +03:30
|
|
|
import images from '@/assets/images/images';
|
|
|
|
|
import { TLocales } from '@/models/layout';
|
2026-07-19 07:59:16 +03:30
|
|
|
import Select from '@/components/uikit/select';
|
2025-06-08 09:25:38 +03:30
|
|
|
import { usePathname } from 'next/navigation';
|
|
|
|
|
|
2026-07-19 07:59:16 +03:30
|
|
|
const languages = [
|
|
|
|
|
{ value: 'en', label: 'English', image: images.en },
|
|
|
|
|
{ value: 'fa', label: 'فارسی', image: images.fa },
|
|
|
|
|
];
|
|
|
|
|
|
2025-06-08 09:25:38 +03:30
|
|
|
export default function LanguageSwitch() {
|
|
|
|
|
const pathname = usePathname();
|
2026-07-19 07:59:16 +03:30
|
|
|
const currentLocale = pathname.split('/')[1] as TLocales;
|
2025-06-08 09:25:38 +03:30
|
|
|
|
2026-07-19 07:59:16 +03:30
|
|
|
const changeLocale = (locale: string) => {
|
2025-06-08 15:52:05 +03:30
|
|
|
if (currentLocale === locale) return;
|
2026-07-19 07:59:16 +03:30
|
|
|
|
|
|
|
|
document.cookie = `locale=${locale}; path=/; max-age=31536000; samesite=lax`;
|
2025-06-08 15:52:05 +03:30
|
|
|
let newPath = pathname.replace(/^\/(en|fa)/, '');
|
|
|
|
|
if (newPath === '/') newPath = '';
|
|
|
|
|
|
|
|
|
|
window.location.pathname = `/${locale}${newPath}`;
|
|
|
|
|
};
|
2025-06-08 09:25:38 +03:30
|
|
|
|
|
|
|
|
return (
|
2026-07-19 07:59:16 +03:30
|
|
|
<Select
|
|
|
|
|
options={languages}
|
|
|
|
|
value={currentLocale}
|
|
|
|
|
onChange={changeLocale}
|
|
|
|
|
size="small"
|
|
|
|
|
/>
|
2025-06-08 09:25:38 +03:30
|
|
|
);
|
|
|
|
|
}
|