From 39761c520ec743a44d36161dc7788dd74577b2b1 Mon Sep 17 00:00:00 2001 From: Alex van Andel Date: Mon, 20 Dec 2021 12:55:49 +0100 Subject: [PATCH] Uses Intl to translate weekdays and time related booking i18n (#1354) Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- components/booking/AvailableTimes.tsx | 8 ++++---- components/booking/DatePicker.tsx | 18 ++++++++---------- components/booking/pages/BookingPage.tsx | 5 ++++- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/components/booking/AvailableTimes.tsx b/components/booking/AvailableTimes.tsx index e1e5ae9197603a..aefcc2239fefae 100644 --- a/components/booking/AvailableTimes.tsx +++ b/components/booking/AvailableTimes.tsx @@ -34,7 +34,7 @@ const AvailableTimes: FC = ({ users, schedulingType, }) => { - const { t } = useLocale(); + const { t, i18n } = useLocale(); const router = useRouter(); const { rescheduleUid } = router.query; @@ -58,10 +58,10 @@ const AvailableTimes: FC = ({
- {t(date.format("dddd").toLowerCase())} + {date.toDate().toLocaleString(i18n.language, { weekday: "long" })} - {date.format(", DD ")} - {t(date.format("MMMM").toLowerCase())} + {date.format(", D ")} + {date.toDate().toLocaleString(i18n.language, { month: "long" })}
diff --git a/components/booking/DatePicker.tsx b/components/booking/DatePicker.tsx index e52104d7646f0b..33284ef04125d7 100644 --- a/components/booking/DatePicker.tsx +++ b/components/booking/DatePicker.tsx @@ -8,6 +8,7 @@ import { useEffect, useMemo, useState } from "react"; import classNames from "@lib/classNames"; import { timeZone } from "@lib/clock"; +import { weekdayNames } from "@lib/core/i18n/weekday"; import { useLocale } from "@lib/hooks/useLocale"; import getSlots from "@lib/slots"; import { WorkingHours } from "@lib/types/schedule"; @@ -82,8 +83,7 @@ function DatePicker({ periodCountCalendarDays, minimumBookingNotice, }: DatePickerProps): JSX.Element { - const { t } = useLocale(); - + const { i18n } = useLocale(); const [browsingDate, setBrowsingDate] = useState(date); useEffect(() => { @@ -157,7 +157,7 @@ function DatePicker({
- {t(browsingDate.format("MMMM").toLowerCase())} + {browsingDate.toDate().toLocaleString(i18n.language, { month: "long" })} {" "} {browsingDate.format("YYYY")} @@ -178,13 +178,11 @@ function DatePicker({
- {["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] - .sort((a, b) => (weekStart.startsWith(a) ? -1 : weekStart.startsWith(b) ? 1 : 0)) - .map((weekDay) => ( -
- {t(weekDay.toLowerCase()).substring(0, 3)} -
- ))} + {weekdayNames(i18n.language, weekStart === "Sunday" ? 0 : 1, "short").map((weekDay) => ( +
+ {weekDay} +
+ ))}
{days.map((day, idx) => ( diff --git a/components/booking/pages/BookingPage.tsx b/components/booking/pages/BookingPage.tsx index 92cc4ba5d1ece8..e9d52e7e8140b5 100644 --- a/components/booking/pages/BookingPage.tsx +++ b/components/booking/pages/BookingPage.tsx @@ -283,7 +283,10 @@ const BookingPage = (props: BookingPageProps) => { )}

- {parseZone(date).format(timeFormat + ", dddd DD MMMM YYYY")} + {date && + parseZone(date).format(timeFormat) + + ", " + + dayjs(date).toDate().toLocaleString(i18n.language, { dateStyle: "full" })}

{props.eventType.description}