Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(i18n): 다국어 기능 지원 #28

Merged
merged 18 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.15.1
16.16.0
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ npm install @travelmakers/<package-name>
yarn add @travelmakers/<package-name>
```

```bash
# 개발모드
nvm install 16.16.0
npm install -g yarn
npm install -g commitizen
npm install -g cz-conventional-changelog-with-jiraid-detection
```

<!-- 구분!!! -->

## :rocket: Getting started
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hot-toast": "^2.4.0",
"swiper": "9.4.1"
"swiper": "9.4.1",
"lerna": "6.1.0"
},
"devDependencies": {
"@rollup/plugin-alias": "^3.1.8",
Expand Down
6 changes: 3 additions & 3 deletions packages/travelmakers-design-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@travelmakers/core",
"version": "0.0.147",
"version": "0.1.0",
"main": "cjs/packages/travelmakers-design-core/src/index.js",
"module": "esm/packages/travelmakers-design-core/src/index.js",
"types": "lib/index.d.ts",
Expand All @@ -24,8 +24,8 @@
"react-dom": ">=18.2.0"
},
"dependencies": {
"@travelmakers/hooks": "^0.0.20",
"@travelmakers/hooks": "^0.1.0",
"@travelmakers/styles": "^0.0.10",
"@travelmakers/utils": "^0.0.22"
"@travelmakers/utils": "^0.1.0"
}
}
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
Loading