i18n: Localise fileName and downloadButtonText of the File block#827
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Extends the “Localize Text” theme-save pipeline to also localize the core/file block’s rich-text-derived strings (stored in inner HTML rather than block-comment JSON), ensuring fileName and downloadButtonText are wrapped for translation during escape_text_content_of_blocks().
Changes:
- Add
core/filehandling toget_text_replacement_patterns_for_html()and the dispatch switch inescape_text_content_of_blocks(). - Introduce unit tests covering File block localization scenarios (with/without download button, custom button text, formatted file name) plus an idempotency test.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
includes/create-theme/theme-locale.php |
Adds regex patterns + dispatch case so core/file inner-HTML link text is localized during block text escaping. |
tests/CbtThemeLocale/escapeTextContentOfBlocks.php |
Adds test coverage for File block localization and verifies idempotency. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
core/filetoget_text_replacement_patterns_for_html()and the dispatch switch inescape_text_content_of_blocks()so the File block's two rich-text-sourced attributes —fileNameanddownloadButtonText— are wrapped withesc_html_e()on theme save."selector": "a:not([download])"forfileNameand"selector": "a[download]"fordownloadButtonText. Two regexes mirror that: a negative-lookahead pattern for the file-name link, and a\sdownload[\s>]pattern for the download button.Why a separate path
fileNameanddownloadButtonTextare"source": "rich-text", so the values live as inner-HTML text inside the two<a>tags rather than in the block-comment JSON.escape_block_attribute_strings()(the JSON path) can't see them, so they need handling alongsidefigcaption,alt, and<summary>.Test plan
npm run lint:phpcleannpm run test:unit:php— 5 new tests pass (file,file without download button,file with custom button text,file with formatted file name, idempotency); 99/99 overallnpm run buildsucceedsparse_blocks → escape_text_content_of_blocks → serialize_blocks → escape_block_attribute_stringsconfirms both attributes wrapped with the active theme's text domainNotes
downloadattribute on the second anchor). If a future Gutenberg release restructures the block (e.g. swaps<a download>for<button>), the download-button regex stops matching. Same fragility as every other entry inget_text_replacement_patterns_for_html()— accepted for the band-aid approach tracked in Consider the ideal approach for text localization #776.