i18n: Makes it possible to translate text strings in HTML comments #788
+128
−0
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
Extends the localization functionality to support text strings stored in block attributes (HTML comments), in addition to the existing HTML markup localization.
Problem
The plugin previously only localized text content within HTML markup (e.g.,
<p>Text</p>,<h1>Heading</h1>), but many WordPress blocks store translatable text in their attributes within the block comment markup. These strings were not being made translation-ready when saving themes.Examples of blocks with translatable attributes that were not being localized:
<!-- wp:search {"label":"Search","placeholder":"Type here..."} /--><!-- wp:query-pagination-next {"label":"Next"} /--><!-- wp:post-excerpt {"moreText":"— read more"} /-->Solution
Added attribute-level localization by:
get_localizable_block_attributes()- Maps block types to their translatable attribute namesescape_text_content_of_blocks()- Now processes block attributes in addition to HTML contentescape_attribute()method - Wraps attribute values with<?php esc_attr_e('...', 'text-domain');?>Supported Blocks & Attributes
core/searchlabel,placeholder,buttonTextcore/query-pagination-previouslabelcore/query-pagination-nextlabelcore/comments-pagination-previouslabelcore/comments-pagination-nextlabelcore/post-navigation-linklabelcore/post-excerptmoreTextExamples
Search Block
Before:
<!-- wp:search {"label":"Search","placeholder":"Type here...","buttonText":"Search"} /-->After:
<!-- wp:search {"label":"<?php esc_attr_e('Search', 'theme-domain');?>","placeholder":"<?php esc_attr_e('Type here...', 'theme-domain');?>","buttonText":"<?php esc_attr_e('Search', 'theme-domain');?>"} /-->Query Pagination
Before:
After:
Comments Pagination with Unicode Characters
Before:
After:
Post Excerpt
Before:
<!-- wp:post-excerpt {"moreText":"— read more","showMoreOnNewLine":false} /-->After:
<!-- wp:post-excerpt {"moreText":"<?php esc_attr_e('— read more', 'theme-domain');?>","showMoreOnNewLine":false} /-->Technical Details
Files Changed
Implementation Notes
Testing
Related Issues
Fixes user-reported issues where pagination labels, search block text, and post excerpt "read more" text were not being made translation-ready.
🤖 Generated with https://claude.com/claude-code
Co-Authored-By: Claude noreply@anthropic.com