Skip to content

Commit bff2fc7

Browse files
committed
localize remaining theme components
1 parent 8b85f97 commit bff2fc7

File tree

10 files changed

+307
-46
lines changed

10 files changed

+307
-46
lines changed

packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/Body/index.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import React from "react";
99

10+
import { translate } from "@docusaurus/Translate";
11+
1012
import json2xml from "@theme/ApiExplorer/Body/json2xml";
1113
import FormFileUpload from "@theme/ApiExplorer/FormFileUpload";
1214
import FormItem from "@theme/ApiExplorer/FormItem";
@@ -17,6 +19,7 @@ import { useTypedDispatch, useTypedSelector } from "@theme/ApiItem/hooks";
1719
import Markdown from "@theme/Markdown";
1820
import SchemaTabs from "@theme/SchemaTabs";
1921
import TabItem from "@theme/TabItem";
22+
import { OPENAPI_BODY, OPENAPI_REQUEST } from "@theme/translationIds";
2023
import { RequestBodyObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
2124
import format from "xml-formatter";
2225

@@ -98,7 +101,10 @@ function Body({
98101
return (
99102
<FormItem>
100103
<FormFileUpload
101-
placeholder={schema.description || "Body"}
104+
placeholder={
105+
schema.description ||
106+
translate({ id: OPENAPI_REQUEST.BODY_TITLE, message: "Body" })
107+
}
102108
onChange={(file: any) => {
103109
if (file === undefined) {
104110
dispatch(clearRawBody());
@@ -302,7 +308,10 @@ function Body({
302308
<SchemaTabs className="openapi-tabs__schema" lazy>
303309
{/* @ts-ignore */}
304310
<TabItem
305-
label="Example (from schema)"
311+
label={translate({
312+
id: OPENAPI_BODY.EXAMPLE_FROM_SCHEMA,
313+
message: "Example (from schema)",
314+
})}
306315
value="Example (from schema)"
307316
default
308317
>
@@ -334,7 +343,10 @@ function Body({
334343
<SchemaTabs className="openapi-tabs__schema" lazy>
335344
{/* @ts-ignore */}
336345
<TabItem
337-
label="Example (from schema)"
346+
label={translate({
347+
id: OPENAPI_BODY.EXAMPLE_FROM_SCHEMA,
348+
message: "Example (from schema)",
349+
})}
338350
value="Example (from schema)"
339351
default
340352
>

packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/FormItem/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
import React from "react";
99

10+
import { translate } from "@docusaurus/Translate";
11+
import { OPENAPI_SCHEMA_ITEM } from "@theme/translationIds";
12+
1013
import clsx from "clsx";
1114

1215
export interface Props {
@@ -24,7 +27,11 @@ function FormItem({ label, type, required, children, className }: Props) {
2427
<label className="openapi-explorer__form-item-label">{label}</label>
2528
)}
2629
{type && <span style={{ opacity: 0.6 }}>{type}</span>}
27-
{required && <span className="openapi-schema__required">required</span>}
30+
{required && (
31+
<span className="openapi-schema__required">
32+
{translate({ id: OPENAPI_SCHEMA_ITEM.REQUIRED, message: "required" })}
33+
</span>
34+
)}
2835
<div>{children}</div>
2936
</div>
3037
);

packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/SecuritySchemes/index.tsx

Lines changed: 117 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
import React from "react";
99

10+
import { translate } from "@docusaurus/Translate";
11+
import { OPENAPI_SECURITY_SCHEMES } from "@theme/translationIds";
12+
1013
import Link from "@docusaurus/Link";
1114
import { useTypedSelector } from "@theme/ApiItem/hooks";
1215

@@ -48,16 +51,31 @@ function SecuritySchemes(props: any) {
4851
}}
4952
>
5053
<span>
51-
<strong>name:</strong>{" "}
54+
<strong>
55+
{translate({
56+
id: OPENAPI_SECURITY_SCHEMES.NAME,
57+
message: "name:",
58+
})}
59+
</strong>{" "}
5260
<Link to={infoAuthPath}>{name ?? key}</Link>
5361
</span>
5462
<span>
55-
<strong>type: </strong>
63+
<strong>
64+
{translate({
65+
id: OPENAPI_SECURITY_SCHEMES.TYPE,
66+
message: "type:",
67+
})}
68+
</strong>{" "}
5669
{type}
5770
</span>
5871
{scopes && scopes.length > 0 && (
5972
<span>
60-
<strong>scopes: </strong>
73+
<strong>
74+
{translate({
75+
id: OPENAPI_SECURITY_SCHEMES.SCOPES,
76+
message: "scopes:",
77+
})}
78+
</strong>{" "}
6179
<code>
6280
{auth.scopes.length > 0 ? auth.scopes.toString() : "[]"}
6381
</code>
@@ -89,16 +107,31 @@ function SecuritySchemes(props: any) {
89107
}}
90108
>
91109
<span>
92-
<strong>name:</strong>{" "}
110+
<strong>
111+
{translate({
112+
id: OPENAPI_SECURITY_SCHEMES.NAME,
113+
message: "name:",
114+
})}
115+
</strong>{" "}
93116
<Link to={infoAuthPath}>{name ?? key}</Link>
94117
</span>
95118
<span>
96-
<strong>type: </strong>
119+
<strong>
120+
{translate({
121+
id: OPENAPI_SECURITY_SCHEMES.TYPE,
122+
message: "type:",
123+
})}
124+
</strong>{" "}
97125
{type}
98126
</span>
99127
{scopes && scopes.length > 0 && (
100128
<span>
101-
<strong>scopes: </strong>
129+
<strong>
130+
{translate({
131+
id: OPENAPI_SECURITY_SCHEMES.SCOPES,
132+
message: "scopes:",
133+
})}
134+
</strong>{" "}
102135
<code>
103136
{auth.scopes.length > 0 ? auth.scopes.toString() : "[]"}
104137
</code>
@@ -128,15 +161,30 @@ function SecuritySchemes(props: any) {
128161
}}
129162
>
130163
<span>
131-
<strong>name:</strong>{" "}
164+
<strong>
165+
{translate({
166+
id: OPENAPI_SECURITY_SCHEMES.NAME,
167+
message: "name:",
168+
})}
169+
</strong>{" "}
132170
<Link to={infoAuthPath}>{auth.name ?? auth.key}</Link>
133171
</span>
134172
<span>
135-
<strong>type: </strong>
173+
<strong>
174+
{translate({
175+
id: OPENAPI_SECURITY_SCHEMES.TYPE,
176+
message: "type:",
177+
})}
178+
</strong>{" "}
136179
{auth.type}
137180
</span>
138181
<span>
139-
<strong>in: </strong>
182+
<strong>
183+
{translate({
184+
id: OPENAPI_SECURITY_SCHEMES.IN,
185+
message: "in:",
186+
})}
187+
</strong>{" "}
140188
{auth.in}
141189
</span>
142190
</pre>
@@ -156,16 +204,31 @@ function SecuritySchemes(props: any) {
156204
}}
157205
>
158206
<span>
159-
<strong>name:</strong>{" "}
207+
<strong>
208+
{translate({
209+
id: OPENAPI_SECURITY_SCHEMES.NAME,
210+
message: "name:",
211+
})}
212+
</strong>{" "}
160213
<Link to={infoAuthPath}>{name ?? key}</Link>
161214
</span>
162215
<span>
163-
<strong>type: </strong>
216+
<strong>
217+
{translate({
218+
id: OPENAPI_SECURITY_SCHEMES.TYPE,
219+
message: "type:",
220+
})}
221+
</strong>{" "}
164222
{type}
165223
</span>
166224
{scopes && scopes.length > 0 && (
167225
<span>
168-
<strong>scopes: </strong>
226+
<strong>
227+
{translate({
228+
id: OPENAPI_SECURITY_SCHEMES.SCOPES,
229+
message: "scopes:",
230+
})}
231+
</strong>{" "}
169232
<code>
170233
{auth.scopes.length > 0 ? auth.scopes.toString() : "[]"}
171234
</code>
@@ -198,16 +261,31 @@ function SecuritySchemes(props: any) {
198261
}}
199262
>
200263
<span>
201-
<strong>name:</strong>{" "}
264+
<strong>
265+
{translate({
266+
id: OPENAPI_SECURITY_SCHEMES.NAME,
267+
message: "name:",
268+
})}
269+
</strong>{" "}
202270
<Link to={infoAuthPath}>{name ?? key}</Link>
203271
</span>
204272
<span>
205-
<strong>type: </strong>
273+
<strong>
274+
{translate({
275+
id: OPENAPI_SECURITY_SCHEMES.TYPE,
276+
message: "type:",
277+
})}
278+
</strong>{" "}
206279
{type}
207280
</span>
208281
{scopes && scopes.length > 0 && (
209282
<span>
210-
<strong>scopes: </strong>
283+
<strong>
284+
{translate({
285+
id: OPENAPI_SECURITY_SCHEMES.SCOPES,
286+
message: "scopes:",
287+
})}
288+
</strong>{" "}
211289
<code>
212290
{auth.scopes.length > 0 ? auth.scopes.toString() : "[]"}
213291
</code>
@@ -226,7 +304,12 @@ function SecuritySchemes(props: any) {
226304
{flows && (
227305
<span>
228306
<code>
229-
<strong>flows: </strong>
307+
<strong>
308+
{translate({
309+
id: OPENAPI_SECURITY_SCHEMES.FLOWS,
310+
message: "flows:",
311+
})}
312+
</strong>{" "}
230313
{JSON.stringify(flows, null, 2)}
231314
</code>
232315
</span>
@@ -248,16 +331,31 @@ function SecuritySchemes(props: any) {
248331
}}
249332
>
250333
<span>
251-
<strong>name:</strong>{" "}
334+
<strong>
335+
{translate({
336+
id: OPENAPI_SECURITY_SCHEMES.NAME,
337+
message: "name:",
338+
})}
339+
</strong>{" "}
252340
<Link to={infoAuthPath}>{name ?? key}</Link>
253341
</span>
254342
<span>
255-
<strong>type: </strong>
343+
<strong>
344+
{translate({
345+
id: OPENAPI_SECURITY_SCHEMES.TYPE,
346+
message: "type:",
347+
})}
348+
</strong>{" "}
256349
{type}
257350
</span>
258351
{scopes && scopes.length > 0 && (
259352
<span>
260-
<strong>scopes: </strong>
353+
<strong>
354+
{translate({
355+
id: OPENAPI_SECURITY_SCHEMES.SCOPES,
356+
message: "scopes:",
357+
})}
358+
</strong>{" "}
261359
<code>
262360
{auth.scopes.length > 0 ? auth.scopes.toString() : "[]"}
263361
</code>

packages/docusaurus-theme-openapi-docs/src/theme/ParamsDetails/index.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
import React from "react";
99

10+
import { translate } from "@docusaurus/Translate";
11+
import { OPENAPI_PARAMS_DETAILS } from "@theme/translationIds";
12+
1013
import BrowserOnly from "@docusaurus/BrowserOnly";
1114
import Details from "@theme/Details";
1215
import ParamsItem from "@theme/ParamsItem";
@@ -31,7 +34,13 @@ const ParamsDetailsComponent: React.FC<Props> = ({ parameters }) => {
3134
const summaryElement = (
3235
<summary>
3336
<h3 className="openapi-markdown__details-summary-header-params">
34-
{`${type.charAt(0).toUpperCase() + type.slice(1)} Parameters`}
37+
{translate(
38+
{
39+
id: OPENAPI_PARAMS_DETAILS.PARAMETERS_TITLE,
40+
message: "{type} Parameters",
41+
},
42+
{ type: type.charAt(0).toUpperCase() + type.slice(1) }
43+
)}
3544
</h3>
3645
</summary>
3746
);

0 commit comments

Comments
 (0)