Skip to content

Localize Text skips text that starts or ends on a new line #868

Open

Description

@iamtakashi

What happens

"Localize Text" skips text that starts or ends on a new line. The HTML patterns in get_text_replacement_patterns_for_html() have no s modifier, so . doesn't match a newline:

https://github.com/WordPress/create-block-theme/blob/5524f195e8/includes/create-theme/theme-locale.php#L217-L262

For example, this heading (from WooCommerce's Related Products markup) is exported unchanged:

<h2 class="wp-block-heading has-x-large-font-size">
				Related products			</h2>

The same happens to a paragraph like <p>\n\tNo products were found matching your selection.</p>. It affects every block type in that list, not just headings.

A side effect: when nothing in a template gets localized, the template isn't moved into a pattern either, because paternize_template() only runs when PHP was added.

Expected

The text is wrapped in esc_html_e(), with the surrounding whitespace trimmed.

Suggested fix

Add the s modifier to these patterns and trim the captured text before escaping it.

Drafted with AI assistance, verified by me against a theme exported with Create Block Theme and the source.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions