mirror of
https://github.com/JOYCEQL/magic-resume.git
synced 2026-07-03 14:07:11 +02:00
perf: language change slowly
This commit is contained in:
@@ -10,23 +10,13 @@ import {
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { locales, localeNames } from "@/i18n/config";
|
||||
import updateLocale from "./UpdateLocale";
|
||||
|
||||
import { Link, usePathname } from "@/i18n/routing.public";
|
||||
|
||||
export default function LanguageSwitch() {
|
||||
const locale = useLocale();
|
||||
const router = useRouter();
|
||||
|
||||
const handleLanguageChange = async (newLocale: string) => {
|
||||
await updateLocale(newLocale);
|
||||
const currentPath = window.location.pathname;
|
||||
if (currentPath === `/${locale}`) {
|
||||
router.push(`/${newLocale}`);
|
||||
} else {
|
||||
const newPath = currentPath.replace(`/${locale}/`, `/${newLocale}/`);
|
||||
router.push(newPath);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -39,20 +29,24 @@ export default function LanguageSwitch() {
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
{locales.map((loc) => (
|
||||
<DropdownMenuItem
|
||||
key={loc}
|
||||
onClick={() => handleLanguageChange(loc)}
|
||||
className={locale === loc ? "bg-accent" : ""}
|
||||
>
|
||||
<span className="flex items-center gap-2">
|
||||
{localeNames[loc]}
|
||||
{locale === loc && (
|
||||
<span className="text-xs text-muted-foreground">✓</span>
|
||||
)}
|
||||
</span>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
{locales.map((loc) => {
|
||||
const pathname = usePathname();
|
||||
return (
|
||||
<DropdownMenuItem
|
||||
key={loc}
|
||||
className={locale === loc ? "bg-accent" : ""}
|
||||
>
|
||||
<Link className="w-full" href={pathname} locale={loc}>
|
||||
<span className="flex items-center gap-2">
|
||||
{localeNames[loc]}
|
||||
{locale === loc && (
|
||||
<span className="text-xs text-muted-foreground">✓</span>
|
||||
)}
|
||||
</span>
|
||||
</Link>
|
||||
</DropdownMenuItem>
|
||||
);
|
||||
})}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user