1
0
Fork 0
freesewing/sites/shared/components/locale-picker.js

41 lines
1.2 KiB
JavaScript
Raw Normal View History

import themes from 'shared/themes/index.js'
import LocaleIcon from 'shared/components/icons/i18n.js'
2022-02-06 19:16:49 +01:00
import { useRouter } from 'next/router'
import { useTranslation } from 'next-i18next'
import Link from 'next/link'
2022-02-06 13:17:42 +01:00
2022-06-04 18:30:30 +02:00
const LocalePicker = ({ app, iconOnly=false }) => {
2022-02-06 19:16:49 +01:00
const { t } = useTranslation(['locales'])
const router = useRouter()
2022-02-07 20:02:28 +01:00
2022-02-06 19:16:49 +01:00
return (
2022-06-04 18:30:30 +02:00
<div className="dropdown dropdown-end w-auto">
<div tabIndex="0" className={ iconOnly
? 'btn btn-sm'
: `m-0 btn btn-neutral flex flex-row gap-2 btn-outline
md:btn-ghost
hover:bg-neutral hover:border-neutral-content
`
}>
2022-02-06 19:16:49 +01:00
<LocaleIcon />
2022-06-04 18:30:30 +02:00
{!iconOnly && <span>{t(router.locale)}</span>}
2022-02-06 19:16:49 +01:00
</div>
<ul tabIndex="0" className="p-2 shadow menu dropdown-content bg-base-100 rounded-box w-52">
{router.locales.map(locale => (
<li key={locale}>
<Link href={router.asPath} locale={locale}>
<a className="btn btn-ghost text-base-content hover:bg-base-200">
<span className="text-base-content">
{t(locale)}
</span>
</a>
</Link>
</li>
))}
</ul>
2022-01-28 18:27:20 +01:00
</div>
2022-02-06 19:16:49 +01:00
)
}
export default LocalePicker