From 99b97bb8c40f0a3225b805b09e2f62f1ad600c91 Mon Sep 17 00:00:00 2001 From: Snowykami Date: Fri, 12 Sep 2025 13:23:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Closes=20#5=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=A6=96=E9=80=89=E8=AF=AD=E8=A8=80=E6=A3=80=E6=B5=8B=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/app/layout.tsx | 4 ++-- web/src/components/comment/comment-item.tsx | 1 - web/src/i18n/request.ts | 9 ++++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/web/src/app/layout.tsx b/web/src/app/layout.tsx index 50a78e9..761ae31 100644 --- a/web/src/app/layout.tsx +++ b/web/src/app/layout.tsx @@ -4,7 +4,7 @@ import "./globals.css"; import { DeviceProvider } from "@/contexts/device-context"; import { NextIntlClientProvider } from 'next-intl'; import config from "@/config"; -import { getUserLocales } from "@/i18n/request"; +import { getUserLocales, getFirstLocale } from '@/i18n/request'; import { Toaster } from "@/components/ui/sonner" const geistSans = Geist({ @@ -28,7 +28,7 @@ export default async function RootLayout({ children: React.ReactNode; }>) { return ( - + diff --git a/web/src/components/comment/comment-item.tsx b/web/src/components/comment/comment-item.tsx index 79c1818..32510b8 100644 --- a/web/src/components/comment/comment-item.tsx +++ b/web/src/components/comment/comment-item.tsx @@ -35,7 +35,6 @@ export function CommentItem( } ) { const locale = useLocale(); - console.log("locale", locale); const t = useTranslations("Comment"); const commonT = useTranslations("Common"); const clickToUserProfile = useToUserProfile(); diff --git a/web/src/i18n/request.ts b/web/src/i18n/request.ts index 005750e..9be1eca 100644 --- a/web/src/i18n/request.ts +++ b/web/src/i18n/request.ts @@ -10,7 +10,6 @@ export default getRequestConfig(async () => { try { return (await import(`@/locales/${locale}.json`)).default; } catch (err) { - console.debug(`Failed to load locale ${locale}:`); return {}; } }) @@ -30,8 +29,7 @@ export async function getUserLocales(): Promise { const user = (await getLoginUser(token)).data; locales.push(user.language); locales.push(user.language.split('-')[0]); - } catch (error) { - console.info("获取用户信息失败,使用默认语言", error); + } catch { } const languageInCookie = cookieStore.get('language')?.value; if (languageInCookie) { @@ -45,4 +43,9 @@ export async function getUserLocales(): Promise { locales = [...new Set([...locales, ...languages, ...languagesWithoutRegion])]; } return locales.reverse(); +} + +export async function getFirstLocale(): Promise { + const locales = await getUserLocales(); + return locales.reverse()[0] || 'en'; } \ No newline at end of file