From 3a026b8b821f7b611e185d1aea90edfe38588158 Mon Sep 17 00:00:00 2001 From: Kevin Stadler Date: Tue, 3 Dec 2024 12:11:11 +0100 Subject: [PATCH] feat: add language names in both locales --- app/[locale]/languages/[language]/page.tsx | 17 +++++--- app/[locale]/layout.tsx | 1 + app/[locale]/translators/page.tsx | 16 ++++++- components/language-link.tsx | 12 +++++- components/single-refinement-dropdown.tsx | 16 ++++--- components/single-refinement-list.tsx | 5 ++- messages/de.json | 44 +++++++++++++++++++ messages/en.json | 44 +++++++++++++++++++ scripts/3_to_typesense.py | 50 +++++++++++++++++++++- 9 files changed, 188 insertions(+), 17 deletions(-) diff --git a/app/[locale]/languages/[language]/page.tsx b/app/[locale]/languages/[language]/page.tsx index 3a02a31..4e93529 100644 --- a/app/[locale]/languages/[language]/page.tsx +++ b/app/[locale]/languages/[language]/page.tsx @@ -15,18 +15,25 @@ interface LanguagesPageProps { // eslint-disable-next-line @typescript-eslint/no-unused-vars export default function LanguagesPage(props: LanguagesPageProps) { const t = useTranslations("LanguagesPage"); + const tl = useTranslations("Languages"); return ( - + { - return items; + return items + .map((item) => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + item.label = tl(item.label as any); + return item; + }) + .sort((a, b) => { + return a.label.localeCompare(b.label); + }); }, }} /> diff --git a/app/[locale]/layout.tsx b/app/[locale]/layout.tsx index e952d7d..990eeb6 100644 --- a/app/[locale]/layout.tsx +++ b/app/[locale]/layout.tsx @@ -123,6 +123,7 @@ export default function LocaleLayout(props: LocaleLayoutProps): ReactNode { "BernhardCategories", "Error", "InstantSearch", + "Languages", "LanguagesPage", "PublicationCover", "SearchPage", diff --git a/app/[locale]/translators/page.tsx b/app/[locale]/translators/page.tsx index fda4aa1..26523d3 100644 --- a/app/[locale]/translators/page.tsx +++ b/app/[locale]/translators/page.tsx @@ -46,6 +46,7 @@ function TranslatorsList() { export default function TranslatorsPage() { const t = useTranslations("TranslatorsPage"); + const tl = useTranslations("Languages"); return ( { + return items + .map((item) => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + item.label = tl(item.label as any); + return item; + }) + .sort((a, b) => { + return a.label.localeCompare(b.label); + }); + }, + }} /> diff --git a/components/language-link.tsx b/components/language-link.tsx index f512b3a..e520636 100644 --- a/components/language-link.tsx +++ b/components/language-link.tsx @@ -1,3 +1,5 @@ +import { useTranslations } from "next-intl"; + import { AppLink } from "./app-link"; interface LanguageLinkProps { @@ -5,5 +7,13 @@ interface LanguageLinkProps { } export function LanguageLink(props: LanguageLinkProps) { - return {props.language}; + const t = useTranslations("Languages"); + return ( + + { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + t(props.language as any) + } + + ); } diff --git a/components/single-refinement-dropdown.tsx b/components/single-refinement-dropdown.tsx index b1d97a2..d67eb74 100644 --- a/components/single-refinement-dropdown.tsx +++ b/components/single-refinement-dropdown.tsx @@ -9,6 +9,7 @@ interface SingleRefinementDropdownProps { attribute: string; allLabel: string; refinementArgs?: Partial; + className?: string; } const defaultTransformItems = (items: Array) => { @@ -21,8 +22,6 @@ const defaultTransformItems = (items: Array) => { // a refinement dropdown that is alphabetically ordered export function SingleRefinementDropdown(props: SingleRefinementDropdownProps) { - // const t = useTranslations("SearchPage"); - const { items, refine } = useMenu({ attribute: props.attribute, limit: 1000, @@ -39,19 +38,24 @@ export function SingleRefinementDropdown(props: SingleRefinementDropdownProps) { }} > - + {items.find((i) => { return i.isRefined; - })?.value ?? props.allLabel} + })?.label ?? props.allLabel} - + {props.allLabel} {items.map((o) => { return ( - + {o.label} ); diff --git a/components/single-refinement-list.tsx b/components/single-refinement-list.tsx index 2badae1..d90d152 100644 --- a/components/single-refinement-list.tsx +++ b/components/single-refinement-list.tsx @@ -6,6 +6,7 @@ interface SingleRefinementListProps { attribute: string; allLabel?: string; refinementArgs?: Partial; + className?: string; } const defaultTransformItems = (items: Array) => { @@ -31,7 +32,7 @@ export function SingleRefinementList(props: SingleRefinementListProps) {