Skip to content

Commit 2531e42

Browse files
authored
Merge pull request #1878 from jicruz96/page-title-translations
Ensure page titles are translate-able
2 parents 6beaf0e + a38ed8c commit 2531e42

23 files changed

+54
-35
lines changed

components/layout.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,24 @@ export const PageContainer: FC<React.PropsWithChildren<unknown>> = ({
1313
return <div className={`vh-100 d-flex flex-column`}>{children}</div>
1414
}
1515

16+
/**
17+
* Props for the Layout component.
18+
*
19+
* @property {string} [titleI18nKey] - The internationalization key for the title.
20+
* This key must be defined in the `common.json` namespace.
21+
*/
1622
export type LayoutProps = {
17-
title?: string
23+
titleI18nKey?: string
1824
}
1925

2026
export const Layout: React.FC<React.PropsWithChildren<LayoutProps>> = ({
2127
children,
22-
title
28+
titleI18nKey
2329
}) => {
2430
const { authenticated, user } = useAuth()
2531
const { t } = useTranslation("common")
26-
const formattedTitle = title
27-
? `${title} | ${t("maple_abbr")}: ${t("maple_fullName")}`
32+
let title = titleI18nKey
33+
? `${t(titleI18nKey)} | ${t("maple_abbr")}: ${t("maple_fullName")}`
2834
: `${t("maple_abbr")}: ${t("maple_fullName")}`
2935

3036
// isClient used to prevent hydration issues: quite possibly better solutions exist
@@ -41,7 +47,7 @@ export const Layout: React.FC<React.PropsWithChildren<LayoutProps>> = ({
4147
{isClient ? (
4248
<>
4349
<Head>
44-
<title>{formattedTitle}</title>
50+
<title>{title}</title>
4551
<link rel="icon" href="/favicon.ico" />
4652
</Head>
4753
<FollowContext.Provider value={{ followStatus, setFollowStatus }}>

components/page.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@ export type AppPropsWithLayout = AppProps & {
1313

1414
export function applyLayout({ Component, pageProps }: AppPropsWithLayout) {
1515
const page = <Component {...pageProps} />
16-
return <Layout title={Component.title}>{page}</Layout>
16+
return <Layout titleI18nKey={Component.titleI18nKey}>{page}</Layout>
1717
}
1818

19-
export type PageOptions<P> = {
20-
title?: string
21-
fullWidth?: boolean
22-
Page: NextPage<P>
23-
}
24-
25-
export function createPage<P>(options: PageOptions<P>): AppPage<P> {
19+
export function createPage<P>(
20+
options: {
21+
Page: NextPage<P>
22+
} & LayoutProps
23+
): AppPage<P> {
2624
const page: AppPage<P> = options.Page
27-
page.title = options.title
25+
page.titleI18nKey = options.titleI18nKey
2826
return page
2927
}

pages/about/faq-page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { FaqPage } from "../../components/Faq/FaqPage"
33
import { createGetStaticTranslationProps } from "components/translations"
44

55
export default createPage({
6-
title: "About",
6+
titleI18nKey: "about",
77
Page: () => {
88
return <FaqPage />
99
}

pages/about/how-maple-uses-ai.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createGetStaticTranslationProps } from "components/translations"
33
import MapleAI from "components/about/MapleAI/MapleAI"
44

55
export default createPage({
6-
title: "How Maple Uses AI",
6+
titleI18nKey: "navigation.ai",
77
Page: () => {
88
return (
99
<div>

pages/about/mission-and-goals.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import GoalsAndMission from "../../components/GoalsAndMission/GoalsAndMission"
33
import { createGetStaticTranslationProps } from "components/translations"
44

55
export default createPage({
6-
title: "About",
6+
titleI18nKey: "about",
77
Page: () => {
88
return <GoalsAndMission />
99
}

pages/about/our-team.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createGetStaticTranslationProps } from "components/translations"
33
import { OurTeam } from "../../components/OurTeam/OurTeam"
44

55
export default createPage({
6-
title: "Our Team",
6+
titleI18nKey: "titles.our_team",
77
Page: () => {
88
return (
99
<div>

pages/about/support-maple.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import SupportMaple from "../../components/about/SupportMaple/SupportMaple"
33
import { createGetStaticTranslationProps } from "components/translations"
44

55
export default createPage({
6-
title: "How to Support MAPLE",
6+
titleI18nKey: "titles.support_maple",
77
Page: () => {
88
return (
99
<div>

pages/admin.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useEffect } from "react"
88
// return <App />
99

1010
export default createPage({
11-
title: "Admin",
11+
titleI18nKey: "titles.admin",
1212
Page: requireAdmin(() => <App />)
1313
})
1414

pages/bills/[court]/[billId].tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { serverSideTranslations } from "next-i18next/serverSideTranslations"
1010
const Query = z.object({ court: z.coerce.number(), billId: z.string({}) })
1111

1212
export default createPage<{ bill: Bill }>({
13-
title: "Bill",
13+
titleI18nKey: "titles.bill",
1414
Page: ({ bill }) => {
1515
return (
1616
<>

pages/bills/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { BillSearch } from "components/search"
55
import { createGetStaticTranslationProps } from "components/translations"
66

77
export default createPage({
8-
title: "Browse Bills",
8+
titleI18nKey: "navigation.browseBills",
99
Page: () => {
1010
const { t } = useTranslation("billSearch")
1111

0 commit comments

Comments
 (0)