From 2df46d7e708cf98f7710270db50dfe8c6f7759c9 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]/search/page.tsx | 24 +++++++++-- 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 +++++++++++++++++++++- 10 files changed, 208 insertions(+), 21 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]/search/page.tsx b/app/[locale]/search/page.tsx index 33dcafc..078751c 100644 --- a/app/[locale]/search/page.tsx +++ b/app/[locale]/search/page.tsx @@ -1,12 +1,16 @@ "use client"; import { useTranslations } from "next-intl"; -import { Menu } from "react-instantsearch"; +import { Menu, type MenuProps } from "react-instantsearch"; import { InstantSearchView } from "@/components/instantsearch-view"; import { MainContent } from "@/components/main-content"; -function FilterMenu(props: { attribute: string }) { +function FilterMenu(props: { + attribute: string; + className?: string; + transformItems?: MenuProps["transformItems"]; +}) { const t = useTranslations("SearchPage"); return ( <> @@ -22,7 +26,7 @@ function FilterMenu(props: { attribute: string }) { classNames={{ count: 'before:content-["("] after:content-[")"]', disabledShowMore: "hidden", - label: "px-1", + label: `px-1 ${props.className ? props.className : ""}`, list: "text-[--color-link]", root: "py-2 text-right", selectedItem: "font-bold text-[--color-link-active]", @@ -31,6 +35,7 @@ function FilterMenu(props: { attribute: string }) { showMore={true} showMoreLimit={50} sortBy={["isRefined", "count", "name"]} + transformItems={props.transformItems} translations={{ showMoreButtonText({ isShowingMore }) { return t(isShowingMore ? "show less" : "show more"); @@ -42,6 +47,7 @@ function FilterMenu(props: { attribute: string }) { } export default function SearchPage() { + 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; + }); + }} + /> { // FIXME when changing the query removes a refinement from the list, that refinement 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) {