Skip to content

Commit

Permalink
feat(i18n): calendar translation
Browse files Browse the repository at this point in the history
  • Loading branch information
jsun969 committed Sep 25, 2024
1 parent 01e4c52 commit 12a92f7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
20 changes: 18 additions & 2 deletions src/components/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,13 @@ const CalendarHeader = ({
<h2 className="text-3xl">
<span className="mr-2 font-bold">
{/* Month for Wednesday in the week is more accurate than Monday */}
{currentWeek.add(2, 'day').format('MMMM')}
{
(
t('calendar.months', {
returnObjects: true,
}) as Array<string>
)[currentWeek.add(2, 'day').month()]
}
</span>
<span className="font-light">{YEAR}</span>
</h2>
Expand All @@ -141,6 +147,8 @@ const CalendarHeader = ({
};

const CalendarBg = ({ currentWeek }: { currentWeek: dayjs.Dayjs }) => {
const { t } = useTranslation();

return (
<div className="-z-50 grid grid-cols-[2.5rem_repeat(5,_minmax(0,_1fr))] grid-rows-[2.5rem_repeat(30,_minmax(0,_1fr))] border-apple-gray-300">
<div className="sticky top-12 z-50 col-span-full col-start-2 grid grid-cols-subgrid border-b-1 bg-white">
Expand All @@ -149,7 +157,15 @@ const CalendarBg = ({ currentWeek }: { currentWeek: dayjs.Dayjs }) => {
key={day}
className="flex justify-center gap-1 text-lg font-light"
>
<div>{day.slice(0, 3)}</div>
<div>
{
(
t('calendar.week-days', {
returnObjects: true,
}) as Array<string>
)[WEEK_DAYS.findIndex((d) => d === day)]
}
</div>
<div>{currentWeek.add(i, 'day').date()}</div>
</div>
))}
Expand Down
17 changes: 16 additions & 1 deletion src/locales/en-au.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 16 additions & 1 deletion src/locales/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,22 @@
"first-week": "首周",
"previous-week": "上一周",
"next-week": "下一周",
"last-week": "末周"
"last-week": "末周",
"week-days": ["周一", "周二", "周三", "周四", "周五"],
"months": [
"一月",
"二月",
"三月",
"四月",
"五月",
"六月",
"七月",
"八月",
"九月",
"十月",
"十一月",
"十二月"
]
},
"footer": {
"github": "Github 开源地址",
Expand Down

0 comments on commit 12a92f7

Please sign in to comment.