From 890e247c97eb1da3dfb49a68581fa90e99d9aceb Mon Sep 17 00:00:00 2001
From: Steven Serrata <9343811+sserrata@users.noreply.github.com>
Date: Thu, 17 Jul 2025 11:29:04 -0500
Subject: [PATCH 1/3] feat(theme): add initial i18n support
---
.../src/theme/ApiExplorer/Request/index.tsx | 20 ++++++++++---
.../src/theme/ApiExplorer/Response/index.tsx | 30 ++++++++++++++-----
.../src/theme/ApiTabs/index.tsx | 7 ++++-
.../src/theme/translationIds.ts | 24 +++++++++++++++
4 files changed, 69 insertions(+), 12 deletions(-)
create mode 100644 packages/docusaurus-theme-openapi-docs/src/theme/translationIds.ts
diff --git a/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/Request/index.tsx b/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/Request/index.tsx
index 30f7bcc69..7036385eb 100644
--- a/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/Request/index.tsx
+++ b/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/Request/index.tsx
@@ -9,6 +9,7 @@
import React, { useState } from "react";
import { useDoc } from "@docusaurus/plugin-content-docs/client";
+import { translate } from "@docusaurus/Translate";
import Accept from "@theme/ApiExplorer/Accept";
import Authorization from "@theme/ApiExplorer/Authorization";
import Body from "@theme/ApiExplorer/Body";
@@ -24,6 +25,7 @@ import {
} from "@theme/ApiExplorer/Response/slice";
import Server from "@theme/ApiExplorer/Server";
import { useTypedDispatch, useTypedSelector } from "@theme/ApiItem/hooks";
+import { OPENAPI_REQUEST } from "@theme/translationIds";
import { ParameterObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
import { ApiItem } from "docusaurus-plugin-openapi-docs/src/types";
import * as sdk from "postman-collection";
@@ -261,10 +263,14 @@ function Request({ item }: { item: ApiItem }) {
setExpandBody(!expandBody);
}}
>
- Body
+ {translate({ id: OPENAPI_REQUEST.BODY_TITLE, message: "Body" })}
{requestBodyRequired && (
- required
+
+ {translate({
+ id: OPENAPI_REQUEST.REQUIRED_LABEL,
+ message: "required",
+ })}
)}
@@ -290,14 +296,20 @@ function Request({ item }: { item: ApiItem }) {
setExpandAccept(!expandAccept);
}}
>
- Accept
+ {translate({
+ id: OPENAPI_REQUEST.ACCEPT_TITLE,
+ message: "Accept",
+ })}
- Click the Send API Request
button above and see
- the response here!
+ {translate({
+ id: OPENAPI_RESPONSE.PLACEHOLDER,
+ message:
+ "Click the Send API Request
button above and see the response here!",
+ })}
- Click the Send API Request
button above and see the
- response here!
+ {translate({
+ id: OPENAPI_RESPONSE.PLACEHOLDER,
+ message:
+ "Click the Send API Request
button above and see the response here!",
+ })}
{auth.scopes.length > 0 ? auth.scopes.toString() : "[]"}
@@ -89,16 +107,31 @@ function SecuritySchemes(props: any) {
}}
>
- name:{" "}
+
+ {translate({
+ id: OPENAPI_SECURITY_SCHEMES.NAME,
+ message: "name:",
+ })}
+ {" "}
{name ?? key}
- type:
+
+ {translate({
+ id: OPENAPI_SECURITY_SCHEMES.TYPE,
+ message: "type:",
+ })}
+ {" "}
{type}
{scopes && scopes.length > 0 && (
- scopes:
+
+ {translate({
+ id: OPENAPI_SECURITY_SCHEMES.SCOPES,
+ message: "scopes:",
+ })}
+ {" "}
{auth.scopes.length > 0 ? auth.scopes.toString() : "[]"}
@@ -128,15 +161,30 @@ function SecuritySchemes(props: any) {
}}
>
- name:{" "}
+
+ {translate({
+ id: OPENAPI_SECURITY_SCHEMES.NAME,
+ message: "name:",
+ })}
+ {" "}
{auth.name ?? auth.key}
- type:
+
+ {translate({
+ id: OPENAPI_SECURITY_SCHEMES.TYPE,
+ message: "type:",
+ })}
+ {" "}
{auth.type}
- in:
+
+ {translate({
+ id: OPENAPI_SECURITY_SCHEMES.IN,
+ message: "in:",
+ })}
+ {" "}
{auth.in}
@@ -156,16 +204,31 @@ function SecuritySchemes(props: any) {
}}
>
- name:{" "}
+
+ {translate({
+ id: OPENAPI_SECURITY_SCHEMES.NAME,
+ message: "name:",
+ })}
+ {" "}
{name ?? key}
- type:
+
+ {translate({
+ id: OPENAPI_SECURITY_SCHEMES.TYPE,
+ message: "type:",
+ })}
+ {" "}
{type}
{scopes && scopes.length > 0 && (
- scopes:
+
+ {translate({
+ id: OPENAPI_SECURITY_SCHEMES.SCOPES,
+ message: "scopes:",
+ })}
+ {" "}
{auth.scopes.length > 0 ? auth.scopes.toString() : "[]"}
@@ -198,16 +261,31 @@ function SecuritySchemes(props: any) {
}}
>
- name:{" "}
+
+ {translate({
+ id: OPENAPI_SECURITY_SCHEMES.NAME,
+ message: "name:",
+ })}
+ {" "}
{name ?? key}
- type:
+
+ {translate({
+ id: OPENAPI_SECURITY_SCHEMES.TYPE,
+ message: "type:",
+ })}
+ {" "}
{type}
{scopes && scopes.length > 0 && (
- scopes:
+
+ {translate({
+ id: OPENAPI_SECURITY_SCHEMES.SCOPES,
+ message: "scopes:",
+ })}
+ {" "}
{auth.scopes.length > 0 ? auth.scopes.toString() : "[]"}
@@ -226,7 +304,12 @@ function SecuritySchemes(props: any) {
{flows && (
- flows:
+
+ {translate({
+ id: OPENAPI_SECURITY_SCHEMES.FLOWS,
+ message: "flows:",
+ })}
+ {" "}
{JSON.stringify(flows, null, 2)}
@@ -248,16 +331,31 @@ function SecuritySchemes(props: any) {
}}
>
- name:{" "}
+
+ {translate({
+ id: OPENAPI_SECURITY_SCHEMES.NAME,
+ message: "name:",
+ })}
+ {" "}
{name ?? key}
- type:
+
+ {translate({
+ id: OPENAPI_SECURITY_SCHEMES.TYPE,
+ message: "type:",
+ })}
+ {" "}
{type}
{scopes && scopes.length > 0 && (
- scopes:
+
+ {translate({
+ id: OPENAPI_SECURITY_SCHEMES.SCOPES,
+ message: "scopes:",
+ })}
+ {" "}
{auth.scopes.length > 0 ? auth.scopes.toString() : "[]"}
diff --git a/packages/docusaurus-theme-openapi-docs/src/theme/ParamsDetails/index.tsx b/packages/docusaurus-theme-openapi-docs/src/theme/ParamsDetails/index.tsx
index ad74e709f..e0beb13cb 100644
--- a/packages/docusaurus-theme-openapi-docs/src/theme/ParamsDetails/index.tsx
+++ b/packages/docusaurus-theme-openapi-docs/src/theme/ParamsDetails/index.tsx
@@ -7,6 +7,9 @@
import React from "react";
+import { translate } from "@docusaurus/Translate";
+import { OPENAPI_PARAMS_DETAILS } from "@theme/translationIds";
+
import BrowserOnly from "@docusaurus/BrowserOnly";
import Details from "@theme/Details";
import ParamsItem from "@theme/ParamsItem";
@@ -31,7 +34,13 @@ const ParamsDetailsComponent: React.FC{defaultValue}
@@ -127,7 +139,12 @@ function ParamsItem({ param, ...rest }: Props) {
}
return (
{JSON.stringify(defaultValue)}
@@ -139,7 +156,12 @@ function ParamsItem({ param, ...rest }: Props) {
const renderExample = guard(toString(example), (example) => (
{exampleProperties.summary}
} {exampleProperties.description && (- Description: + + {translate({ + id: OPENAPI_SCHEMA_ITEM.DESCRIPTION, + message: "Description:", + })}{" "} + {exampleProperties.description}
)}
- Example:
+
+ {translate({
+ id: OPENAPI_SCHEMA_ITEM.EXAMPLE,
+ message: "Example:",
+ })}{" "}
+
{exampleProperties.value}
{defaultValue}
@@ -129,7 +144,12 @@ export default function SchemaItem(props: Props) {
}
return (
{JSON.stringify(defaultValue)}
@@ -144,7 +164,12 @@ export default function SchemaItem(props: Props) {
if (typeof example === "string") {
return (
{example}
@@ -153,7 +178,12 @@ export default function SchemaItem(props: Props) {
}
return (
{JSON.stringify(example)}
@@ -168,7 +198,12 @@ export default function SchemaItem(props: Props) {
if (typeof constValue === "string") {
return (
{constValue}
@@ -177,7 +212,12 @@ export default function SchemaItem(props: Props) {
}
return (
{JSON.stringify(constValue)}
diff --git a/packages/docusaurus-theme-openapi-docs/src/theme/StatusCodes/index.tsx b/packages/docusaurus-theme-openapi-docs/src/theme/StatusCodes/index.tsx
index e838e9897..da7ebf29f 100644
--- a/packages/docusaurus-theme-openapi-docs/src/theme/StatusCodes/index.tsx
+++ b/packages/docusaurus-theme-openapi-docs/src/theme/StatusCodes/index.tsx
@@ -7,12 +7,15 @@
import React from "react";
+import { translate } from "@docusaurus/Translate";
+
import ApiTabs from "@theme/ApiTabs";
import Details from "@theme/Details";
import Markdown from "@theme/Markdown";
import ResponseHeaders from "@theme/ResponseHeaders";
import ResponseSchema from "@theme/ResponseSchema";
import TabItem from "@theme/TabItem";
+import { OPENAPI_STATUS_CODES } from "@theme/translationIds";
import { ApiItem } from "docusaurus-plugin-openapi-docs/lib/types";
interface Props {
@@ -51,7 +54,12 @@ const StatusCodes: React.FC