feat: add runtime i18n with English, Vietnamese, and Simplified Chinese support
- Implement runtime i18n using MutationObserver for automatic DOM translation
- Add language switcher dropdown in dashboard header (EN/VI/ZH)
- Support 3 languages: English (default), Tiếng Việt, 简体中文
- Add translation files: vi.json (197 entries), zh-CN.json (513 entries, cleaned)
- Translate dashboard UI: sidebar menu, header, settings, MITM page
- Use cookie-based locale persistence with /api/locale endpoint
- Zero component changes required - translations applied at runtime
- Fix Header flicker on route change with key={pathname}
Co-authored-by: eachann <each1024@qq.com>
Based on PR #247 from decolua/9router with runtime approach
Made-with: Cursor
This commit is contained in:
parent
b7b4ac5592
commit
afb83f4563
12 changed files with 1092 additions and 9 deletions
|
|
@ -324,7 +324,7 @@ export default function ProvidersPage() {
|
|||
API Key Compatible Providers{" "}
|
||||
</h2>
|
||||
<div className="flex gap-2">
|
||||
{(compatibleProviders.length > 0 || anthropicCompatibleProviders.length > 0) && (
|
||||
{/* {(compatibleProviders.length > 0 || anthropicCompatibleProviders.length > 0) && (
|
||||
<button
|
||||
onClick={() => handleBatchTest("compatible")}
|
||||
disabled={!!testingMode}
|
||||
|
|
@ -340,7 +340,7 @@ export default function ProvidersPage() {
|
|||
</span>
|
||||
{testingMode === "compatible" ? "Testing..." : "Test All"}
|
||||
</button>
|
||||
)}
|
||||
)} */}
|
||||
<Button size="sm" icon="add" onClick={() => setShowAddAnthropicCompatibleModal(true)}>
|
||||
Add Anthropic Compatible
|
||||
</Button>
|
||||
|
|
|
|||
30
src/app/api/locale/route.js
Normal file
30
src/app/api/locale/route.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import { cookies } from "next/headers";
|
||||
import { NextResponse } from "next/server";
|
||||
import { LOCALE_COOKIE, normalizeLocale, isSupportedLocale } from "@/i18n/config";
|
||||
|
||||
export async function POST(request) {
|
||||
try {
|
||||
const { locale } = await request.json();
|
||||
|
||||
if (!locale || !isSupportedLocale(locale)) {
|
||||
return NextResponse.json(
|
||||
{ error: "Invalid locale" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const normalized = normalizeLocale(locale);
|
||||
const cookieStore = await cookies();
|
||||
cookieStore.set(LOCALE_COOKIE, normalized, {
|
||||
path: "/",
|
||||
maxAge: 60 * 60 * 24 * 365, // 1 year
|
||||
});
|
||||
|
||||
return NextResponse.json({ success: true, locale: normalized });
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to set locale" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ import { ThemeProvider } from "@/shared/components/ThemeProvider";
|
|||
import "@/lib/initCloudSync"; // Auto-initialize cloud sync
|
||||
import "@/lib/network/initOutboundProxy"; // Auto-initialize outbound proxy env
|
||||
import { initConsoleLogCapture } from "@/lib/consoleLogBuffer";
|
||||
import { RuntimeI18nProvider } from "@/i18n/RuntimeI18nProvider";
|
||||
|
||||
// Hook console immediately at module load time (server-side only, runs once)
|
||||
initConsoleLogCapture();
|
||||
|
|
@ -39,7 +40,9 @@ export default function RootLayout({ children }) {
|
|||
</head>
|
||||
<body className={`${inter.variable} font-sans antialiased`}>
|
||||
<ThemeProvider>
|
||||
{children}
|
||||
<RuntimeI18nProvider>
|
||||
{children}
|
||||
</RuntimeI18nProvider>
|
||||
</ThemeProvider>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue