perf: language change

This commit is contained in:
JOYCEQL
2025-01-08 14:15:31 +08:00
committed by qingchen
parent b92205137b
commit 0e011800c9
4 changed files with 3 additions and 9 deletions
@@ -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("/");
}
+1 -1
View File
@@ -5,5 +5,5 @@ export const defaultLocale: Locale = "zh";
export const localeNames: Record<Locale, string> = {
zh: "中文",
en: "English"
en: "English",
};
-5
View File
@@ -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() {