i18n: Localise fileName and downloadButtonText of the File block#827
Open
bph wants to merge 1 commit into
Open
i18n: Localise fileName and downloadButtonText of the File block#827bph wants to merge 1 commit into
bph wants to merge 1 commit into
Conversation
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.