Fix attribution section for #1368#1411
Conversation
Co-authored-by: pgzcoa <patriciaguerrero01@gmail.com>
Added note about translating Example pages and remix metadata.
|
Hi @Ryan-z-Feng-ccsf, thank you for working on this. I tested the fix locally, and the attribution section is now showing correctly on translated example pages with the English fallback data. Great work overall. The documentation note added to "localization.md" is also a helpful addition for future translators. A few things worth noting: One thing to flag on the test in "test/pages/_utils.test.ts". The function "getFallbackRemixData" is async but the test is not using "async/await". This means the test is checking that a Promise object exists rather than checking the actual returned data. The test will always pass even if the function is broken. Here is the current test: typescript It should be: typescript Also worth noting for future contributions, it is good practice to create a separate branch for your work rather than working directly on your fork's main branch. Not blocking, but keeping this in mind will make future PRs cleaner. |
… the actual resolved data instead of just the Promise object. Addresses PR review feedback.
|
Hi @Nwakaego-Eg. Thanks for the review and for catching that! I've updated the test to include async/await. I also appreciate the tip about creating a separate branch—I'll definitely do that for future PRs. |
|
Closing this in favor of #1425, which uses a separate branch as suggested and includes the completed Vitest mock fixes. Thanks again for the feedback! |
Resolves #1368
Changes
This PR implements a robust multilingual fallback mechanism for the remix metadata (attributions and code history) in the localized Examples pages.
Implementation details and decisions:
Logic Extraction: Created getFallbackRemixData in src/pages/_utils.ts to cleanly separate the data-fetching logic from the UI layout (ExampleLayout.astro).
Dynamic Path Resolution: If a localized example is missing its remix data, the utility dynamically replaces the current locale prefix with the English one (e.g., "zh-Hans/02_.../description.mdx" -> "en/02_.../description.mdx") and fetches the corresponding English metadata via getCollection.
Early Returns & Safe Fallbacks: The function safely exits and returns existing data if the page is already in English or if the localized data is already populated.
Unit Testing: Added comprehensive test cases in test/pages/_utils.test.ts to ensure the fallback safely retrieves English attribution data when localized versions are empty, and degrades safely when no data exists at all.
Documentation Update: Added a note to
docs/localization.mdto clarify to future translators that they no longer need to copy or include theremixmetadata block into localized.mdxfiles.Screenshots of the change
PR Checklist
[x] I have read the Contributor Guidelines and followed the instructions.
[x] I have added tests to cover my changes (if applicable).
[x] My changes do not introduce any new errors or warnings.
(Note: Thanks to @pgzcoa for the collaboration and initial issue tracking!)