Skip to content

Commit

Permalink
perf: make <Translate> calls more discoverable with Docusaurus write-…
Browse files Browse the repository at this point in the history
…translations
  • Loading branch information
jy95 committed Feb 4, 2023
1 parent a955fc1 commit 5e938b4
Show file tree
Hide file tree
Showing 11 changed files with 230 additions and 187 deletions.
24 changes: 14 additions & 10 deletions src/theme/JSONSchemaViewer/JSONSchemaElements/CreatePrimitive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,22 @@ function createPrimitive(props: Props) {
let type = detectType(schema)
let friendly_type = schema?.format ? `${type} (${schema.format})` : type

const typeLabel = (
<strong>
<Translate
values={{
id: "json-schema.keywords.type",
count: 1,
}}
>
{"type"}
</Translate>
</strong>
)

return (
<>
<strong>
<Translate
values={{
id: "json-schema.keywords.type",
count: 1,
}}
>
{"type"}
</Translate>
</strong>
{typeLabel}
&nbsp;&#58;&nbsp;
<span style={{ opacity: "0.6" }}>{friendly_type}</span>
<div style={{ marginTop: "var(--ifm-table-cell-padding)" }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,42 +39,39 @@ function DependentSchemas(props: Props): JSX.Element {
),
}))

// Translated labels
const ifLabel = (
<strong>
<Translate
values={{
id: "json-schema.keywords.if",
}}
>
{"If"}
</Translate>
</strong>
)

const elseLabel = (
<strong>
<Translate
values={{
id: "json-schema.keywords.then",
}}
>
{"Then"}
</Translate>
</strong>
)

return (
<ul>
{items.map((item) => (
<Tabs key={item.id}>
<TabItem
key={"schema_if"}
value={"schema_if"}
label={
<strong>
<Translate
values={{
id: "json-schema.keywords.if",
}}
>
{"If"}
</Translate>
</strong>
}
>
<TabItem key={"schema_if"} value={"schema_if"} label={ifLabel}>
{item.label}
</TabItem>
<TabItem
key={"schema_then"}
value={"schema_then"}
label={
<strong>
<Translate
values={{
id: "json-schema.keywords.then",
}}
>
{"Then"}
</Translate>
</strong>
}
>
<TabItem key={"schema_then"} value={"schema_then"} label={elseLabel}>
<CreateNodes schema={item.subSchema} />
</TabItem>
</Tabs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,49 +26,56 @@ function IfElseThen(props: Props): JSX.Element {
const hasThen = schema.then !== undefined
const hasElse = schema.else !== undefined

// Translated labels
const ifLabel = (
<strong>
<Translate
values={{
id: "json-schema.keywords.if",
}}
>
{"If"}
</Translate>
</strong>
)

const thenLabel = (
<strong>
<Translate
values={{
id: "json-schema.keywords.then",
}}
>
{"Then"}
</Translate>
</strong>
)

const elseLabel = (
<strong>
<Translate
values={{
id: "json-schema.keywords.else",
}}
>
{"Else"}
</Translate>
</strong>
)

// values for Tabs
let values = [
{
value: "schema_if",
label: (
<strong>
<Translate
values={{
id: "json-schema.keywords.if",
}}
>
{"If"}
</Translate>
</strong>
),
label: ifLabel,
},
hasThen && {
value: "schema_then",
label: (
<strong>
<Translate
values={{
id: "json-schema.keywords.then",
}}
>
{"Then"}
</Translate>
</strong>
),
label: thenLabel,
},
hasElse && {
value: "schema_else",
label: (
<strong>
<Translate
values={{
id: "json-schema.keywords.else",
}}
>
{"Else"}
</Translate>
</strong>
),
label: elseLabel,
},
].filter((v) => typeof v !== "boolean") as {
value: "schema_if" | "schema_then" | "schema_else"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,21 @@ function SchemaConditional(props: Props): JSX.Element {
(schema as JSONSchemaNS.Object)?.dependentSchemas !== undefined
const isDependencies = schema?.dependencies !== undefined

const schemaConditionalLabel = (
<strong>
<Translate
values={{
id: "json-schema.labels.schemaConditional",
}}
>
{"Conditional subschemas"}
</Translate>
</strong>
)

return (
<Collapsible
summary={
<strong>
<Translate
values={{
id: "json-schema.labels.schemaConditional",
}}
>
{"Conditional subschemas"}
</Translate>
</strong>
}
summary={schemaConditionalLabel}
detailsProps={{
open: true,
}}
Expand Down
24 changes: 13 additions & 11 deletions src/theme/JSONSchemaViewer/JSONSchemaElements/array/Contains.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,22 @@ function createContains(props: Props): JSX.Element {

let item = typedSchema.contains!

const containsLabel = (
<code>
<Translate
values={{
id: "json-schema.keywords.contains",
}}
>
{"contains"}
</Translate>
</code>
)

return (
<CreateEdge
key={"contains"}
name={
<code>
<Translate
values={{
id: "json-schema.keywords.contains",
}}
>
{"contains"}
</Translate>
</code>
}
name={containsLabel}
schema={item}
required={
typedSchema?.minContains !== undefined && typedSchema.minContains > 0
Expand Down
46 changes: 27 additions & 19 deletions src/theme/JSONSchemaViewer/JSONSchemaElements/array/CreateArray.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,36 @@ function createArray(props: Props): JSX.Element {
<PrefixItems schema={schema} />
) : undefined

const typeLabel = (
<strong>
<Translate
values={{
id: "json-schema.keywords.type",
count: 1,
}}
>
{"type"}
</Translate>
</strong>
)

const typeArrayLabel = (
<span style={{ opacity: "0.6" }}>
<Translate
values={{
id: "json-schema.keywords.array",
}}
>
{"array"}
</Translate>
</span>
)

return (
<>
<strong>
<Translate
values={{
id: "json-schema.keywords.type",
count: 1,
}}
>
{"type"}
</Translate>
</strong>
{typeLabel}
&nbsp;&#58;&nbsp;
<span style={{ opacity: "0.6" }}>
<Translate
values={{
id: "json-schema.keywords.array",
}}
>
{"array"}
</Translate>
</span>
{typeArrayLabel}
{items !== undefined && <ul>{items}</ul>}
{prefixItems !== undefined && <ul>{prefixItems}</ul>}
{contains !== undefined && <ul>{contains}</ul>}
Expand Down
24 changes: 13 additions & 11 deletions src/theme/JSONSchemaViewer/JSONSchemaElements/array/Items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,22 @@ function createItems(props: Props): JSX.Element {
// singe items (most common case)
let typedItem = items as JSONSchema

const itemsLabel = (
<code>
<Translate
values={{
id: "json-schema.keywords.items",
}}
>
{"items"}
</Translate>
</code>
)

return (
<CreateEdge
key={"array_items"}
name={
<code>
<Translate
values={{
id: "json-schema.keywords.items",
}}
>
{"items"}
</Translate>
</code>
}
name={itemsLabel}
schema={typedItem}
required={
typedSchema?.minItems !== undefined && typedSchema?.minItems > 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,22 @@ function createAdditionalProperties(props: Props): JSX.Element {
if (types.length > 0) {
// Most of the time, only one entry but prefer to be safe that sorry ...

const additionalPropertiesLabel = (
<code>
<Translate
values={{
id: "json-schema.labels.additionalProperties",
}}
>
{"property name*"}
</Translate>
</code>
)

return (
<CreateEdge
key={"object_additionalProperties"}
name={
<code>
<Translate
values={{
id: "json-schema.labels.additionalProperties",
}}
>
{"property name*"}
</Translate>
</code>
}
name={additionalPropertiesLabel}
schema={typedSchema}
required={false}
/>
Expand Down
Loading

0 comments on commit 5e938b4

Please sign in to comment.