mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-05-05 11:09:39 +00:00
34 lines
987 B
TypeScript
34 lines
987 B
TypeScript
'use client';
|
|
|
|
import type { ChangeEventHandler } from 'react';
|
|
import { useLocale } from 'next-intl';
|
|
import { useRouter } from 'next/navigation';
|
|
import { usePathname } from '@/libs/I18nNavigation';
|
|
import { routing } from '@/libs/I18nRouting';
|
|
|
|
export const LocaleSwitcher = () => {
|
|
const router = useRouter();
|
|
const pathname = usePathname();
|
|
const locale = useLocale();
|
|
|
|
const handleChange: ChangeEventHandler<HTMLSelectElement> = (event) => {
|
|
router.push(`/${event.target.value}${pathname}`);
|
|
router.refresh(); // Ensure the page takes the new locale into account related to the issue #395
|
|
};
|
|
|
|
return (
|
|
<select
|
|
defaultValue={locale}
|
|
onChange={handleChange}
|
|
className="border border-gray-300 font-medium focus:outline-hidden focus-visible:ring-3"
|
|
aria-label="lang-switcher"
|
|
>
|
|
{routing.locales.map(elt => (
|
|
<option key={elt} value={elt}>
|
|
{elt.toUpperCase()}
|
|
</option>
|
|
))}
|
|
</select>
|
|
);
|
|
};
|