mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-11-16 23:04:24 +08:00
fix(i18n): use English runtime text and localize system UI
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useLayoutEffect, useState } from 'react';
|
||||
import { NextIntlClientProvider } from 'next-intl';
|
||||
import type { AbstractIntlMessages } from 'next-intl';
|
||||
import type { ReactNode } from 'react';
|
||||
@@ -25,20 +25,17 @@ export function AppIntlProvider({
|
||||
messages: ssrMessages,
|
||||
children,
|
||||
}: Props) {
|
||||
// Static export (NEXT_STANDALONE_EXPORT) pre-renders every page at build time
|
||||
// with the default locale, so the SSR locale is stale at runtime. Re-resolve
|
||||
// from the NEXT_LOCALE cookie / browser language on the client. The first
|
||||
// render stays identical to SSR to avoid a hydration mismatch, then flips —
|
||||
// the brief flash matches the theme-hydration pattern (suppressHydrationWarning
|
||||
// is already set on <html>/<body>).
|
||||
// Static exports start in the default English locale. Keep hydration aligned
|
||||
// with that HTML, then apply an explicit preference before the hydrated UI
|
||||
// paints instead of switching languages in a passive effect after paint.
|
||||
const [clientLocale, setClientLocale] = useState<AppLocale | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
useLayoutEffect(() => {
|
||||
const resolved = resolveClientLocale();
|
||||
if (resolved !== ssrLocale) {
|
||||
setClientLocale(resolved);
|
||||
document.documentElement.lang = resolved;
|
||||
}
|
||||
document.documentElement.lang = resolved;
|
||||
}, [ssrLocale]);
|
||||
|
||||
const locale = clientLocale ?? ssrLocale;
|
||||
|
||||
@@ -4,8 +4,10 @@ import { useQuery } from '@tanstack/react-query';
|
||||
import { useEffect } from 'react';
|
||||
import { ConfigService } from '@/lib/services/config';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { useTranslations } from 'next-intl';
|
||||
|
||||
export function SiteTitleUpdater() {
|
||||
const t = useTranslations('providers.titleUpdater');
|
||||
const pathname = usePathname();
|
||||
const publicConfigQuery = useQuery({
|
||||
queryKey: ['public-config'],
|
||||
@@ -18,17 +20,17 @@ export function SiteTitleUpdater() {
|
||||
// Determine the page suffix based on path
|
||||
let suffix = '';
|
||||
if (pathname === '/login') {
|
||||
suffix = ' - 登录';
|
||||
suffix = ` - ${t('login')}`;
|
||||
} else if (pathname === '/register') {
|
||||
suffix = ' - 注册';
|
||||
suffix = ` - ${t('register')}`;
|
||||
} else if (pathname.startsWith('/admin')) {
|
||||
suffix = ' - 后台管理';
|
||||
suffix = ` - ${t('admin')}`;
|
||||
} else if (pathname === '/') {
|
||||
suffix = ' - 总览';
|
||||
suffix = ` - ${t('dashboard')}`;
|
||||
}
|
||||
|
||||
document.title = `${siteName}${suffix}`;
|
||||
}, [publicConfigQuery.data?.site_name, pathname]);
|
||||
}, [publicConfigQuery.data?.site_name, pathname, t]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user