chore: disable locale switch if only one locale defined
This commit is contained in:
parent
d9e25b39af
commit
743ef4aef7
@ -20,7 +20,7 @@ import {
|
||||
} from '@/components/ui/sidebar';
|
||||
import { websiteConfig } from '@/config/website';
|
||||
import { useLocalePathname, useLocaleRouter } from '@/i18n/navigation';
|
||||
import { routing } from '@/i18n/routing';
|
||||
import { LOCALES, routing } from '@/i18n/routing';
|
||||
import { authClient } from '@/lib/auth-client';
|
||||
import { useLocaleStore } from '@/stores/locale-store';
|
||||
import { usePaymentStore } from '@/stores/payment-store';
|
||||
@ -171,32 +171,36 @@ export function SidebarUser({ user, className }: SidebarUserProps) {
|
||||
</DropdownMenuSub>
|
||||
</DropdownMenuGroup>
|
||||
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuSub>
|
||||
<DropdownMenuSubTrigger className="cursor-pointer">
|
||||
<Languages className="mr-2 size-4" />
|
||||
<span>{t('Common.language')}</span>
|
||||
</DropdownMenuSubTrigger>
|
||||
<DropdownMenuSubContent>
|
||||
{routing.locales.map((localeOption) => (
|
||||
<DropdownMenuItem
|
||||
key={localeOption}
|
||||
onClick={() => setLocale(localeOption)}
|
||||
className="cursor-pointer"
|
||||
>
|
||||
{websiteConfig.i18n.locales[localeOption].flag && (
|
||||
<span className="mr-2 text-md">
|
||||
{websiteConfig.i18n.locales[localeOption].flag}
|
||||
</span>
|
||||
)}
|
||||
<span className="text-sm">
|
||||
{websiteConfig.i18n.locales[localeOption].name}
|
||||
</span>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuSubContent>
|
||||
</DropdownMenuSub>
|
||||
</DropdownMenuGroup>
|
||||
|
||||
{
|
||||
LOCALES.length > 1 && (
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuSub>
|
||||
<DropdownMenuSubTrigger className="cursor-pointer">
|
||||
<Languages className="mr-2 size-4" />
|
||||
<span>{t('Common.language')}</span>
|
||||
</DropdownMenuSubTrigger>
|
||||
<DropdownMenuSubContent>
|
||||
{routing.locales.map((localeOption) => (
|
||||
<DropdownMenuItem
|
||||
key={localeOption}
|
||||
onClick={() => setLocale(localeOption)}
|
||||
className="cursor-pointer"
|
||||
>
|
||||
{websiteConfig.i18n.locales[localeOption].flag && (
|
||||
<span className="mr-2 text-md">
|
||||
{websiteConfig.i18n.locales[localeOption].flag}
|
||||
</span>
|
||||
)}
|
||||
<span className="text-sm">
|
||||
{websiteConfig.i18n.locales[localeOption].name}
|
||||
</span>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuSubContent>
|
||||
</DropdownMenuSub>
|
||||
</DropdownMenuGroup>
|
||||
)}
|
||||
|
||||
<DropdownMenuSeparator />
|
||||
|
||||
|
@ -9,7 +9,7 @@ import {
|
||||
} from '@/components/ui/select';
|
||||
import { websiteConfig } from '@/config/website';
|
||||
import { useLocalePathname, useLocaleRouter } from '@/i18n/navigation';
|
||||
import { DEFAULT_LOCALE } from '@/i18n/routing';
|
||||
import { DEFAULT_LOCALE, LOCALES } from '@/i18n/routing';
|
||||
import { useLocaleStore } from '@/stores/locale-store';
|
||||
import { Locale, useLocale } from 'next-intl';
|
||||
import { useParams } from 'next/navigation';
|
||||
@ -26,6 +26,11 @@ import { useEffect, useTransition } from 'react';
|
||||
* https://next-intl.dev/docs/routing/navigation#userouter
|
||||
*/
|
||||
export default function LocaleSelector() {
|
||||
// Return null if there's only one locale available
|
||||
if (LOCALES.length <= 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const router = useLocaleRouter();
|
||||
const pathname = useLocalePathname();
|
||||
const params = useParams();
|
||||
|
@ -9,6 +9,7 @@ import {
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import { websiteConfig } from '@/config/website';
|
||||
import { useLocalePathname, useLocaleRouter } from '@/i18n/navigation';
|
||||
import { LOCALES } from '@/i18n/routing';
|
||||
import { useLocaleStore } from '@/stores/locale-store';
|
||||
import { Languages } from 'lucide-react';
|
||||
import { Locale, useLocale, useTranslations } from 'next-intl';
|
||||
@ -24,6 +25,11 @@ import { useEffect, useTransition } from 'react';
|
||||
* https://next-intl.dev/docs/routing/navigation#userouter
|
||||
*/
|
||||
export default function LocaleSwitcher() {
|
||||
// Return null if there's only one locale available
|
||||
if (LOCALES.length <= 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const router = useLocaleRouter();
|
||||
const pathname = useLocalePathname();
|
||||
const params = useParams();
|
||||
|
Loading…
Reference in New Issue
Block a user