Skip to content

Commit 890e247

Browse files
committed
feat(theme): add initial i18n support
1 parent 44f3869 commit 890e247

File tree

4 files changed

+69
-12
lines changed

4 files changed

+69
-12
lines changed

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import React, { useState } from "react";
1010

1111
import { useDoc } from "@docusaurus/plugin-content-docs/client";
12+
import { translate } from "@docusaurus/Translate";
1213
import Accept from "@theme/ApiExplorer/Accept";
1314
import Authorization from "@theme/ApiExplorer/Authorization";
1415
import Body from "@theme/ApiExplorer/Body";
@@ -24,6 +25,7 @@ import {
2425
} from "@theme/ApiExplorer/Response/slice";
2526
import Server from "@theme/ApiExplorer/Server";
2627
import { useTypedDispatch, useTypedSelector } from "@theme/ApiItem/hooks";
28+
import { OPENAPI_REQUEST } from "@theme/translationIds";
2729
import { ParameterObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
2830
import { ApiItem } from "docusaurus-plugin-openapi-docs/src/types";
2931
import * as sdk from "postman-collection";
@@ -261,10 +263,14 @@ function Request({ item }: { item: ApiItem }) {
261263
setExpandBody(!expandBody);
262264
}}
263265
>
264-
Body
266+
{translate({ id: OPENAPI_REQUEST.BODY_TITLE, message: "Body" })}
265267
{requestBodyRequired && (
266268
<span className="openapi-schema__required">
267-
&nbsp;required
269+
&nbsp;
270+
{translate({
271+
id: OPENAPI_REQUEST.REQUIRED_LABEL,
272+
message: "required",
273+
})}
268274
</span>
269275
)}
270276
</summary>
@@ -290,14 +296,20 @@ function Request({ item }: { item: ApiItem }) {
290296
setExpandAccept(!expandAccept);
291297
}}
292298
>
293-
Accept
299+
{translate({
300+
id: OPENAPI_REQUEST.ACCEPT_TITLE,
301+
message: "Accept",
302+
})}
294303
</summary>
295304
<Accept />
296305
</details>
297306
)}
298307
{showRequestButton && item.method !== "event" && (
299308
<button className="openapi-explorer__request-btn" type="submit">
300-
Send API Request
309+
{translate({
310+
id: OPENAPI_REQUEST.SEND_BUTTON,
311+
message: "Send API Request",
312+
})}
301313
</button>
302314
)}
303315
</div>

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import React from "react";
99

1010
import { useDoc } from "@docusaurus/plugin-content-docs/client";
1111
import { usePrismTheme } from "@docusaurus/theme-common";
12+
import { translate } from "@docusaurus/Translate";
1213
import ApiCodeBlock from "@theme/ApiExplorer/ApiCodeBlock";
1314
import { useTypedDispatch, useTypedSelector } from "@theme/ApiItem/hooks";
1415
import SchemaTabs from "@theme/SchemaTabs";
1516
import TabItem from "@theme/TabItem";
17+
import { OPENAPI_RESPONSE } from "@theme/translationIds";
1618
import clsx from "clsx";
1719
import { ApiItem } from "docusaurus-plugin-openapi-docs/src/types";
1820

@@ -74,7 +76,9 @@ function Response({ item }: { item: ApiItem }) {
7476
return (
7577
<div className="openapi-explorer__response-container">
7678
<div className="openapi-explorer__response-title-container">
77-
<span className="openapi-explorer__response-title">Response</span>
79+
<span className="openapi-explorer__response-title">
80+
{translate({ id: OPENAPI_RESPONSE.TITLE, message: "Response" })}
81+
</span>
7882
<span
7983
className="openapi-explorer__response-clear-btn"
8084
onClick={() => {
@@ -83,7 +87,7 @@ function Response({ item }: { item: ApiItem }) {
8387
dispatch(clearHeaders());
8488
}}
8589
>
86-
Clear
90+
{translate({ id: OPENAPI_RESPONSE.CLEAR, message: "Clear" })}
8791
</span>
8892
</div>
8993
<div
@@ -117,14 +121,23 @@ function Response({ item }: { item: ApiItem }) {
117121
>
118122
{prettyResponse || (
119123
<p className="openapi-explorer__response-placeholder-message">
120-
Click the <code>Send API Request</code> button above and see
121-
the response here!
124+
{translate({
125+
id: OPENAPI_RESPONSE.PLACEHOLDER,
126+
message:
127+
"Click the <code>Send API Request</code> button above and see the response here!",
128+
})}
122129
</p>
123130
)}
124131
</ApiCodeBlock>
125132
</TabItem>
126133
{/* @ts-ignore */}
127-
<TabItem label="Headers" value="headers">
134+
<TabItem
135+
label={translate({
136+
id: OPENAPI_RESPONSE.HEADERS_TAB,
137+
message: "Headers",
138+
})}
139+
value="headers"
140+
>
128141
{/* @ts-ignore */}
129142
<ApiCodeBlock
130143
className="openapi-explorer__code-block openapi-response__status-headers"
@@ -145,8 +158,11 @@ function Response({ item }: { item: ApiItem }) {
145158
</div>
146159
) : (
147160
<p className="openapi-explorer__response-placeholder-message">
148-
Click the <code>Send API Request</code> button above and see the
149-
response here!
161+
{translate({
162+
id: OPENAPI_RESPONSE.PLACEHOLDER,
163+
message:
164+
"Click the <code>Send API Request</code> button above and see the response here!",
165+
})}
150166
</p>
151167
)}
152168
</div>

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ import {
2020
useTabs,
2121
} from "@docusaurus/theme-common/internal";
2222
import { TabItemProps } from "@docusaurus/theme-common/lib/utils/tabsUtils";
23+
import { translate } from "@docusaurus/Translate";
2324
import useIsBrowser from "@docusaurus/useIsBrowser";
2425
import Heading from "@theme/Heading";
26+
import { OPENAPI_TABS } from "@theme/translationIds";
2527
import clsx from "clsx";
2628

2729
export interface TabListProps extends TabProps {
@@ -35,7 +37,10 @@ function TabList({
3537
selectedValue,
3638
selectValue,
3739
tabValues,
38-
label = "Responses",
40+
label = translate({
41+
id: OPENAPI_TABS.RESPONSES_LABEL,
42+
message: "Responses",
43+
}),
3944
id = "responses",
4045
}: TabListProps & ReturnType<typeof useTabs>) {
4146
const tabRefs: (HTMLLIElement | null)[] = [];
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* ============================================================================
2+
* Copyright (c) Palo Alto Networks
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
* ========================================================================== */
7+
8+
export const OPENAPI_RESPONSE = {
9+
TITLE: "theme.openapi.response.title",
10+
CLEAR: "theme.openapi.response.clear",
11+
PLACEHOLDER: "theme.openapi.response.placeholder",
12+
HEADERS_TAB: "theme.openapi.response.headersTab",
13+
};
14+
15+
export const OPENAPI_TABS = {
16+
RESPONSES_LABEL: "theme.openapi.tabs.responses.label",
17+
};
18+
19+
export const OPENAPI_REQUEST = {
20+
BODY_TITLE: "theme.openapi.request.body.title",
21+
ACCEPT_TITLE: "theme.openapi.request.accept.title",
22+
SEND_BUTTON: "theme.openapi.request.sendButton",
23+
REQUIRED_LABEL: "theme.openapi.request.requiredLabel",
24+
};

0 commit comments

Comments
 (0)