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