Skip to content

Commit 8b85f97

Browse files
committed
Add i18n wrappers across more theme components
1 parent 890e247 commit 8b85f97

13 files changed

Lines changed: 226 additions & 30 deletions

File tree

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

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77

88
import React from "react";
99

10+
import { translate } from "@docusaurus/Translate";
1011
import FormItem from "@theme/ApiExplorer/FormItem";
1112
import FormSelect from "@theme/ApiExplorer/FormSelect";
1213
import FormTextInput from "@theme/ApiExplorer/FormTextInput";
1314
import { useTypedDispatch, useTypedSelector } from "@theme/ApiItem/hooks";
15+
import { OPENAPI_AUTH } from "@theme/translationIds";
1416

1517
import { setAuthData, setSelectedAuth } from "./slice";
1618

@@ -45,9 +47,18 @@ function Authorization() {
4547
{selectedAuth.map((a: any) => {
4648
if (a.type === "http" && a.scheme === "bearer") {
4749
return (
48-
<FormItem label="Bearer Token" key={a.key + "-bearer"}>
50+
<FormItem
51+
label={translate({
52+
id: OPENAPI_AUTH.BEARER_TOKEN,
53+
message: "Bearer Token",
54+
})}
55+
key={a.key + "-bearer"}
56+
>
4957
<FormTextInput
50-
placeholder="Bearer Token"
58+
placeholder={translate({
59+
id: OPENAPI_AUTH.BEARER_TOKEN,
60+
message: "Bearer Token",
61+
})}
5162
password
5263
value={data[a.key].token ?? ""}
5364
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
@@ -67,9 +78,18 @@ function Authorization() {
6778

6879
if (a.type === "oauth2") {
6980
return (
70-
<FormItem label="Bearer Token" key={a.key + "-oauth2"}>
81+
<FormItem
82+
label={translate({
83+
id: OPENAPI_AUTH.BEARER_TOKEN,
84+
message: "Bearer Token",
85+
})}
86+
key={a.key + "-oauth2"}
87+
>
7188
<FormTextInput
72-
placeholder="Bearer Token"
89+
placeholder={translate({
90+
id: OPENAPI_AUTH.BEARER_TOKEN,
91+
message: "Bearer Token",
92+
})}
7393
password
7494
value={data[a.key].token ?? ""}
7595
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
@@ -90,9 +110,17 @@ function Authorization() {
90110
if (a.type === "http" && a.scheme === "basic") {
91111
return (
92112
<React.Fragment key={a.key + "-basic"}>
93-
<FormItem label="Username">
113+
<FormItem
114+
label={translate({
115+
id: OPENAPI_AUTH.USERNAME,
116+
message: "Username",
117+
})}
118+
>
94119
<FormTextInput
95-
placeholder="Username"
120+
placeholder={translate({
121+
id: OPENAPI_AUTH.USERNAME,
122+
message: "Username",
123+
})}
96124
value={data[a.key].username ?? ""}
97125
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
98126
const value = e.target.value;
@@ -106,9 +134,17 @@ function Authorization() {
106134
}}
107135
/>
108136
</FormItem>
109-
<FormItem label="Password">
137+
<FormItem
138+
label={translate({
139+
id: OPENAPI_AUTH.PASSWORD,
140+
message: "Password",
141+
})}
142+
>
110143
<FormTextInput
111-
placeholder="Password"
144+
placeholder={translate({
145+
id: OPENAPI_AUTH.PASSWORD,
146+
message: "Password",
147+
})}
112148
password
113149
value={data[a.key].password ?? ""}
114150
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {

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

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

88
import React, { useState } from "react";
99

10+
import { translate } from "@docusaurus/Translate";
1011
import FloatingButton from "@theme/ApiExplorer/FloatingButton";
12+
import { OPENAPI_FORM_FILE_UPLOAD } from "@theme/translationIds";
1113
import MagicDropzone from "react-magic-dropzone";
1214

1315
type PreviewFile = { preview: string } & File;
@@ -102,7 +104,10 @@ function FormFileUpload({ placeholder, onChange }: Props) {
102104
setAndNotifyFile(undefined);
103105
}}
104106
>
105-
Clear
107+
{translate({
108+
id: OPENAPI_FORM_FILE_UPLOAD.CLEAR_BUTTON,
109+
message: "Clear",
110+
})}
106111
</button>
107112
<RenderPreview file={file} />
108113
</>

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
// @ts-nocheck
99
import React from "react";
1010

11+
import { translate } from "@docusaurus/Translate";
1112
import { ErrorMessage } from "@hookform/error-message";
13+
import { OPENAPI_FORM } from "@theme/translationIds";
1214
import clsx from "clsx";
1315
import { useFormContext } from "react-hook-form";
1416

@@ -41,7 +43,12 @@ function FormTextInput({
4143
{paramName ? (
4244
<input
4345
{...register(paramName, {
44-
required: isRequired ? "This field is required" : false,
46+
required: isRequired
47+
? translate({
48+
id: OPENAPI_FORM.FIELD_REQUIRED,
49+
message: "This field is required",
50+
})
51+
: false,
4552
})}
4653
className={clsx("openapi-explorer__form-item-input", {
4754
error: showErrorMessage,

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
import React, { type JSX, useEffect, useState } from "react";
99

1010
import { usePrismTheme } from "@docusaurus/theme-common";
11+
import { translate } from "@docusaurus/Translate";
1112
import useIsBrowser from "@docusaurus/useIsBrowser";
1213
import { ErrorMessage } from "@hookform/error-message";
1314
import { setStringRawBody } from "@theme/ApiExplorer/Body/slice";
15+
import { OPENAPI_FORM } from "@theme/translationIds";
1416
import clsx from "clsx";
1517
import { Controller, useFormContext } from "react-hook-form";
1618
import { LiveProvider, LiveEditor, withLive } from "react-live";
@@ -85,7 +87,13 @@ function App({
8587
<Controller
8688
control={control}
8789
rules={{
88-
required: isRequired && !code ? "This field is required" : false,
90+
required:
91+
isRequired && !code
92+
? translate({
93+
id: OPENAPI_FORM.FIELD_REQUIRED,
94+
message: "This field is required",
95+
})
96+
: false,
8997
}}
9098
name="requestBody"
9199
render={({ field: { onChange, name } }) => (

packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.tsx

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

88
import React, { useEffect, useState } from "react";
99

10+
import { translate } from "@docusaurus/Translate";
1011
import { ErrorMessage } from "@hookform/error-message";
1112
import { nanoid } from "@reduxjs/toolkit";
1213
import FormSelect from "@theme/ApiExplorer/FormSelect";
1314
import FormTextInput from "@theme/ApiExplorer/FormTextInput";
1415
import { Param, setParam } from "@theme/ApiExplorer/ParamOptions/slice";
1516
import { useTypedDispatch } from "@theme/ApiItem/hooks";
17+
import { OPENAPI_FORM } from "@theme/translationIds";
1618
import { Controller, useFormContext } from "react-hook-form";
1719

1820
export interface ParamProps {
@@ -121,7 +123,14 @@ export default function ParamArrayFormItem({ param }: ParamProps) {
121123
<>
122124
<Controller
123125
control={control}
124-
rules={{ required: param.required ? "This field is required" : false }}
126+
rules={{
127+
required: param.required
128+
? translate({
129+
id: OPENAPI_FORM.FIELD_REQUIRED,
130+
message: "This field is required",
131+
})
132+
: false,
133+
}}
125134
name="paramArray"
126135
render={({ field: { onChange, name } }) => (
127136
<>

packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.tsx

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

88
import React from "react";
99

10+
import { translate } from "@docusaurus/Translate";
1011
import { ErrorMessage } from "@hookform/error-message";
1112
import FormSelect from "@theme/ApiExplorer/FormSelect";
1213
import { Param, setParam } from "@theme/ApiExplorer/ParamOptions/slice";
1314
import { useTypedDispatch } from "@theme/ApiItem/hooks";
15+
import { OPENAPI_FORM } from "@theme/translationIds";
1416
import { Controller, useFormContext } from "react-hook-form";
1517

1618
export interface ParamProps {
@@ -31,7 +33,14 @@ export default function ParamBooleanFormItem({ param }: ParamProps) {
3133
<>
3234
<Controller
3335
control={control}
34-
rules={{ required: param.required ? "This field is required" : false }}
36+
rules={{
37+
required: param.required
38+
? translate({
39+
id: OPENAPI_FORM.FIELD_REQUIRED,
40+
message: "This field is required",
41+
})
42+
: false,
43+
}}
3544
name="paramBoolean"
3645
render={({ field: { onChange, name } }) => (
3746
<FormSelect

packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.tsx

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

88
import React from "react";
99

10+
import { translate } from "@docusaurus/Translate";
1011
import { ErrorMessage } from "@hookform/error-message";
1112
import FormMultiSelect from "@theme/ApiExplorer/FormMultiSelect";
1213
import { Param, setParam } from "@theme/ApiExplorer/ParamOptions/slice";
1314
import { useTypedDispatch, useTypedSelector } from "@theme/ApiItem/hooks";
15+
import { OPENAPI_FORM } from "@theme/translationIds";
1416
import { Controller, useFormContext } from "react-hook-form";
1517

1618
export interface ParamProps {
@@ -61,7 +63,14 @@ export default function ParamMultiSelectFormItem({ param }: ParamProps) {
6163
<>
6264
<Controller
6365
control={control}
64-
rules={{ required: param.required ? "This field is required" : false }}
66+
rules={{
67+
required: param.required
68+
? translate({
69+
id: OPENAPI_FORM.FIELD_REQUIRED,
70+
message: "This field is required",
71+
})
72+
: false,
73+
}}
6574
name="paramMultiSelect"
6675
render={({ field: { onChange, name } }) => (
6776
<FormMultiSelect

packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.tsx

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

88
import React from "react";
99

10+
import { translate } from "@docusaurus/Translate";
1011
import { ErrorMessage } from "@hookform/error-message";
1112
import FormSelect from "@theme/ApiExplorer/FormSelect";
1213
import { Param, setParam } from "@theme/ApiExplorer/ParamOptions/slice";
1314
import { useTypedDispatch } from "@theme/ApiItem/hooks";
15+
import { OPENAPI_FORM } from "@theme/translationIds";
1416
import { Controller, useFormContext } from "react-hook-form";
1517

1618
export interface ParamProps {
@@ -33,7 +35,14 @@ export default function ParamSelectFormItem({ param }: ParamProps) {
3335
<>
3436
<Controller
3537
control={control}
36-
rules={{ required: param.required ? "This field is required" : false }}
38+
rules={{
39+
required: param.required
40+
? translate({
41+
id: OPENAPI_FORM.FIELD_REQUIRED,
42+
message: "This field is required",
43+
})
44+
: false,
45+
}}
3746
name="paramSelect"
3847
render={({ field: { onChange, name } }) => (
3948
<FormSelect

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77

88
import React, { useState } from "react";
99

10+
import { translate } from "@docusaurus/Translate";
1011
import FormItem from "@theme/ApiExplorer/FormItem";
1112
import ParamArrayFormItem from "@theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem";
1213
import ParamBooleanFormItem from "@theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem";
1314
import ParamMultiSelectFormItem from "@theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem";
1415
import ParamSelectFormItem from "@theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem";
1516
import ParamTextFormItem from "@theme/ApiExplorer/ParamOptions/ParamFormItems/ParamTextFormItem";
1617
import { useTypedSelector } from "@theme/ApiItem/hooks";
18+
import { OPENAPI_PARAM_OPTIONS } from "@theme/translationIds";
1719

1820
import { Param } from "./slice";
1921

@@ -119,8 +121,14 @@ function ParamOptions() {
119121
</span>
120122
</span>
121123
{showOptional
122-
? "Hide optional parameters"
123-
: "Show optional parameters"}
124+
? translate({
125+
id: OPENAPI_PARAM_OPTIONS.HIDE_OPTIONAL,
126+
message: "Hide optional parameters",
127+
})
128+
: translate({
129+
id: OPENAPI_PARAM_OPTIONS.SHOW_OPTIONAL,
130+
message: "Show optional parameters",
131+
})}
124132
</button>
125133

126134
<div

0 commit comments

Comments
 (0)