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): add sample i18n for HomePage components #669

Merged
merged 3 commits into from
May 26, 2021
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
15 changes: 5 additions & 10 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@
"vite",
"vitejs"
],
"i18n-ally.localesPaths": [
"./packages/flat-i18n/locales/"
],
"i18n-ally.enabledFrameworks": [
"react",
"i18next"
],
"i18n-ally.keystyle": "flat",
"i18n-ally.localesPaths": ["./packages/flat-i18n/locales/"],
"i18n-ally.enabledFrameworks": ["react", "i18next"],
"i18n-ally.keystyle": "nested",
"i18n-ally.sourceLanguage": "zh-CN",
"i18n-ally.displayLanguage": "zh-CN",
}
"i18n-ally.displayLanguage": "zh-CN"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import emptyRoomSVG from "../../../assets/image/empty-room.svg";

import { clipboard } from "electron";
import { message, Skeleton } from "antd";
import React, { useCallback, useContext, useEffect, useState } from "react";
import React, { Fragment, useCallback, useContext, useEffect, useState } from "react";
import { observer } from "mobx-react-lite";
import { isSameDay } from "date-fns";
import {
Expand Down Expand Up @@ -128,12 +128,9 @@ export const MainRoomList = observer<MainRoomListProps>(function MainRoomList({
: { key: "join", text: "加入" };

return (
<>
{shouldShowDate && beginTime && (
<RoomListDate key={room.roomUUID + "-date"} date={beginTime} />
)}
<Fragment key={room.roomUUID}>
{shouldShowDate && beginTime && <RoomListDate date={beginTime} />}
<RoomListItem
key={room.roomUUID}
title={room.title!}
beginTime={beginTime}
endTime={endTime}
Expand Down Expand Up @@ -187,7 +184,7 @@ export const MainRoomList = observer<MainRoomListProps>(function MainRoomList({
}
}}
/>
</>
</Fragment>
);
},
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "./index.less";
import React from "react";
import { Radio } from "antd";
import classNames from "classnames";
import { useTranslation } from "react-i18next";

export type ClassPickerItemType = "oneToOne" | "bigClass" | "smallClass";

Expand All @@ -22,22 +23,11 @@ const ClassPickerIcons: Record<ClassPickerItemType, string> = {
smallClass: smallClassSVG,
};

const ClassPickerTitles: Record<ClassPickerItemType, string> = {
bigClass: "大班课",
oneToOne: "一对一",
smallClass: "小班课",
};

const ClassPickerTexts: Record<ClassPickerItemType, string> = {
bigClass: "适用于 1 位老师面向大量学生",
oneToOne: "适用于 1 位老师与 1 名学生",
smallClass: "适用于 1 位老师面向最多 16 名学生",
};

export const ClassPickerItem: React.FC<Pick<ClassPickerProps, "type" | "large">> = ({
type,
large,
}) => {
const { t } = useTranslation();
return (
<Radio value={type}>
{large ? (
Expand All @@ -48,18 +38,22 @@ export const ClassPickerItem: React.FC<Pick<ClassPickerProps, "type" | "large">>
></img>
<div className="class-large-picker-item-right">
<span className="class-large-picker-item-title">
{ClassPickerTitles[type]}
{t(`class-picker-title.${type}`)}
</span>
<span className="class-large-picker-item-content">
{ClassPickerTexts[type]}
{t(`class-picker-text.${type}`)}
</span>
</div>
</div>
) : (
<div className="class-picker-item-container">
<img className="class-picker-item-icon" src={ClassPickerIcons[type]}></img>
<span className="class-picker-item-title">{ClassPickerTitles[type]}</span>
<span className="class-picker-item-content">{ClassPickerTexts[type]}</span>
<span className="class-picker-item-title">
{t(`class-picker-title.${type}`)}
</span>
<span className="class-picker-item-content">
{t(`class-picker-text.${type}`)}
</span>
</div>
)}
</Radio>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import createSVG from "./icons/create.svg";
import scheduleSVG from "./icons/schedule.svg";
import React from "react";
import { Button } from "antd";
import { useTranslation } from "react-i18next";

type HomePageHeroButtonType = "join" | "create" | "schedule";

Expand Down Expand Up @@ -33,17 +34,12 @@ export interface HomePageHeroButtonProps {
onClick?: () => void;
}

const HomePageHeroButtonTypeTexts: Record<HomePageHeroButtonType, string> = {
join: "加入房间",
create: "创建房间",
schedule: "预定房间",
};

export const HomePageHeroButton: React.FC<HomePageHeroButtonProps> = ({ type, onClick }) => {
const { t } = useTranslation();
return (
<HomePageHeroButtonBase
type={type}
text={HomePageHeroButtonTypeTexts[type]}
text={t(`home-page-hero-button-type.${type}`)}
onClick={onClick}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { format, isToday, isTomorrow } from "date-fns";
import { zhCN } from "date-fns/locale";
import classNames from "classnames";
import { Button, Dropdown, Menu } from "antd";
import { useTranslation } from "react-i18next";

export interface RoomListDateProps {
date: Date;
Expand Down Expand Up @@ -49,12 +50,6 @@ export interface RoomListItemProps<T extends string> {
onClickMenu?: (key: T) => void;
}

const RoomStatusTexts: Record<RoomStatusType, string> = {
idle: "待开始",
running: "进行中",
stopped: "已结束",
};

export function RoomListItem<T extends string = string>({
title,
beginTime,
Expand All @@ -65,6 +60,7 @@ export function RoomListItem<T extends string = string>({
onClick,
onClickMenu,
}: PropsWithChildren<RoomListItemProps<T>>): ReactElement {
const { t } = useTranslation();
return (
<div className="room-list-item">
<div
Expand All @@ -81,7 +77,7 @@ export function RoomListItem<T extends string = string>({
</div>
)}
<div className="room-list-item-status">
<span className={status}>{RoomStatusTexts[status]}</span>
<span className={status}>{t(`room-status.${status}`)}</span>
{isPeriodic && <span className="periodic">周期</span>}
</div>
</div>
Expand Down
22 changes: 21 additions & 1 deletion packages/flat-i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,25 @@
"student-exit-room-tip": "The class is continuing, are you sure to leave the room?",
"student-sure-to-exit-the-room": "Sure to exit the room",
"teacher-left-temporarily": "The teacher leaves temporarily",
"the-room-has-ended-and-is-about-to-exit": "The room has ended and is about to exit..."
"the-room-has-ended-and-is-about-to-exit": "The room has ended and is about to exit...",
"class-picker-text": {
"bigClass": "Suitable for 1 teacher for a large number of students",
"oneToOne": "Suitable for 1 teacher and 1 student",
"smallClass": "Suitable for 1 teacher for up to 16 students"
},
"class-picker-title": {
"bigClass": "Large Class",
"oneToOne": "One to One",
"smallClass": "Small Class"
},
"home-page-hero-button-type": {
"create": "Create",
"join": "Join",
"schedule": "Schedule"
},
"room-status": {
"idle": "idle",
"running": "running",
"stopped": "stopped"
}
}
22 changes: 21 additions & 1 deletion packages/flat-i18n/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,25 @@
"network-quality5": "网络质量非常差",
"network-quality6": "网络连接已断开",
"network-quality7": "暂时无法检测网络质量",
"network-quality8": "正在检测..."
"network-quality8": "正在检测...",
"room-status": {
"idle": "待开始",
"running": "进行中",
"stopped": "已结束"
},
"home-page-hero-button-type": {
"join": "加入房间",
"create": "创建房间",
"schedule": "预定房间"
},
"class-picker-title": {
"bigClass": "大班课",
"oneToOne": "一对一",
"smallClass": "小班课"
},
"class-picker-text": {
"bigClass": "适用于 1 位老师面向大量学生",
"oneToOne": "适用于 1 位老师与 1 名学生",
"smallClass": "适用于 1 位老师面向最多 16 名学生"
}
}