-
Notifications
You must be signed in to change notification settings - Fork 60
i18n: Makes it possible to translate text strings in HTML comments #788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
mikachan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ), | ||
| ); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also add a test for blocks without any attributes, to make sure they aren't changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Done in 9b5e282
Co-authored-by: Sarah Norris <[email protected]>
…ate-block-theme into fix/i18n-for-html-comments
mikachan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good, thanks @scruffian!


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 [email protected]