diff --git a/.storybook/preview.ts b/.storybook/preview.ts index d077e0d..fadc1aa 100644 --- a/.storybook/preview.ts +++ b/.storybook/preview.ts @@ -1,5 +1,7 @@ import type { Preview } from '@storybook/react'; import '../packages/core/dist/style.css'; +import '../packages/core/lib/i18n'; +import i18n from '../packages/core/lib/i18n'; const preview: Preview = { parameters: { @@ -10,6 +12,27 @@ const preview: Preview = { }, }, }, + decorators: [ + (Story, context) => { + const { locale } = context.globals; + i18n.changeLanguage(locale); + return Story(); + }, + ], + globalTypes: { + locale: { + name: 'Locale', + description: '언어 선택', + defaultValue: 'ko', + toolbar: { + icon: 'globe', + items: [ + { value: 'ko', title: '한국어' }, + { value: 'en', title: 'English' }, + ], + }, + }, + }, }; export default preview; diff --git a/package.json b/package.json index ca92752..3cfaa40 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,9 @@ "@storybook/test": "^8.2.7", "@types/node": "^22.0.0", "bundlewatch": "^0.4.0", + "i18next": "^24.2.1", + "react-i18next": "^15.4.0", + "i18next-browser-languagedetector": "^8.0.2", "lerna": "^8.1.7", "prettier": "1.19.1", "storybook": "^8.2.7", diff --git a/packages/core/lib/components/Calendar.tsx b/packages/core/lib/components/Calendar.tsx index 6b22150..de4bae1 100644 --- a/packages/core/lib/components/Calendar.tsx +++ b/packages/core/lib/components/Calendar.tsx @@ -1,4 +1,5 @@ import React, { useState } from 'react'; +import { useTranslation } from 'react-i18next'; import { Label } from './Label'; interface CalendarProps { @@ -6,23 +7,6 @@ interface CalendarProps { onSelect: (dates: string[]) => void; } -const today = new Date(); -const DAYS = ['일', '월', '화', '수', '목', '금', '토']; -const MONTHS = [ - '1월', - '2월', - '3월', - '4월', - '5월', - '6월', - '7월', - '8월', - '9월', - '10월', - '11월', - '12월', -]; - const TriangleIcon: React.FC<{ direction: 'left' | 'right' }> = ({ direction, }) => ( @@ -45,9 +29,17 @@ const TriangleIcon: React.FC<{ direction: 'left' | 'right' }> = ({ ); export const Calendar: React.FC = ({ mode, onSelect }) => { + const { t } = useTranslation(); const [currentDate, setCurrentDate] = useState(new Date()); const [selectedDates, setSelectedDates] = useState([]); + const DAYS = (t('calendar.days', { + returnObjects: true, + }) as unknown) as string[]; + const MONTHS = (t('calendar.months', { + returnObjects: true, + }) as unknown) as string[]; + const getDaysInMonth = (date: Date): Date[] => { const year = date.getFullYear(); const month = date.getMonth(); @@ -151,6 +143,7 @@ export const Calendar: React.FC = ({ mode, onSelect }) => { @@ -163,6 +156,7 @@ export const Calendar: React.FC = ({ mode, onSelect }) => { ) } className="mr-2 p-1 border rounded" + aria-label={t('calendar.year')} > {Array.from( { length: 100 }, @@ -177,10 +171,15 @@ export const Calendar: React.FC = ({ mode, onSelect }) => { value={currentDate.getMonth()} onChange={(e) => setCurrentDate( - new Date(today.getFullYear(), parseInt(e.target.value), 1), + new Date( + currentDate.getFullYear(), + parseInt(e.target.value), + 1, + ), ) } className="p-1 border rounded" + aria-label={t('calendar.month')} > {MONTHS.map((month, index) => (