feat(i18n): make QualifierMessage strings translatable#1364
Merged
Conversation
Move qualifier-message rendering fully to the theme layer so that
Docusaurus i18n can translate the human-readable constraint strings:
- "characters" (minLength / maxLength)
- "non-empty" (minLength === 1)
- "Value must match regular expression" (pattern)
Architecture:
- `getQualifierMessage` is removed from the plugin and kept only in
the theme (`docusaurus-theme-openapi-docs/src/markdown/schema.ts`),
where `translate()` is available at render time.
- `SchemaItem` now computes `qualifierMessage` from its `schema` prop
when the caller doesn't pass one explicitly, so all callers are
simplified — no more `qualifierMessage={getQualifierMessage(schema)}`
at every call site.
- Plugin `createSchema.ts` and `Schema/index.tsx` drop all
`qualifierMessage` prop passes; the theme component handles it.
- `utils.ts` `create()` skips props with `undefined` values, cleaning
up generated MDX.
- Dead code removed: `humanizeConstraints`, `humanizeNumberRange`, and
related helpers were exported but unused.
Translation IDs added:
theme.openapi.schemaItem.characters
theme.openapi.schemaItem.nonEmpty
theme.openapi.schemaItem.expression
Demo directory intentionally untouched (no locale config added).
Closes #1249. Credit: @dsuket
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Size Change: -389 B (-0.02%) Total Size: 2.2 MB
ℹ️ View Unchanged
|
|
Visit the preview URL for this PR (updated for commit 8ab9e17): https://docusaurus-openapi-36b86--pr1364-lt38p7il.web.app (expires Wed, 29 Apr 2026 17:02:05 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: bf293780ee827f578864d92193b8c2866acd459f |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Takes ownership of #1249 and applies the approved changes with one cleanup: the demo
i18nconfig changes are excluded (they were test-only and shouldn't gate the feature).Architecture changes
getQualifierMessagemoved to theme layer — The function is removed from the plugin and kept only indocusaurus-theme-openapi-docs/src/markdown/schema.ts, where@docusaurus/Translateis available at render time.SchemaItemnow self-computesqualifierMessage— If thequalifierMessageprop is not passed,SchemaItemfalls back to callinggetQualifierMessage(schema)itself. This cleans up all call sites — callers just passschemaand the component handles the rest.qualifierMessage={getQualifierMessage(schema)}/qualifierMessage: undefinedpasses removed fromcreateSchema.tsandSchema/index.tsx.utils.tscreate()skipsundefinedprops — Generated MDX no longer emitsqualifierMessage={undefined}.New translation IDs
Dead code removed
humanizeConstraints,humanizeNumberRange,humanizeRangeConstraint,humanizeMultipleOfConstraint— exported but never imported anywhere.schema.test.tsin plugin — testedgetQualifierMessagewhich no longer exists there.Related
Test plan
yarn build-packagespasses with no TypeScript errorsminLength,maxLength,pattern,enumschemasi18n/<locale>/code.json)🤖 Generated with Claude Code