Skip to content

feat(i18n): make QualifierMessage strings translatable#1364

Merged
sserrata merged 1 commit intomainfrom
feat/i18n-qualifier-message
Mar 30, 2026
Merged

feat(i18n): make QualifierMessage strings translatable#1364
sserrata merged 1 commit intomainfrom
feat/i18n-qualifier-message

Conversation

@sserrata
Copy link
Copy Markdown
Member

Summary

Takes ownership of #1249 and applies the approved changes with one cleanup: the demo i18n config changes are excluded (they were test-only and shouldn't gate the feature).

Architecture changes

  • getQualifierMessage moved to theme layer — The function is removed from the plugin and kept only in docusaurus-theme-openapi-docs/src/markdown/schema.ts, where @docusaurus/Translate is available at render time.
  • SchemaItem now self-computes qualifierMessage — If the qualifierMessage prop is not passed, SchemaItem falls back to calling getQualifierMessage(schema) itself. This cleans up all call sites — callers just pass schema and the component handles the rest.
  • Plugin call sites simplified — All qualifierMessage={getQualifierMessage(schema)} / qualifierMessage: undefined passes removed from createSchema.ts and Schema/index.tsx.
  • utils.ts create() skips undefined props — Generated MDX no longer emits qualifierMessage={undefined}.

New translation IDs

theme.openapi.schemaItem.characters          → "characters"
theme.openapi.schemaItem.nonEmpty            → "non-empty"
theme.openapi.schemaItem.expression          → "Value must match regular expression"

Dead code removed

  • humanizeConstraints, humanizeNumberRange, humanizeRangeConstraint, humanizeMultipleOfConstraint — exported but never imported anywhere.
  • schema.test.ts in plugin — tested getQualifierMessage which no longer exists there.

Related

Test plan

  • yarn build-packages passes with no TypeScript errors
  • Snapshots updated
  • Verify qualifier messages render correctly for minLength, maxLength, pattern, enum schemas
  • Verify i18n override works (add translation to i18n/<locale>/code.json)

🤖 Generated with Claude Code

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>
@sserrata sserrata mentioned this pull request Mar 30, 2026
4 tasks
@github-actions
Copy link
Copy Markdown

Size Change: -389 B (-0.02%)

Total Size: 2.2 MB

Filename Size Change
demo/build/petstore/schemas/cat/index.html 38.7 kB -59 B (-0.15%)
demo/build/petstore/schemas/dog/index.html 39 kB -59 B (-0.15%)
demo/build/petstore/schemas/honeybee/index.html 39.1 kB -59 B (-0.15%)
demo/build/petstore/schemas/order/index.html 26.8 kB -47 B (-0.18%)
demo/build/petstore/schemas/pet/index.html 38.5 kB -59 B (-0.15%)
demo/build/petstore/schemas/user/index.html 40.6 kB -58 B (-0.14%)
ℹ️ View Unchanged
Filename Size Change
demo/.docusaurus/codeTranslations.json 2 B 0 B
demo/.docusaurus/docusaurus.config.mjs 14.7 kB 0 B
demo/.docusaurus/globalData.json 65.4 kB 0 B
demo/.docusaurus/i18n.json 372 B 0 B
demo/.docusaurus/registry.js 94.7 kB 0 B
demo/.docusaurus/routes.js 89.6 kB 0 B
demo/.docusaurus/routesChunkNames.json 37.1 kB 0 B
demo/.docusaurus/site-metadata.json 1.51 kB 0 B
demo/build/assets/css/styles.********.css 164 kB 0 B
demo/build/assets/js/main.********.js 656 kB 0 B
demo/build/assets/js/runtime~main.********.js 22.3 kB 0 B
demo/build/index.html 97.6 kB 0 B
demo/build/petstore/add-pet/index.html 29.3 kB 0 B
demo/build/petstore/create-user/index.html 24 kB 0 B
demo/build/petstore/create-users-with-array-input/index.html 24.1 kB 0 B
demo/build/petstore/create-users-with-list-input/index.html 24.1 kB 0 B
demo/build/petstore/delete-order/index.html 23.8 kB 0 B
demo/build/petstore/delete-pet/index.html 24.1 kB 0 B
demo/build/petstore/delete-user/index.html 24.3 kB 0 B
demo/build/petstore/find-pets-by-status/index.html 24.8 kB 0 B
demo/build/petstore/find-pets-by-tags/index.html 25.4 kB 0 B
demo/build/petstore/get-inventory/index.html 23.1 kB 0 B
demo/build/petstore/get-order-by-id/index.html 24.1 kB 0 B
demo/build/petstore/get-pet-by-id/index.html 24.9 kB 0 B
demo/build/petstore/get-user-by-name/index.html 24.4 kB 0 B
demo/build/petstore/login-user/index.html 24.9 kB 0 B
demo/build/petstore/logout-user/index.html 23.7 kB 0 B
demo/build/petstore/new-pet/index.html 24.3 kB 0 B
demo/build/petstore/pet/index.html 22.5 kB 0 B
demo/build/petstore/place-order/index.html 23.3 kB 0 B
demo/build/petstore/schemas/apiresponse/index.html 24.6 kB -12 B (-0.05%)
demo/build/petstore/schemas/category/index.html 25.7 kB -12 B (-0.05%)
demo/build/petstore/schemas/id/index.html 22.7 kB -12 B (-0.05%)
demo/build/petstore/schemas/tag/index.html 24.1 kB -12 B (-0.05%)
demo/build/petstore/store/index.html 21.5 kB 0 B
demo/build/petstore/subscribe-to-the-store-events/index.html 30.2 kB 0 B
demo/build/petstore/swagger-petstore-yaml/index.html 30.2 kB 0 B
demo/build/petstore/update-pet-with-form/index.html 24.3 kB 0 B
demo/build/petstore/update-pet/index.html 24.7 kB 0 B
demo/build/petstore/update-user/index.html 24.3 kB 0 B
demo/build/petstore/upload-file/index.html 24.1 kB 0 B
demo/build/petstore/user/index.html 22.2 kB 0 B

compressed-size-action

@github-actions
Copy link
Copy Markdown

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

@sserrata sserrata merged commit 59e7ecc into main Mar 30, 2026
11 checks passed
@sserrata sserrata deleted the feat/i18n-qualifier-message branch March 30, 2026 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant