mirror of
https://github.com/vercel/commerce.git
synced 2025-05-15 14:06:59 +00:00
30 lines
680 B
TypeScript
30 lines
680 B
TypeScript
'use client'
|
|
|
|
import Link from 'next/link'
|
|
import { usePathname } from 'next/navigation'
|
|
import { i18n } from '../../i18n-config'
|
|
|
|
export default function LocaleSwitcher() {
|
|
const pathName = usePathname()
|
|
const redirectedPathName = (locale: string) => {
|
|
if (!pathName) return '/'
|
|
const segments = pathName.split('/')
|
|
segments[1] = locale
|
|
return segments.join('/')
|
|
}
|
|
|
|
return (
|
|
<div>
|
|
<p>Locale switcher:</p>
|
|
<ul>
|
|
{i18n.locales.map((locale) => {
|
|
return (
|
|
<li key={locale}>
|
|
<Link href={redirectedPathName(locale)}>{locale}</Link>
|
|
</li>
|
|
)
|
|
})}
|
|
</ul>
|
|
</div>
|
|
)
|
|
} |