mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 20:00:47 +00:00
- 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
28 lines
629 B
JavaScript
28 lines
629 B
JavaScript
"use client";
|
|
|
|
import { useEffect } from "react";
|
|
import { usePathname } from "next/navigation";
|
|
import { initRuntimeI18n, reloadTranslations } from "./runtime";
|
|
|
|
export function RuntimeI18nProvider({ children }) {
|
|
const pathname = usePathname();
|
|
|
|
useEffect(() => {
|
|
initRuntimeI18n();
|
|
}, []);
|
|
|
|
// Re-process DOM when route changes
|
|
useEffect(() => {
|
|
if (pathname) {
|
|
// Double RAF to ensure React has committed changes to DOM
|
|
requestAnimationFrame(() => {
|
|
requestAnimationFrame(() => {
|
|
reloadTranslations();
|
|
});
|
|
});
|
|
}
|
|
}, [pathname]);
|
|
|
|
return <>{children}</>;
|
|
}
|