Skip to content

Commit

Permalink
Add more translation
Browse files Browse the repository at this point in the history
  • Loading branch information
chuigda committed Apr 29, 2024
1 parent 9203480 commit 9bc6632
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/components/panels/analysis/ReportPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const GameStats = memo(
.filter((a) => isBasicAnnotation(a))
.map((annotation) => {
const s = annotation as "??" | "?" | "?!" | "!!" | "!" | "!?";
const { name, color } = ANNOTATION_INFO[s];
const { name, color, translationKey } = ANNOTATION_INFO[s];
const w = whiteAnnotations[s];
const b = blackAnnotations[s];
return (
Expand All @@ -127,7 +127,7 @@ const GameStats = memo(
{annotation}
</Grid.Col>
<Grid.Col span={4} c={w + b > 0 ? color : undefined}>
{name}
{translationKey ? t(`Annotate.${translationKey}`) : name}
</Grid.Col>
<Grid.Col
className={cx(b > 0 && label)}
Expand Down
5 changes: 4 additions & 1 deletion src/components/panels/annotation/AnnotationEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import { useEditor } from "@tiptap/react";
import StarterKit from "@tiptap/starter-kit";
import { useAtomValue } from "jotai";
import { useContext } from "react";
import { useTranslation } from "react-i18next";
import { Markdown } from "tiptap-markdown";
import { useStore } from "zustand";

function AnnotationEditor() {
const { t } = useTranslation();

const store = useContext(TreeStateContext)!;
const root = useStore(store, (s) => s.root);
const position = useStore(store, (s) => s.position);
Expand All @@ -32,7 +35,7 @@ function AnnotationEditor() {
Markdown.configure({
linkify: true,
}),
Placeholder.configure({ placeholder: "Write here..." }),
Placeholder.configure({ placeholder: t("Board.Annotate.WriteHere") }),
],
content: currentNode.comment,
onUpdate: ({ editor }) => {
Expand Down
9 changes: 7 additions & 2 deletions src/components/panels/annotation/AnnotationPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
import { IconChevronDown } from "@tabler/icons-react";
import { atom, useAtom } from "jotai";
import { memo, useContext } from "react";
import { useTranslation } from "react-i18next";
import { useStore } from "zustand";
import AnnotationEditor from "./AnnotationEditor";

Expand All @@ -29,13 +30,17 @@ const SymbolButton = memo(function SymbolButton({
curAnnotations: Annotation[];
annotation: Annotation;
}) {
const { t } = useTranslation();

const store = useContext(TreeStateContext)!;
const setAnnotation = useStore(store, (s) => s.setAnnotation);
const { name, color } = ANNOTATION_INFO[annotation];
const { translationKey, name, color } = ANNOTATION_INFO[annotation];
const isActive = curAnnotations.includes(annotation);
const theme = useMantineTheme();
return (
<Tooltip label={name} position="bottom">
<Tooltip label={
translationKey ? t(`Annotate.${translationKey}`) : name
} position="bottom">
<ActionIcon
onClick={() => setAnnotation(annotation)}
variant={isActive ? "filled" : "default"}
Expand Down
26 changes: 16 additions & 10 deletions src/components/panels/database/DatabasePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import OpeningsTable from "./OpeningsTable";
import LichessOptionsPanel from "./options/LichessOptionsPanel";
import LocalOptionsPanel from "./options/LocalOptionsPanel";
import MasterOptionsPanel from "./options/MastersOptionsPanel";
import { useTranslation } from "react-i18next";

type DBType =
| { type: "local"; options: LocalOptions }
Expand Down Expand Up @@ -105,6 +106,8 @@ async function fetchOpening(db: DBType, tab: string) {
}

function DatabasePanel() {
const { t } = useTranslation();

const store = useContext(TreeStateContext)!;
const fen = useStore(store, (s) => s.currentNode().fen);
const referenceDatabase = useAtomValue(referenceDbAtom);
Expand Down Expand Up @@ -164,9 +167,9 @@ function DatabasePanel() {
<Group justify="space-between" w="100%">
<SegmentedControl
data={[
{ label: "Local", value: "local" },
{ label: "Lichess All", value: "lch_all" },
{ label: "Lichess Masters", value: "lch_master" },
{ label: t("Board.Database.Local"), value: "local" },
{ label: t("Board.Database.LichessAll"), value: "lch_all" },
{ label: t("Board.Database.LichessMaster"), value: "lch_master" },
]}
value={db}
onChange={(value) =>
Expand All @@ -176,10 +179,13 @@ function DatabasePanel() {

{tabType !== "options" && (
<Text>
{formatNumber(
Math.max(grandTotal || 0, openingData?.games.length || 0),
)}{" "}
matches
{
t("Board.Database.Matches", {
matches: formatNumber(
Math.max(grandTotal || 0, openingData?.games.length || 0),
)
})
}
</Text>
)}
</Group>
Expand All @@ -203,10 +209,10 @@ function DatabasePanel() {
dbType.type === "local" && dbType.options.type === "partial"
}
>
Stats
{t("Board.Database.Stats")}
</Tabs.Tab>
<Tabs.Tab value="games">Games</Tabs.Tab>
<Tabs.Tab value="options">Options</Tabs.Tab>
<Tabs.Tab value="games">{t("Board.Database.Games")}</Tabs.Tab>
<Tabs.Tab value="options">{t("Board.Database.Options")}</Tabs.Tab>
</Tabs.List>

<PanelWithError value="stats" error={error} type={db}>
Expand Down
9 changes: 6 additions & 3 deletions src/components/panels/database/NoDatabaseWarning.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { Text } from "@mantine/core";
import { Link } from "@tanstack/react-router";
import { useTranslation } from "react-i18next";

function NoDatabaseWarning() {
const { t } = useTranslation();

return (
<>
<Text>No reference database selected.</Text>
<Text>{t("Board.Database.NoReference1")}</Text>
<Text>
Please <Link to="/databases">add a database</Link> first and mark it as
the reference.
{t("Board.Database.NoReference2")} <Link to="/databases">{t("Board.Database.SelectReference")}</Link> {" "}
{t("Board.Database.NoReference3")}
</Text>
</>
);
Expand Down
53 changes: 53 additions & 0 deletions src/translation/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,47 @@ export const en_US = {
"GoMode.Nodes": "Nodes",
"GoMode.Infinite": "Infinite",

"Annotate.Brilliant": "Brilliant",
"Annotate.Good": "Good",
"Annotate.Interesting": "Interesting",
"Annotate.Dubious": "Dubious",
"Annotate.Mistake": "Mistake",
"Annotate.Blunder": "Blunder",
"Annotate.WhiteWinning": "White is winning",
"Annotate.WhiteAdvantage": "White has a clear advantage",
"Annotate.WhiteEdge": "White has a slight advantage",
"Annotate.Equal": "Equal position",
"Annotate.Unclear": "Unclear position",
"Annotate.BlackEdge": "Black has a slight advantage",
"Annotate.BlackAdvantage": "Black has a clear advantage",
"Annotate.BlackWinning": "Black is winning",
"Annotate.Novelty": "Novelty",
"Annotate.Development": "Development",
"Annotate.Initiative": "Initiative",
"Annotate.Attack": "Attack",
"Annotate.Counterplay": "Counterplay",
"Annotate.WithCompensation": "With compensation",
"Annotate.TimeTrouble": "Time Trouble",
"Annotate.WithIdea": "With the idea",
"Annotate.OnlyMove": "Only move",
"Annotate.Zugzwang": "Zugzwang",

"RichText.Bold": "Bold",
"RichText.Italic": "Italic",
"RichText.Underline": "Underline",
"RichText.Strike": "Strikethrough",
"RichText.ClearFormatting": "Clear formatting",
"RichText.H1": "Heading 1",
"RichText.H2": "Heading 2",
"RichText.H3": "Heading 3",
"RichText.H4": "Heading 4",
"RichText.Quote": "Blockquote",
"RichText.HLine": "Horizontal line",
"RichText.BulletList": "Bullet list",
"RichText.NumberedList": "Ordered list",
"RichText.Link": "Link",
"RichText.RemoveLink": "Remove link",

"Menu.File": "File",
"Menu.File.NewTab": "New Tab",
"Menu.File.OpenFile": "Open File",
Expand Down Expand Up @@ -126,6 +167,18 @@ export const en_US = {
"Board.Analysis.Analyze": "Analyze",
"Board.Analysis.Advantage": "Advantage",
"Board.Analysis.Accuracy": "Accuracy",
"Board.Database.Local": "Local",
"Board.Database.LichessAll": "Lichess All",
"Board.Database.LichessMaster": "Lichess Masters",
"Board.Database.Matches": "{{matches}} matches",
"Board.Database.Stats": "Stats",
"Board.Database.Games": "Games",
"Board.Database.Options": "Options",
"Board.Database.NoReference1": "No reference database selected.",
"Board.Database.NoReference2": "Please",
"Board.Database.SelectReference": "add a database",
"Board.Database.NoReference3": "first and mark it as the reference.",
"Board.Annotate.WriteHere": "Write here...",

"Engines.Title": "Your Engines",
"Engines.Settings.NoEngine": "No engine selected",
Expand Down
53 changes: 53 additions & 0 deletions src/translation/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,47 @@ export const zh_CN = {
"GoMode.Nodes": "局面数",
"GoMode.Infinite": "无限",

"Annotate.Brilliant": "Brilliant",
"Annotate.Good": "Good",
"Annotate.Interesting": "Interesting",
"Annotate.Dubious": "Dubious",
"Annotate.Mistake": "Mistake",
"Annotate.Blunder": "Blunder",
"Annotate.WhiteWinning": "白胜",
"Annotate.WhiteAdvantage": "白大优",
"Annotate.WhiteEdge": "白略优",
"Annotate.Equal": "均势",
"Annotate.Unclear": "局势不明",
"Annotate.BlackEdge": "黑略优",
"Annotate.BlackAdvantage": "黑大优",
"Annotate.BlackWinning": "黑胜",
"Annotate.Novelty": "新奇着法",
"Annotate.Development": "发展",
"Annotate.Initiative": "主动",
"Annotate.Attack": "进攻",
"Annotate.Counterplay": "反击",
"Annotate.WithCompensation": "优势补偿",
"Annotate.TimeTrouble": "无暇多虑",
"Annotate.WithIdea": "有想法",
"Annotate.OnlyMove": "唯一着法",
"Annotate.Zugzwang": "楚茨文克",

"RichText.Bold": "粗体",
"RichText.Italic": "斜体",
"RichText.Underline": "下划线",
"RichText.Strike": "删除线",
"RichText.ClearFormatting": "清除格式",
"RichText.H1": "一级标题",
"RichText.H2": "二级标题",
"RichText.H3": "三级标题",
"RichText.H4": "四级标题",
"RichText.Quote": "引用",
"RichText.HLine": "水平分隔",
"RichText.BulletList": "无序列表",
"RichText.NumberedList": "有序列表",
"RichText.Link": "链接",
"RichText.RemoveLink": "移除链接",

"Menu.File": "文件",
"Menu.File.NewTab": "新建标签页",
"Menu.File.OpenFile": "打开文件",
Expand Down Expand Up @@ -126,6 +167,18 @@ export const zh_CN = {
"Board.Analysis.Analyze": "分析",
"Board.Analysis.Advantage": "优势",
"Board.Analysis.Accuracy": "精度",
"Board.Database.Local": "本地",
"Board.Database.LichessAll": "Lichess 全部对局",
"Board.Database.LichessMaster": "Lichess 大师对局",
"Board.Database.Matches": "{{matches}} 个匹配的对局",
"Board.Database.Stats": "统计",
"Board.Database.Games": "对局",
"Board.Database.Options": "选项",
"Board.Database.NoReference1": "没有参考数据库",
"Board.Database.NoReference2": "请先",
"Board.Database.SelectReference": "添加一个数据库",
"Board.Database.NoReference3": "并将其作为参考",
"Board.Annotate.WriteHere": "在这里写评注...",

"Engines.Title": "引擎管理",
"Engines.Settings.NoEngine": "没有选中的引擎",
Expand Down
37 changes: 19 additions & 18 deletions src/utils/annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const NAG_INFO = new Map<string, Annotation>([
type AnnotationInfo = {
group?: string;
name: string;
translationKey?: string;
color?: MantineColor;
nag: number;
};
Expand All @@ -76,24 +77,24 @@ export const ANNOTATION_INFO: Record<Annotation, AnnotationInfo> = {
"?!": { group: "basic", name: "Dubious", color: "yellow", nag: 6 },
"?": { group: "basic", name: "Mistake", color: "orange", nag: 2 },
"??": { group: "basic", name: "Blunder", color: "red", nag: 4 },
"+-": { group: "advantage", name: "White is winning", nag: 18 },
"±": { group: "advantage", name: "White has a clear advantage", nag: 16 },
"⩲": { group: "advantage", name: "White has a slight advantage", nag: 14 },
"=": { group: "advantage", name: "Equal position", nag: 10 },
"∞": { group: "advantage", name: "Unclear position", nag: 13 },
"⩱": { group: "advantage", name: "Black has a slight advantage", nag: 15 },
"∓": { group: "advantage", name: "Black has a clear advantage", nag: 17 },
"-+": { group: "advantage", name: "Black is winning", nag: 19 },
N: { name: "Novelty", nag: 146 },
"↑↑": { name: "Development", nag: 32 },
"↑": { name: "Initiative", nag: 36 },
"→": { name: "Attack", nag: 40 },
"⇆": { name: "Counterplay", nag: 132 },
"=∞": { name: "With compensation", nag: 44 },
"⊕": { name: "Time Trouble", nag: 138 },
"∆": { name: "With the idea", nag: 140 },
"□": { name: "Only move", nag: 7 },
"⨀": { name: "Zugzwang", nag: 22 },
"+-": { group: "advantage", name: "White is winning", translationKey: "WhiteWinning", nag: 18 },
"±": { group: "advantage", name: "White has a clear advantage", translationKey: "WhiteAdvantage", nag: 16 },
"⩲": { group: "advantage", name: "White has a slight advantage", translationKey: "WhiteEdge", nag: 14 },
"=": { group: "advantage", name: "Equal position", translationKey: "Equal", nag: 10 },
"∞": { group: "advantage", name: "Unclear position", translationKey: "Unclear", nag: 13 },
"⩱": { group: "advantage", name: "Black has a slight advantage", translationKey: "BlackEdge", nag: 15 },
"∓": { group: "advantage", name: "Black has a clear advantage", translationKey: "BlackAdvantage", nag: 17 },
"-+": { group: "advantage", name: "Black is winning", translationKey: "BlackWinning", nag: 19 },
N: { name: "Novelty", translationKey: "Novelty", nag: 146 },
"↑↑": { name: "Development", translationKey: "Development", nag: 32 },
"↑": { name: "Initiative", translationKey: "Initiative", nag: 36 },
"→": { name: "Attack", translationKey: "Attack", nag: 40 },
"⇆": { name: "Counterplay", translationKey: "Counterplay", nag: 132 },
"=∞": { name: "With compensation", translationKey: "WithCompensation", nag: 44 },
"⊕": { name: "Time Trouble", translationKey: "TimeTrouble", nag: 138 },
"∆": { name: "With the idea", translationKey: "WithIdea", nag: 140 },
"□": { name: "Only move", translationKey: "OnlyMove", nag: 7 },
"⨀": { name: "Zugzwang", translationKey: "Zugzwang", nag: 22 },
};

export function isBasicAnnotation(
Expand Down

0 comments on commit 9bc6632

Please sign in to comment.