[web] i18n: refresh page when switching locale (#1368)

This commit is contained in:
Nitesh Seram 2025-04-09 15:56:03 +05:30 committed by GitHub
parent 6b7984d146
commit 89377a0a57
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 4 deletions

View File

@ -1,10 +1,11 @@
import { RiTranslate2 } from 'react-icons/ri';
import url from 'url';
import { useIntl } from '~/components/intl';
import DropdownMenu from '~/components/ui/DropdownMenu';
import i18nLabelOptions from '~/i18n/i18nLabelOptions';
import { useI18nPathname } from '~/next-i18nostic/src';
import { i18nHref, useI18nPathname } from '~/next-i18nostic/src';
type Props = Readonly<{
showSelected?: boolean;
@ -45,10 +46,15 @@ export default function NavI18nDropdown({ size, showSelected }: Props) {
{i18nLabelOptions.map(({ label, locale: localeItem }) => (
<DropdownMenu.Item
key={localeItem}
href={pathname == null ? undefined : pathname}
href={
pathname == null
? undefined
: url.format(i18nHref(pathname, localeItem))
}
isSelected={locale === localeItem}
label={label}
locale={localeItem}
refresh={true}
/>
))}
</DropdownMenu>

View File

@ -1,10 +1,11 @@
import { RiTranslate2 } from 'react-icons/ri';
import url from 'url';
import { useIntl } from '~/components/intl';
import DropdownMenu from '~/components/ui/DropdownMenu';
import i18nLabelOptions from '~/i18n/i18nLabelOptions';
import { useI18nPathname } from '~/next-i18nostic/src';
import { i18nHref, useI18nPathname } from '~/next-i18nostic/src';
type Props = Readonly<{
type: 'menu' | 'submenu';
@ -28,10 +29,15 @@ export default function SidebarI18nSubMenu({ type }: Props) {
{i18nLabelOptions.map(({ label, locale: localeItem }) => (
<DropdownMenu.Item
key={localeItem}
href={pathname == null ? undefined : pathname}
href={
pathname == null
? undefined
: url.format(i18nHref(pathname, localeItem))
}
isSelected={locale === localeItem}
label={label}
locale={localeItem}
refresh={true}
/>
))}
</DropdownElement>