Skip to content

Commit 9120b09

Browse files
committed
setup /app/categories/{category} for translation
1 parent 672f079 commit 9120b09

File tree

5 files changed

+42
-17
lines changed

5 files changed

+42
-17
lines changed

app/[locale]/apps/[application]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ const Page = async ({
275275
{nextApp && (
276276
<LinkBox className="group hidden flex-row items-center rounded-lg p-3 hover:bg-background-highlight sm:flex">
277277
<div className="mr-2 flex flex-col text-right">
278-
<p className="text-sm text-gray-500 text-nowrap">See next</p>
278+
<p className="text-nowrap text-sm text-gray-500">See next</p>
279279
<p className="text-primary group-hover:text-primary-hover">
280280
{nextApp.name}
281281
</p>

app/[locale]/apps/_components/AppsTable.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ import { trackCustomEvent } from "@/lib/utils/matomo"
1616

1717
import AppCard from "./AppCard"
1818

19+
import useTranslation from "@/hooks/useTranslation"
20+
1921
const AppsTable = ({ apps }: { apps: AppData[] }) => {
22+
const { t } = useTranslation("page-apps")
2023
const [filterBy, setFilterBy] = useState("All")
2124

2225
const subCategories = useMemo(
@@ -41,7 +44,7 @@ const AppsTable = ({ apps }: { apps: AppData[] }) => {
4144
<div className="flex flex-col gap-7">
4245
<div className="flex flex-row items-end justify-between border-b pb-2 sm:items-center">
4346
<div className="flex flex-col items-start gap-2 sm:flex-row sm:items-center">
44-
<p className="whitespace-nowrap">Filter by</p>
47+
<p className="whitespace-nowrap">{t("page-apps-filter-by")}</p>
4548
<Select
4649
value={filterBy}
4750
onValueChange={(value) => {
@@ -61,7 +64,7 @@ const AppsTable = ({ apps }: { apps: AppData[] }) => {
6164
value="All"
6265
className="cursor-pointer hover:bg-primary-low-contrast"
6366
>
64-
All
67+
{t("page-apps-filter-all")}
6568
</SelectItem>
6669
{subCategories.map((subCategory) => (
6770
<SelectItem
@@ -77,7 +80,7 @@ const AppsTable = ({ apps }: { apps: AppData[] }) => {
7780
</div>
7881
<div>
7982
<p className="text-body-medium">
80-
Showing{" "}
83+
{t("page-apps-showing")}{" "}
8184
<span className="text-body">
8285
(
8386
{filteredApps.length === apps.length

app/[locale]/apps/_components/CategoriesNav.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1+
import { getTranslations } from "next-intl/server"
2+
13
import TabNav from "@/components/ui/TabNav"
24

5+
import { slugify } from "@/lib/utils/url"
6+
37
import { appsCategories } from "@/data/apps/categories"
48

5-
const CategoriesNav = ({ activeCategory = "" }: { activeCategory: string }) => {
9+
const CategoriesNav = async ({
10+
activeCategory = "",
11+
}: {
12+
activeCategory: string
13+
}) => {
14+
const t = await getTranslations("page-apps")
15+
616
const items = Object.values(appsCategories).map(
717
({ name, icon: Icon, slug }) => ({
8-
key: name,
9-
label: name,
18+
key: slug,
19+
label: t(name),
1020
href: `/apps/categories/${slug}`,
1121
icon: <Icon className="h-4 w-4" />,
1222
})
@@ -15,7 +25,7 @@ const CategoriesNav = ({ activeCategory = "" }: { activeCategory: string }) => {
1525
return (
1626
<TabNav
1727
items={items}
18-
activeKey={activeCategory}
28+
activeKey={slugify(activeCategory)}
1929
customEventOptions={{
2030
eventCategory: "categories_page",
2131
eventAction: "navigation",

app/[locale]/apps/categories/[catetgoryName]/page.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { pick } from "lodash"
22
import { notFound } from "next/navigation"
3-
import { getMessages, setRequestLocale } from "next-intl/server"
3+
import {
4+
getMessages,
5+
getTranslations,
6+
setRequestLocale,
7+
} from "next-intl/server"
48

59
import { AppCategoryEnum } from "@/lib/types"
610

@@ -52,6 +56,8 @@ const Page = async ({
5256

5357
const [appsData] = await loadData()
5458

59+
const t = await getTranslations({ locale, namespace: "page-apps" })
60+
5561
// Get i18n messages
5662
const allMessages = await getMessages({ locale })
5763
const requiredNamespaces = getRequiredNamespacesForPage("/apps")
@@ -96,13 +102,15 @@ const Page = async ({
96102
/
97103
</BreadcrumbSeparator>
98104
<BreadcrumbItem>
99-
<BreadcrumbPage>{category.name.toUpperCase()}</BreadcrumbPage>
105+
<BreadcrumbPage>
106+
{t(category.name).toUpperCase()}
107+
</BreadcrumbPage>
100108
</BreadcrumbItem>
101109
</BreadcrumbList>
102110
</Breadcrumb>
103111
}
104-
title={category.name}
105-
subtitle={category.description}
112+
title={t(category.name)}
113+
subtitle={t(category.description)}
106114
/>
107115

108116
<div className="flex flex-col gap-4 px-4 md:px-8">
@@ -111,15 +119,15 @@ const Page = async ({
111119

112120
<MainArticle className="flex flex-col gap-32 py-10">
113121
<div className="flex flex-col px-4 md:px-8">
114-
<h2>Highlights</h2>
122+
<h2>{t("page-apps-highlights-title")}</h2>
115123
<AppsHighlight
116124
apps={highlightedApps}
117125
matomoCategory={`category_page`}
118126
/>
119127
</div>
120128

121129
<div className="flex flex-col px-4 md:px-8">
122-
<AppsTable apps={appsData[category.name]} />
130+
<AppsTable apps={appsData[categoryEnum]} />
123131
</div>
124132

125133
<div className="flex flex-col px-4 md:px-8">
@@ -137,6 +145,7 @@ export async function generateMetadata({
137145
params: Promise<{ locale: string; catetgoryName: string }>
138146
}) {
139147
const { locale, catetgoryName } = await params
148+
const t = await getTranslations({ locale, namespace: "page-apps" })
140149

141150
// Normalize slug to lowercase
142151
const normalizedSlug = catetgoryName.toLowerCase()
@@ -156,8 +165,8 @@ export async function generateMetadata({
156165
notFound()
157166
}
158167

159-
const title = category.metaTitle
160-
const description = category.metaDescription
168+
const title = t(category.metaTitle)
169+
const description = t(category.metaDescription)
161170

162171
return await getMetadata({
163172
locale,

src/intl/en/page-apps.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,8 @@
5353
"page-apps-see-all": "See all",
5454
"page-apps-suggest-an-app-title": "Suggest an app",
5555
"page-apps-suggest-an-app-description": "We're always looking for new apps to add to our list. If you know of an app that you think should be on the list, please let us know.",
56-
"page-apps-suggest-an-app-button": "Suggest an app"
56+
"page-apps-suggest-an-app-button": "Suggest an app",
57+
"page-apps-filter-by": "Filter by",
58+
"page-apps-filter-all": "All",
59+
"page-apps-showing": "Showing"
5760
}

0 commit comments

Comments
 (0)