From 9f69a44bc7d1ee0d86126a8d622b07765b446bbd Mon Sep 17 00:00:00 2001 From: Mikael Siidorow Date: Wed, 30 Oct 2024 14:37:37 +0200 Subject: [PATCH] feat: implement support for localizing event titles in UI with common practice divider --- .../signups/[signupId]/[signupEditToken]/page.tsx | 7 +++++-- .../[signupId]/[signupEditToken]/signup-form.tsx | 5 +++-- apps/web/src/components/events-display/index.tsx | 12 ++++++++---- apps/web/src/custom-pages/event-calendar.tsx | 12 +++++++----- apps/web/src/custom-pages/events-page.tsx | 3 ++- apps/web/src/lib/utils.ts | 11 +++++++++++ 6 files changed, 36 insertions(+), 14 deletions(-) diff --git a/apps/web/src/app/[locale]/signups/[signupId]/[signupEditToken]/page.tsx b/apps/web/src/app/[locale]/signups/[signupId]/[signupEditToken]/page.tsx index 7c75183..06ad194 100644 --- a/apps/web/src/app/[locale]/signups/[signupId]/[signupEditToken]/page.tsx +++ b/apps/web/src/app/[locale]/signups/[signupId]/[signupEditToken]/page.tsx @@ -6,7 +6,8 @@ import { deleteSignUpAction, saveSignUpAction, } from "../../../../../lib/api/external/ilmomasiina/actions"; -import { getScopedI18n } from "../../../../../locales/server"; +import { getCurrentLocale, getScopedI18n } from "../../../../../locales/server"; +import { getLocalizedEventTitle } from "../../../../../lib/utils"; import { SignupForm } from "./signup-form"; interface PageProps { @@ -48,6 +49,7 @@ export default async function Page({ throw new Error("Failed to fetch signup info"); } + const locale = await getCurrentLocale(); const t = await getScopedI18n("ilmomasiina.form"); return ( @@ -58,7 +60,8 @@ export default async function Page({

- {t("Edit sign up")} - {signupInfo.data.event.title} + {t("Edit sign up")} -{" "} + {getLocalizedEventTitle(signupInfo.data.event.title, locale)}

{signupInfo.data.signup.status === "in-queue" diff --git a/apps/web/src/app/[locale]/signups/[signupId]/[signupEditToken]/signup-form.tsx b/apps/web/src/app/[locale]/signups/[signupId]/[signupEditToken]/signup-form.tsx index 4d5cebd..e8f91ea 100644 --- a/apps/web/src/app/[locale]/signups/[signupId]/[signupEditToken]/signup-form.tsx +++ b/apps/web/src/app/[locale]/signups/[signupId]/[signupEditToken]/signup-form.tsx @@ -29,7 +29,7 @@ import { useCurrentLocale, useScopedI18n, } from "../../../../../locales/client"; -import { cn } from "../../../../../lib/utils"; +import { cn, getLocalizedEventTitle } from "../../../../../lib/utils"; type FieldErrorI18n = ReturnType; @@ -212,6 +212,7 @@ function Form({ saveAction: typeof saveSignUpAction; deleteAction: typeof deleteSignUpAction; }) { + const locale = useCurrentLocale(); const t = useScopedI18n("ilmomasiina.form"); const [state, formAction] = useFormState(saveAction, null); const isSignupPeriodEnded = @@ -386,7 +387,7 @@ function Form({ />

diff --git a/apps/web/src/components/events-display/index.tsx b/apps/web/src/components/events-display/index.tsx index 0375da2..280e699 100644 --- a/apps/web/src/components/events-display/index.tsx +++ b/apps/web/src/components/events-display/index.tsx @@ -14,7 +14,11 @@ import { import type { IlmomasiinaEvent } from "../../lib/api/external/ilmomasiina"; import { fetchUpcomingEvents } from "../../lib/api/external/ilmomasiina"; import { getCurrentLocale, getI18n } from "../../locales/server"; -import { formatDateTime, formatDateTimeOptions } from "../../lib/utils"; +import { + formatDateTime, + formatDateTimeOptions, + getLocalizedEventTitle, +} from "../../lib/utils"; import { DateTime } from "../datetime"; function EventListSkeleton() { @@ -37,14 +41,14 @@ async function EventItem({ event }: { event: IlmomasiinaEvent }) {
  • - {event.title} + {getLocalizedEventTitle(event.title, locale)}