Fix attribution section for #1368#1411
Open
Ryan-z-Feng-ccsf wants to merge 3 commits into
Open
Conversation
Co-authored-by: pgzcoa <patriciaguerrero01@gmail.com>
Added note about translating Example pages and remix metadata.
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.
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!)