Skip to content

Commit

Permalink
feat: Improve crumbs translations
Browse files Browse the repository at this point in the history
Move the translation of the crumbs inside the router.
This will make sure translations can be correctly extracted
from the source.
  • Loading branch information
LuukvH committed Jul 20, 2024
1 parent e428576 commit a813fe0
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 55 deletions.
123 changes: 70 additions & 53 deletions src/web/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,70 +1,87 @@
import { RouterProvider, createBrowserRouter } from "react-router-dom";
import { useTranslation } from "react-i18next";
import ErrorPage from "./components/ErrorPage";
import MainLayout from "./components/AuthProviderLayout";
import { type TFunction } from "i18next";

const router = createBrowserRouter([
{
path: "/",
element: <MainLayout />,
errorElement: <ErrorPage />,
handle: {
crumb: () => "Home",
},
children: [
{
path: "children/:childId",
lazy: () => import("./pages/children/UpdateChildPage"),
},
{
path: "children",
lazy: () => import("./pages/children/IndexChildPage"),
handle: {
crumb: () => "Children",
const router = (t: TFunction<"translation", undefined>) =>
createBrowserRouter([
{
path: "/",
element: <MainLayout />,
errorElement: <ErrorPage />,
handle: {
crumb: () => {
return t("Home");
},
},
{
path: "people",
lazy: () => import("./pages/people/IndexPersonPage"),
handle: {
crumb: () => "People",
children: [
{
path: "children/:childId",
lazy: () => import("./pages/children/UpdateChildPage"),
},
},
{
path: "children/new",
lazy: () => import("./pages/children/NewChildPage"),
},
{
path: "groups",
lazy: () => import("./pages/groups/ListGroupsPage"),
handle: {
crumb: () => "Groups",
{
path: "children",
lazy: () => import("./pages/children/IndexChildPage"),
handle: {
crumb: () => {
return t("Children");
},
},
},
},
{
path: "settings",
handle: {
crumb: () => "Settings",
{
path: "people",
lazy: () => import("./pages/people/IndexPersonPage"),
handle: {
crumb: () => {
return t("People");
},
},
},
children: [
{
index: true,
lazy: () => import("./pages/settings/SettingsPage"),
{
path: "children/new",
lazy: () => import("./pages/children/NewChildPage"),
},
{
path: "groups",
lazy: () => import("./pages/groups/ListGroupsPage"),
handle: {
crumb: () => {
return t("Groups");
},
},
{
path: "scheduling",
lazy: () => import("./pages/settings/SchedulingSettingsPage"),
handle: {
crumb: () => "Scheduling",
},
{
path: "settings",
handle: {
crumb: () => {
return t("Settings");
},
},
],
},
],
},
]);
children: [
{
index: true,
lazy: () => import("./pages/settings/SettingsPage"),
},
{
path: "scheduling",
lazy: () => import("./pages/settings/SchedulingSettingsPage"),
handle: {
crumb: () => {
return t("Scheduling");
},
},
},
],
},
],
},
]);

function App() {
return <RouterProvider router={router} />;
const { t } = useTranslation();

return <RouterProvider router={router(t)} />;
}

export default App;
4 changes: 2 additions & 2 deletions src/web/src/components/RouterBreadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useTranslation } from "react-i18next";
import { Typography } from "@mui/material";

type Handle = {
crumb: (data: any) => string;
crumb: (data: any) => React.ReactElement;
};

const RouterBreadcrumbs: React.FC = () => {
Expand Down Expand Up @@ -38,7 +38,7 @@ const RouterBreadcrumbs: React.FC = () => {
color="inherit"
to={crumb.pathname}
>
{t(crumb.crumbElement)}
{crumb.crumbElement}
</Link>
),
)}
Expand Down

0 comments on commit a813fe0

Please sign in to comment.