mirror of
https://github.com/JOYCEQL/magic-resume.git
synced 2026-07-03 14:07:11 +02:00
perf: language change
This commit is contained in:
@@ -17,6 +17,7 @@ export default function LanguageSwitch() {
|
||||
const router = useRouter();
|
||||
|
||||
const handleLanguageChange = async (newLocale: string) => {
|
||||
await updateLocale(newLocale);
|
||||
const currentPath = window.location.pathname;
|
||||
if (currentPath === `/${locale}`) {
|
||||
router.push(`/${newLocale}`);
|
||||
@@ -24,8 +25,6 @@ export default function LanguageSwitch() {
|
||||
const newPath = currentPath.replace(`/${locale}/`, `/${newLocale}/`);
|
||||
router.push(newPath);
|
||||
}
|
||||
await updateLocale(newLocale);
|
||||
router.refresh();
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -3,5 +3,5 @@ import { setUserLocale } from "@/i18n/db";
|
||||
import { revalidatePath } from "next/cache";
|
||||
export default async function updateLocale(locale: string) {
|
||||
setUserLocale(locale);
|
||||
// revalidatePath("/app");
|
||||
revalidatePath("/");
|
||||
}
|
||||
|
||||
@@ -5,5 +5,5 @@ export const defaultLocale: Locale = "zh";
|
||||
|
||||
export const localeNames: Record<Locale, string> = {
|
||||
zh: "中文",
|
||||
en: "English"
|
||||
en: "English",
|
||||
};
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import { cookies } from "next/headers";
|
||||
import { defaultLocale } from "./config";
|
||||
|
||||
// This cookie name is used by `next-intl` on the public pages too. By
|
||||
// reading/writing to this locale, we can ensure that the user's locale
|
||||
// is consistent across public and private pages. In case you save the
|
||||
// locale of registered users in a database, you can of course also use
|
||||
// that instead when the user is logged in.
|
||||
const COOKIE_NAME = "NEXT_LOCALE";
|
||||
|
||||
export async function getUserLocale() {
|
||||
|
||||
Reference in New Issue
Block a user