Skip to content

Commit ee3dae3

Browse files
chore: organize translations keys
- Classify translation keys into categories - Correct a few errors on singular/plural forms in `en-US.tsx` - Merge the duplicate keys `definition` and `definitionTooltip` into `definitions` - Refactor a switch-key-case-return into a `Record<Key, string>`, making it sensitive to missing keys
1 parent ae8b524 commit ee3dae3

File tree

7 files changed

+85
-99
lines changed

7 files changed

+85
-99
lines changed

src/components/templates/CategoryTemplate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const CategoryTemplate: FC<CategoryTemplateProps> = ({
3030
{page.body.content.items.length > 0 && (
3131
<>
3232
<h2 id="definitions">
33-
<Translation translationKey="definition" />
33+
<Translation translationKey="definitions" />
3434
</h2>
3535
<ul class="subgridded">
3636
{page.body.content.items.map((item) => (

src/components/templates/FuncTemplate.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const FuncTemplate: FC<FuncTemplateProps> = ({
5353
</div>
5454

5555
<h2 id="parameters" class="flex items-baseline gap-1">
56-
<Translation translationKey="argument" />
56+
<Translation translationKey="parameters" />
5757
<Tooltip kind="parameters" />
5858
</h2>
5959

@@ -102,9 +102,9 @@ function ScopedDefinitions({
102102
{parent ? (
103103
// Currently, the scope has at most two levels.
104104
// Therefore, it is sufficient to only annotate the direct `parent`.
105-
<Translation translationKey="definitionOf" name={parent.name} />
105+
<Translation translationKey="definitionsOf" name={parent.name} />
106106
) : (
107-
<Translation translationKey="definition" />
107+
<Translation translationKey="definitions" />
108108
)}
109109
<Tooltip kind="definitions" />
110110
</h2>

src/components/templates/TypeTemplate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const TypeTemplate: FC<TypeTemplateProps> = ({
5353
{content.scope.length > 0 && (
5454
<>
5555
<h2 id="definitions" class="flex items-center gap-1">
56-
<Translation translationKey="definition" />
56+
<Translation translationKey="definitions" />
5757
<Tooltip kind="definitions" />
5858
</h2>
5959

src/components/ui/Tooltip.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import { Translation, translation } from "../../translation/";
33
import { CloseIcon, HelpCircleIcon } from "../icons";
44

55
export type TooltipProps = {
6-
kind:
6+
kind: // Function tooltips
77
| "element"
88
| "contextual"
9+
// Section tooltips
910
| "definitions"
1011
| "parameters"
12+
// Parameter tooltips
1113
| "variadic"
1214
| "settable"
1315
| "positional"
@@ -39,15 +41,15 @@ const tooltipContent: Record<
3941
textColor: "text-indigo-700",
4042
},
4143
definitions: {
42-
label: <Translation translationKey="definitionTooltip" />,
43-
desc: <Translation translationKey="definitionTooltipDescription" />,
44+
label: <Translation translationKey="definitions" />,
45+
desc: <Translation translationKey="definitionsDescription" />,
4446
isShowLabel: false,
4547
bgColor: "bg-gray-100",
4648
textColor: "text-gray-700",
4749
},
4850
parameters: {
49-
label: <Translation translationKey="argument" />,
50-
desc: <Translation translationKey="argumentDescription" />,
51+
label: <Translation translationKey="parameters" />,
52+
desc: <Translation translationKey="parametersDescription" />,
5153
isShowLabel: false,
5254
bgColor: "bg-gray-100",
5355
textColor: "text-gray-700",

src/translation/en-US.tsx

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,28 @@ export const translation: TranslationObject = {
1414
showInformation: (props: { name: string }) =>
1515
`Show details for ${props.name}`,
1616
tooltipKind: (props: { kind: TooltipProps["kind"] }) => {
17-
switch (props.kind) {
18-
case "element":
19-
return "Element";
20-
case "contextual":
21-
return "Contextual";
22-
case "definitions":
23-
return "Definition";
24-
case "parameters":
25-
return "Parameter";
26-
case "variadic":
27-
return "Variadic";
28-
case "settable":
29-
return "Settable";
30-
case "positional":
31-
return "Positional";
32-
case "required":
33-
return "Required";
34-
default:
35-
return props.kind;
36-
}
17+
const map: Record<TooltipProps["kind"], string> = {
18+
element: "Element",
19+
contextual: "Contextual",
20+
definitions: "Definitions",
21+
parameters: "Parameters",
22+
variadic: "Variadic",
23+
settable: "Settable",
24+
positional: "Positional",
25+
required: "Required",
26+
};
27+
return map[props.kind];
3728
},
3829
} as const;
3930

4031
export const Translation: TranslationComponent = (props) => {
4132
switch (props.translationKey) {
42-
case "definition":
43-
return <Fragment>Definition</Fragment>;
4433
case "constructor":
4534
return <Fragment>Constructor</Fragment>;
46-
case "definitionOf":
35+
case "definitionsOf":
4736
return (
4837
<Fragment>
49-
<code>{props.name}</code> Definition
38+
Definitions of <code>{props.name}</code>
5039
</Fragment>
5140
);
5241
case "search":
@@ -128,19 +117,19 @@ export const Translation: TranslationComponent = (props) => {
128117
Context functions can only be used when the context is known.
129118
</Fragment>
130119
);
131-
case "definitionTooltip":
132-
return <Fragment>Definition</Fragment>;
133-
case "definitionTooltipDescription":
120+
case "definitions":
121+
return <Fragment>Definitions</Fragment>;
122+
case "definitionsDescription":
134123
return (
135124
<Fragment>
136125
These functions and types can have related definitions. To access a
137126
definition, specify the name of the function or type, followed by the
138127
definition name separated by a period.
139128
</Fragment>
140129
);
141-
case "argument":
130+
case "parameters":
142131
return <Fragment>Parameter</Fragment>;
143-
case "argumentDescription":
132+
case "parametersDescription":
144133
return (
145134
<Fragment>
146135
Parameters are input values for functions. Specify them in parentheses

src/translation/index.tsx

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,62 +30,68 @@ export type TranslationObject = {
3030
};
3131

3232
type TranslationComponentKey =
33-
| "definition"
34-
| "constructor"
35-
| "tableOfContents"
36-
| "untranslated"
37-
| "untranslatedMessage"
38-
| "document"
39-
| "langVersion"
33+
// Function tooltips
4034
| "elementFunction"
4135
| "elementFunctionDescription"
4236
| "contextFunction"
4337
| "contextFunctionDescription"
44-
| "definitionTooltip"
45-
| "definitionTooltipDescription"
38+
// Section tooltips
39+
| "constructor"
40+
| "definitions" // See also `definitionsOf`
41+
| "definitionsDescription"
42+
| "parameters"
43+
| "parametersDescription"
44+
// Parameter tooltips
4645
| "variadic"
47-
| "translationRate"
4846
| "variadicDescription"
49-
| "typstOfficialDocs"
50-
| "typstOfficialWebsite"
47+
| "settable"
48+
| "settableDescription"
49+
| "positional"
50+
| "positionalDescription"
51+
| "required"
52+
| "requiredDescription"
53+
// Other texts in documentation
54+
| "tutorial"
55+
| "tutorialDescription"
56+
| "reference"
57+
| "referenceDescription"
58+
| "defaultValue"
59+
| "stringValues"
60+
| "showExample"
61+
// Translation statuses
62+
| "untranslated"
63+
| "untranslatedMessage"
5164
| "communityContent"
5265
| "contentAddedByCommunity"
5366
| "partiallyTranslated"
5467
| "partiallyTranslatedMessage"
5568
| "translated"
5669
| "translatedMessage"
57-
| "siteNoticeBannerTitle"
58-
| "siteNoticeBannerDescription"
59-
| "tutorial"
60-
| "tutorialDescription"
61-
| "referenceDescription"
62-
| "reference"
63-
| "openOfficialDocs"
70+
// Header, sidebar, and footer
71+
| "document"
72+
| "langVersion"
73+
| "translationRate"
6474
| "search"
65-
| "argument"
66-
| "argumentDescription"
67-
| "required"
68-
| "requiredDescription"
69-
| "positional"
70-
| "positionalDescription"
71-
| "defaultValue"
72-
| "stringValues"
73-
| "showExample"
74-
| "settable"
75-
| "settableDescription"
75+
| "typstOfficialWebsite"
76+
| "typstOfficialDocs"
77+
| "openOfficialDocs"
78+
| "tableOfContents"
79+
| "footer"
7680
| "previousPage"
7781
| "nextPage"
78-
| "footer";
82+
// Site notice
83+
| "siteNoticeBannerTitle"
84+
| "siteNoticeBannerDescription";
7985

8086
export type TranslationComponentProps =
8187
| { translationKey: TranslationComponentKey }
82-
| { translationKey: "definitionOf"; name: string };
88+
| { translationKey: "definitionsOf"; name: string };
8389

8490
/**
8591
* Translation component for UI text, descriptions, and other content to be embedded as JSX.
8692
*
8793
* @example
88-
* <Translation translationKey="definition" />
94+
* <Translation translationKey="definitions" />
8995
*/
9096
export type TranslationComponent = FC<TranslationComponentProps>;
9197

src/translation/ja-JP.tsx

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,25 @@ export const translation: TranslationObject = {
1919
openSearch: () => "検索を開く",
2020
showInformation: (props: { name: string }) => `${props.name}の詳細情報を表示`,
2121
tooltipKind: (props: { kind: TooltipProps["kind"] }) => {
22-
switch (props.kind) {
23-
case "element":
24-
return "要素関数";
25-
case "contextual":
26-
return "コンテキスト関数";
27-
case "definitions":
28-
return "定義";
29-
case "parameters":
30-
return "引数";
31-
case "variadic":
32-
return "可変長引数";
33-
case "settable":
34-
return "設定可能引数";
35-
case "positional":
36-
return "位置引数";
37-
case "required":
38-
return "必須引数";
39-
default:
40-
return props.kind;
41-
}
22+
const map: Record<TooltipProps["kind"], string> = {
23+
element: "要素関数",
24+
contextual: "コンテキスト関数",
25+
definitions: "定義",
26+
parameters: "引数",
27+
variadic: "可変長引数",
28+
settable: "設定可能引数",
29+
positional: "位置引数",
30+
required: "必須引数",
31+
};
32+
return map[props.kind];
4233
},
4334
} as const;
4435

4536
export const Translation: TranslationComponent = (props) => {
4637
switch (props.translationKey) {
47-
case "definition":
48-
return <Fragment>定義</Fragment>;
4938
case "constructor":
5039
return <Fragment>コンストラクタ</Fragment>;
51-
case "definitionOf":
40+
case "definitionsOf":
5241
return (
5342
<Fragment>
5443
<code>{props.name}</code>の定義
@@ -131,17 +120,17 @@ export const Translation: TranslationComponent = (props) => {
131120
コンテキスト関数は、コンテキストが既知の場合にのみ使用できます。
132121
</Fragment>
133122
);
134-
case "definitionTooltip":
123+
case "definitions":
135124
return <Fragment>定義</Fragment>;
136-
case "definitionTooltipDescription":
125+
case "definitionsDescription":
137126
return (
138127
<Fragment>
139128
これらの関数や型には、関連する定義を持たせることができます。定義にアクセスするには、対象の関数や型の名前を指定した後に、ピリオド区切りで定義名を記述します。
140129
</Fragment>
141130
);
142-
case "argument":
131+
case "parameters":
143132
return <Fragment>引数</Fragment>;
144-
case "argumentDescription":
133+
case "parametersDescription":
145134
return (
146135
<Fragment>
147136
引数は関数への入力値です。関数名の後に括弧で囲んで指定します。

0 commit comments

Comments
 (0)