From 12a92f7338956abf24aa6e63c4148b7a867b078d Mon Sep 17 00:00:00 2001 From: jsun969 Date: Wed, 25 Sep 2024 20:51:22 +0930 Subject: [PATCH] feat(i18n): calendar translation --- src/components/Calendar.tsx | 20 ++++++++++++++++++-- src/locales/en-au.json | 17 ++++++++++++++++- src/locales/zh-cn.json | 17 ++++++++++++++++- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/components/Calendar.tsx b/src/components/Calendar.tsx index cc546ad..00db6a8 100644 --- a/src/components/Calendar.tsx +++ b/src/components/Calendar.tsx @@ -117,7 +117,13 @@ const CalendarHeader = ({

{/* Month for Wednesday in the week is more accurate than Monday */} - {currentWeek.add(2, 'day').format('MMMM')} + { + ( + t('calendar.months', { + returnObjects: true, + }) as Array + )[currentWeek.add(2, 'day').month()] + } {YEAR}

@@ -141,6 +147,8 @@ const CalendarHeader = ({ }; const CalendarBg = ({ currentWeek }: { currentWeek: dayjs.Dayjs }) => { + const { t } = useTranslation(); + return (
@@ -149,7 +157,15 @@ const CalendarBg = ({ currentWeek }: { currentWeek: dayjs.Dayjs }) => { key={day} className="flex justify-center gap-1 text-lg font-light" > -
{day.slice(0, 3)}
+
+ { + ( + t('calendar.week-days', { + returnObjects: true, + }) as Array + )[WEEK_DAYS.findIndex((d) => d === day)] + } +
{currentWeek.add(i, 'day').date()}
))} diff --git a/src/locales/en-au.json b/src/locales/en-au.json index 9ba935e..488fe5f 100644 --- a/src/locales/en-au.json +++ b/src/locales/en-au.json @@ -19,7 +19,22 @@ "first-week": "First week", "previous-week": "Previous week", "next-week": "Next week", - "last-week": "Last week" + "last-week": "Last week", + "week-days": ["Mon", "Tue", "Wed", "Thu", "Fri"], + "months": [ + "Janurary", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December" + ] }, "footer": { "github": "Github Repo", diff --git a/src/locales/zh-cn.json b/src/locales/zh-cn.json index 2992a96..7c06fd4 100644 --- a/src/locales/zh-cn.json +++ b/src/locales/zh-cn.json @@ -19,7 +19,22 @@ "first-week": "首周", "previous-week": "上一周", "next-week": "下一周", - "last-week": "末周" + "last-week": "末周", + "week-days": ["周一", "周二", "周三", "周四", "周五"], + "months": [ + "一月", + "二月", + "三月", + "四月", + "五月", + "六月", + "七月", + "八月", + "九月", + "十月", + "十一月", + "十二月" + ] }, "footer": { "github": "Github 开源地址",