Add locale support to calendar components (ko, en)
Applied i18n locale to both calendar components: Changes to nice-calendar.tsx: - Added useTranslation hook import - Get current locale from i18n.language - Updated all format functions (formatMonthYear, formatYear, formatMonth, formatDay, formatShortWeekday) to use currentLocale instead of hardcoded 'en' - Added locale prop to Calendar component Changes to nice-calendar-month.tsx: - Added useTranslation hook import - Get current locale from i18n.language - Updated all format functions to use currentLocale instead of hardcoded 'en' - Added locale prop to Calendar component Now calendars will display in Korean when language is set to 'ko' and in English when set to 'en'. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import Calendar from 'react-calendar';
|
||||
import 'react-calendar/dist/Calendar.css';
|
||||
import { useEffect } from 'react';
|
||||
import { CalendarType } from '@/entities/common/model/types';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
interface NiceCalendarProps {
|
||||
calendarOpen: boolean;
|
||||
@@ -25,6 +26,9 @@ const NiceCalendarMonth = ({
|
||||
calendarType,
|
||||
setNewMonth
|
||||
}: NiceCalendarProps) => {
|
||||
const { i18n } = useTranslation();
|
||||
const currentLocale = i18n.language || 'en';
|
||||
|
||||
const [valueYear, setValueYear] = useState<string>();
|
||||
const [minMonth, setMinMonth] = useState<Date | undefined>();
|
||||
const [maxMonth, setMaxMonth] = useState<Date | undefined>();
|
||||
@@ -57,28 +61,28 @@ const NiceCalendarMonth = ({
|
||||
};
|
||||
|
||||
const formatMonthYear = (locale: string | undefined, date: Date) => {
|
||||
return date.toLocaleDateString('en', {
|
||||
return date.toLocaleDateString(currentLocale, {
|
||||
month: 'long',
|
||||
year: 'numeric'
|
||||
});
|
||||
};
|
||||
const formatYear = (locale: string | undefined, date: Date) => {
|
||||
return date.toLocaleDateString('en', {
|
||||
return date.toLocaleDateString(currentLocale, {
|
||||
year: 'numeric'
|
||||
});
|
||||
};
|
||||
const formmatMonth = (locale: string | undefined, date: Date) => {
|
||||
return date.toLocaleDateString('en', {
|
||||
return date.toLocaleDateString(currentLocale, {
|
||||
month: 'short'
|
||||
});
|
||||
};
|
||||
const formatDay = (locale: string | undefined, date: Date) => {
|
||||
return date.toLocaleString('en', {
|
||||
return date.toLocaleString(currentLocale, {
|
||||
day: 'numeric'
|
||||
});
|
||||
};
|
||||
const formatShortWeekday = (locale: string | undefined, date: Date) => {
|
||||
return date.toLocaleString('en', {
|
||||
return date.toLocaleString(currentLocale, {
|
||||
weekday: 'short'
|
||||
});
|
||||
};
|
||||
@@ -95,6 +99,7 @@ const NiceCalendarMonth = ({
|
||||
<div className="bg-dim"></div>
|
||||
<CalendarWrapper onClick={ () => onClickToClose() }>
|
||||
<Calendar
|
||||
locale={currentLocale}
|
||||
minDate={ minMonth }
|
||||
maxDate={ maxMonth }
|
||||
onClickMonth={ onChangeToMonth }
|
||||
|
||||
@@ -5,6 +5,7 @@ import Calendar from 'react-calendar';
|
||||
import 'react-calendar/dist/Calendar.css';
|
||||
import { useEffect } from 'react';
|
||||
import { CalendarType } from '@/entities/common/model/types';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
interface NiceCalendarProps {
|
||||
calendarOpen: boolean;
|
||||
@@ -29,6 +30,9 @@ const NiceCalendar = ({
|
||||
minDate: propMinDate,
|
||||
maxDate: propMaxDate
|
||||
}: NiceCalendarProps) => {
|
||||
const { i18n } = useTranslation();
|
||||
const currentLocale = i18n.language || 'en';
|
||||
|
||||
const [valueDate, setValueDate] = useState<Date | undefined>();
|
||||
const [minDate, setMinDate] = useState<Date | undefined>();
|
||||
const [maxDate, setMaxDate] = useState<Date | undefined>();
|
||||
@@ -63,28 +67,28 @@ const NiceCalendar = ({
|
||||
};
|
||||
|
||||
const formatMonthYear = (locale: string | undefined, date: Date) => {
|
||||
return date.toLocaleDateString('en', {
|
||||
return date.toLocaleDateString(currentLocale, {
|
||||
month: 'long',
|
||||
year: 'numeric'
|
||||
});
|
||||
};
|
||||
const formatYear = (locale: string | undefined, date: Date) => {
|
||||
return date.toLocaleDateString('en', {
|
||||
return date.toLocaleDateString(currentLocale, {
|
||||
year: 'numeric'
|
||||
});
|
||||
};
|
||||
const formmatMonth = (locale: string | undefined, date: Date) => {
|
||||
return date.toLocaleDateString('en', {
|
||||
return date.toLocaleDateString(currentLocale, {
|
||||
month: 'short'
|
||||
});
|
||||
};
|
||||
const formatDay = (locale: string | undefined, date: Date) => {
|
||||
return date.toLocaleString('en', {
|
||||
return date.toLocaleString(currentLocale, {
|
||||
day: 'numeric'
|
||||
});
|
||||
};
|
||||
const formatShortWeekday = (locale: string | undefined, date: Date) => {
|
||||
return date.toLocaleString('en', {
|
||||
return date.toLocaleString(currentLocale, {
|
||||
weekday: 'short'
|
||||
});
|
||||
};
|
||||
@@ -101,6 +105,7 @@ const NiceCalendar = ({
|
||||
<div className="bg-dim"></div>
|
||||
<CalendarWrapper onClick={ () => onClickToClose() }>
|
||||
<Calendar
|
||||
locale={currentLocale}
|
||||
minDate={ minDate }
|
||||
maxDate={ maxDate }
|
||||
onChange={ onchangeToDate }
|
||||
|
||||
Reference in New Issue
Block a user