Skip to content

Commit

Permalink
feat(i18n): 다국어 처리 (#26)
Browse files Browse the repository at this point in the history
* feat(calendar): 캘린더 다국어 처리

* feat(calendar): 박수 부분 영어 전환

* feat(card): 카드 컴포넌트에 대해서 i18n 다국어 적용

* feat(getpaymethod): getPayMethod i18n 다국어 처리

* feat(utils): timeline에 대한 i18n 다국어 번역 추가
  • Loading branch information
sgd122 committed Jan 18, 2024
1 parent 26a2eed commit f107cf6
Show file tree
Hide file tree
Showing 24 changed files with 1,639 additions and 694 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useCalendar, useUpdateEffect } from "@travelmakers/hooks";
import { ko, enUS } from "date-fns/locale";
import { PolymorphicRef } from "@travelmakers/styles";
import React, {
forwardRef,
Expand Down Expand Up @@ -49,6 +50,15 @@ export interface Props {
topIndicatorPosition?: string;

loadingImageSrc?: string;

indicatorText: {
from: string;
to: string;
descriptionFrom: string;
descriptionTo: string;
};

locale?: "ko" | "en";
}

/**
Expand Down Expand Up @@ -77,14 +87,18 @@ export const Calendar = forwardRef(
onChange,
onClick,
loadingImageSrc,
indicatorText,
locale = "ko",
children,
className,
...props
}: PropsWithChildren<CalendarProps<C>>,
ref: PolymorphicRef<C>
) => {
const { classes, cx } = useStyles();
const [state, actions] = useCalendar(null);
const [state, actions] = useCalendar(null, {
locale: locale === "ko" ? ko : enUS,
});
const deferredState = useDeferredValue(state);
const [isPending, startTransition] = useTransition();
const [checked, setChecked] = useState<SelectedDays>({
Expand Down Expand Up @@ -135,10 +149,13 @@ export const Calendar = forwardRef(
selected={selected}
type={type}
topIndicatorPosition={topIndicatorPosition}
text={indicatorText}
locale={locale}
/>
<div className={classes.calendar}>
{deferredState && (
<DateTable
locale={locale}
checked={checked}
setChecked={setChecked}
type={type}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from "./DateCell.type";
import { SelectedDays } from "../../Calendar.type";
import { differenceInDays, isEqual } from "date-fns";
import { log } from "next/dist/server/typescript/utils";

export interface Props {
selectableDates: string[];
Expand All @@ -23,12 +24,14 @@ export interface Props {
enabledDays: Date;
minNight: number;
type: "tour" | "move-in";
locale?: "ko" | "en";
}

export const DateCell = React.memo(
forwardRef(
<C extends React.ElementType = "td">(
{
locale,
day,
visible,
checked,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface Props {
months: string[];
years: number[];
weeks?: CalendarState["weeks"];
locale?: "ko" | "en";
}

export const DateTable = React.memo(
Expand All @@ -40,6 +41,7 @@ export const DateTable = React.memo(
months,
years,
weeks,
locale,
className,
...props
}: DateTableProps<C>,
Expand Down Expand Up @@ -197,15 +199,17 @@ export const DateTable = React.memo(
const year = years[index];
if (!year) return null;
const title = `${year}${month}`;
const titleEN = `${month} ${year}`;
return (
<DateYear
locale={locale}
key={title}
checked={checked}
betweenDays={betweenDays}
type={type}
disabledDays={disabledDays}
selectableDates={selectableDates}
title={title}
title={locale === "ko" ? title : titleEN}
hotelName={hotelName}
year={year}
month={month}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import _ from "lodash";
import { getMonth } from "date-fns";
import { DateCellDay, DateCellType } from "../DateCell/DateCell.type";
import { SelectedDays } from "../../Calendar.type";
import { getDate } from "@travelmakers/utils";

export interface Props {
title: string;
Expand All @@ -27,12 +28,14 @@ export interface Props {
enabledDays: Date;
minNight: number;
type: "tour" | "move-in";
locale?: "ko" | "en";
}

export const DateYear = React.memo(
forwardRef(
<C extends React.ElementType = "div">(
{
locale,
title,
hotelName,
checked,
Expand All @@ -58,14 +61,14 @@ export const DateYear = React.memo(
return (
<>
<div className={classes.tableHead}>
<HeadMonthly title={title} onClear={onClear} />
<HeadMonthly title={title} onClear={onClear} locale={locale} />
</div>
<table>
<caption className={"sr-only"}>
{hotelName && `${hotelName} :`} {title} 달력
</caption>
<thead className={classes.mt10}>
<HeadTitle />
<HeadTitle locale={locale} />
</thead>
<tbody>
{weeks
Expand All @@ -82,9 +85,16 @@ export const DateYear = React.memo(
<tr>
{week.map((day) => {
if (!day.year) return null;
const visibleKO =
_.first(week).month ===
`${getMonth(day.date) + 1}월`;
const visibleEN =
_.first(week).month ===
getDate(day.date, "MMMM").format;
return (
<DateCell
key={`${weeklyKey}-${day.dayOfMonth}day`}
locale={locale}
day={day}
betweenDays={betweenDays}
dateBreak={dateBreak}
Expand All @@ -95,10 +105,7 @@ export const DateYear = React.memo(
disabledDays={disabledDays}
selectableDates={selectableDates}
onClick={onClick}
visible={
_.first(week).month ===
`${getMonth(day.date) + 1}월`
}
visible={locale === "ko" ? visibleKO : visibleEN}
/>
);
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ import { Button } from "../../../Button";
const HeadMonthly = ({
title,
onClear,
locale = "ko",
}: {
title: string;
onClear: () => void;
locale?: "ko" | "en";
}) => {
return (
<>
<Typography level="subhead2" color="primary1" strong>
{title}
</Typography>
<Button variant="text" size="small" roundness onClick={onClear}>
초기화
{locale === "ko" ? "초기화" : "clear"}
</Button>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import React from "react";
import { Typography } from "../../../Typography";
import useStyles from "../../Calendar.style";

const DAYS = ["일", "월", "화", "수", "목", "금", "토"];
const DAYS_KO = ["일", "월", "화", "수", "목", "금", "토"];
const DAYS_EN = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];

const HeadTitle: React.FC = () => {
const HeadTitle: React.FC<{ locale?: "ko" | "en" }> = ({ locale = "ko" }) => {
const { classes, cx } = useStyles();
const days = locale === "ko" ? DAYS_KO : DAYS_EN;
return (
<tr>
{DAYS.map((day) => {
{days.map((day) => {
return (
<th key={day} className={classes.tableCell}>
<Typography level="body2" color="primary1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ export default createStyles(
indicatorDateCountBox: {
margin: "auto 0",
["& > div"]: {
width: "56px",
minWidth: "56px",
height: "28px",
padding: `0 ${theme.spacing.spacing10}`,
border: `1px solid ${theme.colors.primary1}`,
borderRadius: theme.radius.radius100,
textAlign: "center",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,25 @@ import { SelectedDays } from "../../Calendar.type";
export interface Props {
selected: SelectedDays;
type: "tour" | "move-in";
text: {
from: string;
to: string;
descriptionFrom: string;
descriptionTo: string;
};
topIndicatorPosition?: string;
locale?: "ko" | "en";
}

export const Indicator: React.FC<Props> = ({
selected,
type,
topIndicatorPosition,
text,
locale = "ko",
}) => {
const { classes } = useStyles({ topIndicatorPosition });
const isTour = type === "tour";
const headlineText = {
from: !isTour ? "체크인" : "투어 예정일",
to: !isTour ? "체크아웃" : "투어 예정 시간",
description: !isTour
? "일정을 <br /> 선택해주세요."
: "시간을 <br /> 선택해주세요.",
};

const generateToHeadlineText = () => {
if (isTour) {
Expand All @@ -34,7 +36,7 @@ export const Indicator: React.FC<Props> = ({
<Typography
level="caption"
color="primary3"
dangerouslySetInnerHTML={{ __html: headlineText.description }}
dangerouslySetInnerHTML={{ __html: text.descriptionTo }}
/>
);
}
Expand All @@ -51,7 +53,7 @@ export const Indicator: React.FC<Props> = ({
<Typography
level="caption"
color="primary3"
dangerouslySetInnerHTML={{ __html: headlineText.description }}
dangerouslySetInnerHTML={{ __html: text.descriptionTo }}
/>
);
}
Expand All @@ -61,7 +63,7 @@ export const Indicator: React.FC<Props> = ({
{getDate(selected.to.date).format}
</Typography>
<Typography level="caption" color="primary1">
{getDay(selected.to.date)}
{getDay(selected.to.date, locale)}
</Typography>
</div>
);
Expand All @@ -73,28 +75,30 @@ export const Indicator: React.FC<Props> = ({
<div className={classes.indicatorInnerBox}>
<div>
<Typography level="body3" color="secondary1" strong>
{headlineText.from}
{text.from}
</Typography>

{!selected.from ? (
<Typography level="caption" color="primary3">
일정을 <br /> 선택해주세요.
</Typography>
<Typography
level="caption"
color="primary3"
dangerouslySetInnerHTML={{ __html: text.descriptionFrom }}
/>
) : (
<div className={classes.indicatorSelectedDay}>
<Typography level="subhead1" color="primary1" strong>
{getDate(selected.from.date).format}
</Typography>
<Typography level="caption" color="primary1">
{getDay(selected.from.date)}
{getDay(selected.from.date, locale)}
</Typography>
</div>
)}
</div>
<Divider type={"vertical"} color="outline" />
<div>
<Typography level="body3" color="secondary1" strong>
{headlineText.to}
{text.to}
</Typography>

{generateToHeadlineText()}
Expand All @@ -108,7 +112,8 @@ export const Indicator: React.FC<Props> = ({
level="subhead2"
color="primary1"
>
{differenceInDays(selected.to.date, selected.from.date)}
{differenceInDays(selected.to.date, selected.from.date)}
{locale === "ko" ? "박" : " nights"}
</Typography>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ export const Default = (props) => {
topIndicatorPosition="0px"
selected={selected}
onChange={setSelected}
indicatorText={{
from: "Tour date",
to: "Tour time",
descriptionFrom: "Please <br/> select a schedule.",
descriptionTo: "Please <br/> select a time.",
}}
>
<Calendar.OptionBox
title={"시간 선택하기"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export interface Props {

/** true일 경우 HotelCard 컴포넌트가 disabled 됩니다. */
disabled?: boolean;

locale?: "ko" | "en";
}

export const HotelCard = forwardRef(
Expand All @@ -58,6 +60,7 @@ export const HotelCard = forwardRef(
price = [],
isCoupon,
disabled = false,
locale = "ko",
className,
...props
}: HotelCardProps<C>,
Expand All @@ -84,7 +87,7 @@ export const HotelCard = forwardRef(
Sold Out
</Typography>
<Typography color="white" level="body2">
다음에 만나요
{locale === "ko" ? "다음에 만나요" : "See you next time"}
</Typography>
</div>
) : (
Expand Down
Loading

0 comments on commit f107cf6

Please sign in to comment.