fix(content-docs): use category key for generated-index translation lookup#11743
Conversation
…ookup When a sidebar category has a custom `key` attribute, the translation system generates keys using `category.key ?? category.label`. However, the read phase (`transformSidebarCategoryLink`) was using `category.label` directly for generated-index title and description lookups, causing a key mismatch and silent translation failure. This aligns the generated-index lookup with the existing pattern already used for category labels, link labels, and doc labels. Fixes facebook#11738
|
Hi @4RH1T3CT0R7! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
✅ [V2]
To edit notification comments on pull requests, go to your Netlify project configuration. |
slorber
left a comment
There was a problem hiding this comment.
LGTM thanks 👍
Just simplified a bit the test to match what we already had before
Motivation
Fixes #11738
When a sidebar category has a custom
keyattribute (via_category_.jsonor sidebar config), the translation system has two phases:getSidebarTranslationFileContent): generates translation keys usingcategory.key ?? category.labeltranslateSidebar-transformSidebarCategoryLink): looks up translations to apply themThe read phase for generated-index
titleanddescriptionwas usingcategory.labelinstead ofcategory.key ?? category.label, so when a category had a customkey, the lookup key didn't match the written key and translations silently failed.This was already correctly handled for category labels, link labels, and doc labels - only the generated-index title/description lookups were broken.
Changes
translations.ts(2-line fix):const categoryKey = category.key ?? category.labelintransformSidebarCategoryLinkcategoryKeyinstead ofcategory.labelin the two generated-index translation key lookupstranslations.test.ts:keyandgenerated-indexlink to the existing conflict test fixturetranslateLoadedContentcorrectly applies translations when a category has bothkeyand agenerated-indexlinkTest plan
yarn jest packages/docusaurus-plugin-content-docs/src/__tests__/translations.test.ts- all 6 tests passkeyis undefined)yarn build:packages