WIP - starting to implement I18n
This commit is contained in:
874
gui/rpk-gui/package-lock.json
generated
874
gui/rpk-gui/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -31,11 +31,15 @@
|
|||||||
"@tiptap/extension-underline": "^2.11.7",
|
"@tiptap/extension-underline": "^2.11.7",
|
||||||
"@tiptap/react": "^2.11.7",
|
"@tiptap/react": "^2.11.7",
|
||||||
"@tiptap/starter-kit": "^2.11.7",
|
"@tiptap/starter-kit": "^2.11.7",
|
||||||
|
"i18next": "^25.0.1",
|
||||||
|
"i18next-browser-languagedetector": "^8.0.5",
|
||||||
|
"i18next-http-backend": "^3.0.2",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"mui-tiptap": "^1.18.1",
|
"mui-tiptap": "^1.18.1",
|
||||||
"react": "^18.0.0",
|
"react": "^18.0.0",
|
||||||
"react-dom": "^18.0.0",
|
"react-dom": "^18.0.0",
|
||||||
"react-hook-form": "^7.30.0",
|
"react-hook-form": "^7.30.0",
|
||||||
|
"react-i18next": "^15.5.1",
|
||||||
"react-router": "^7.0.2"
|
"react-router": "^7.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
7
gui/rpk-gui/public/locales/en/common.json
Normal file
7
gui/rpk-gui/public/locales/en/common.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"pages": {
|
||||||
|
"login": {
|
||||||
|
"title": "Sign in to your account"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
7
gui/rpk-gui/public/locales/fr/common.json
Normal file
7
gui/rpk-gui/public/locales/fr/common.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"pages": {
|
||||||
|
"login": {
|
||||||
|
"title": "S'authentifier"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Authenticated, Refine } from "@refinedev/core";
|
import { Authenticated, I18nProvider, Refine } from "@refinedev/core";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
import { RefineSnackbarProvider, useNotificationProvider } from "@refinedev/mui";
|
import { RefineSnackbarProvider, useNotificationProvider } from "@refinedev/mui";
|
||||||
|
|
||||||
@@ -26,6 +27,15 @@ import { FirmRoutes } from "./pages/firm";
|
|||||||
import rpcTheme from "./theme";
|
import rpcTheme from "./theme";
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
|
|
||||||
|
const { t, i18n } = useTranslation();
|
||||||
|
|
||||||
|
const i18nProvider: I18nProvider = {
|
||||||
|
translate: (key: string, options?: any) => t(key, options) as string,
|
||||||
|
changeLocale: (lang: string) => i18n.changeLanguage(lang),
|
||||||
|
getLocale: () => i18n.language,
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
<ThemeProvider theme={rpcTheme}>
|
<ThemeProvider theme={rpcTheme}>
|
||||||
@@ -36,6 +46,7 @@ function App() {
|
|||||||
<Refine
|
<Refine
|
||||||
authProvider={authProvider}
|
authProvider={authProvider}
|
||||||
dataProvider={dataProvider}
|
dataProvider={dataProvider}
|
||||||
|
i18nProvider={i18nProvider}
|
||||||
notificationProvider={useNotificationProvider}
|
notificationProvider={useNotificationProvider}
|
||||||
routerProvider={routerBindings}
|
routerProvider={routerBindings}
|
||||||
options={{
|
options={{
|
||||||
|
|||||||
@@ -18,10 +18,17 @@ import { FirmContext } from "../../contexts/FirmContext";
|
|||||||
import { Logout } from "../auth/Logout";
|
import { Logout } from "../auth/Logout";
|
||||||
import { IUser } from "../../interfaces";
|
import { IUser } from "../../interfaces";
|
||||||
import MuiLink from "@mui/material/Link";
|
import MuiLink from "@mui/material/Link";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useTranslation as useTranslationR } from "@refinedev/core";
|
||||||
|
import { useSetLocale } from "@refinedev/core";
|
||||||
|
|
||||||
export const Header: React.FC<RefineThemedLayoutV2HeaderProps> = ({
|
export const Header: React.FC<RefineThemedLayoutV2HeaderProps> = ({
|
||||||
sticky = true,
|
sticky = true,
|
||||||
}) => {
|
}) => {
|
||||||
|
const { i18n } = useTranslation();
|
||||||
|
const { getLocale, changeLocale } = useTranslationR();
|
||||||
|
const currentLocale = getLocale();
|
||||||
|
|
||||||
const collapsed = false;
|
const collapsed = false;
|
||||||
const { mode, setMode } = useContext(ColorModeContext);
|
const { mode, setMode } = useContext(ColorModeContext);
|
||||||
const { currentFirm } = useContext(FirmContext);
|
const { currentFirm } = useContext(FirmContext);
|
||||||
@@ -37,6 +44,16 @@ export const Header: React.FC<RefineThemedLayoutV2HeaderProps> = ({
|
|||||||
setAnchorEl(null);
|
setAnchorEl(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const [anchorIn, setAnchorIn] = React.useState<null | HTMLElement>(null);
|
||||||
|
const openI18nMenu = Boolean(anchorEl);
|
||||||
|
const handleOpenI18nMenu = (event: React.MouseEvent<HTMLButtonElement>) => {
|
||||||
|
setAnchorIn(event.currentTarget);
|
||||||
|
}
|
||||||
|
const handleCloseI18nMenu = () => {
|
||||||
|
setAnchorIn(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AppBar position={sticky ? "sticky" : "relative"}>
|
<AppBar position={sticky ? "sticky" : "relative"}>
|
||||||
<Toolbar>
|
<Toolbar>
|
||||||
@@ -132,7 +149,43 @@ export const Header: React.FC<RefineThemedLayoutV2HeaderProps> = ({
|
|||||||
{!user && (
|
{!user && (
|
||||||
<Link to="/auth/login"><Button>Login</Button></Link>
|
<Link to="/auth/login"><Button>Login</Button></Link>
|
||||||
)}
|
)}
|
||||||
|
<Button
|
||||||
|
id="i18n-button"
|
||||||
|
aria-controls={openI18nMenu ? 'i18n-menu' : undefined}
|
||||||
|
aria-haspopup="true"
|
||||||
|
aria-expanded={openI18nMenu ? 'true' : undefined}
|
||||||
|
onClick={handleOpenI18nMenu}>
|
||||||
|
<Typography
|
||||||
|
sx={{
|
||||||
|
display: {
|
||||||
|
xs: "none",
|
||||||
|
sm: "inline-block",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
variant="subtitle2"
|
||||||
|
>
|
||||||
|
{currentLocale}
|
||||||
|
</Typography>
|
||||||
|
<Avatar src={`/images/flags/${currentLocale}.svg`} alt={currentLocale}/>
|
||||||
|
</Button>
|
||||||
|
<Menu
|
||||||
|
id="i18n-menu"
|
||||||
|
open={openI18nMenu}
|
||||||
|
anchorEl={anchorIn}
|
||||||
|
onClose={handleCloseI18nMenu}
|
||||||
|
>
|
||||||
|
{[...(i18n.languages || [])].sort().map((lang: string) => (
|
||||||
|
<MenuItem
|
||||||
|
key={lang}
|
||||||
|
onClick={() => changeLocale(lang)}
|
||||||
|
>
|
||||||
|
<span style={{ marginRight: 8 }}>
|
||||||
|
<Avatar src={`/images/flags/${lang}.svg`} alt={lang}/>
|
||||||
|
</span>
|
||||||
|
{lang === "en" ? "English" : "Français"}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</Menu>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Toolbar>
|
</Toolbar>
|
||||||
|
|||||||
20
gui/rpk-gui/src/i18n.tsx
Normal file
20
gui/rpk-gui/src/i18n.tsx
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import i18n from "i18next";
|
||||||
|
import { initReactI18next } from "react-i18next";
|
||||||
|
import Backend from "i18next-http-backend";
|
||||||
|
import detector from "i18next-browser-languagedetector";
|
||||||
|
|
||||||
|
i18n
|
||||||
|
.use(Backend)
|
||||||
|
.use(detector)
|
||||||
|
.use(initReactI18next)
|
||||||
|
.init({
|
||||||
|
supportedLngs: ["en", "fr"],
|
||||||
|
backend: {
|
||||||
|
loadPath: "/locales/{{lng}}/{{ns}}.json", // locale files path
|
||||||
|
},
|
||||||
|
ns: ["common"],
|
||||||
|
defaultNS: "common",
|
||||||
|
fallbackLng: ["en", "fr"],
|
||||||
|
});
|
||||||
|
|
||||||
|
export default i18n;
|
||||||
@@ -2,12 +2,15 @@ import React from "react";
|
|||||||
import { createRoot } from "react-dom/client";
|
import { createRoot } from "react-dom/client";
|
||||||
|
|
||||||
import App from "./App";
|
import App from "./App";
|
||||||
|
import "./i18n";
|
||||||
|
|
||||||
const container = document.getElementById("root") as HTMLElement;
|
const container = document.getElementById("root") as HTMLElement;
|
||||||
const root = createRoot(container);
|
const root = createRoot(container);
|
||||||
|
|
||||||
root.render(
|
root.render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
|
<React.Suspense fallback="loading">
|
||||||
<App />
|
<App />
|
||||||
|
</React.Suspense>
|
||||||
</React.StrictMode>
|
</React.StrictMode>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user