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}</>;
|
||
|
|
}
|