Skip to content

Localize Text wraps empty block attribute values in a translation call #879

Open

Description

@iamtakashi

Description

When Localize Text exports a block attribute whose value is an empty string, it wraps it in a translation call anyway. For example, an Excerpt block with an empty "Read more" text:

<!-- wp:post-excerpt {"moreText":""} /-->

is written to the theme as:

<!-- wp:post-excerpt {"moreText":"<?php esc_attr_e('', 'my-theme');?>"} /-->

That adds an empty string to the theme's translatable strings, and WordPress Coding Standards flag it (WordPress.WP.I18n.NoEmptyStrings). We found three of these in a theme exported with Create Block Theme (the Excerpt blocks in its index, archive and search patterns).

Cause

escape_block_attribute() has no empty-string check:
https://github.com/WordPress/create-block-theme/blob/trunk/includes/create-theme/theme-locale.php#L26

The other two escape functions in the same file already return an empty string unchanged (escape_text_content() and escape_attribute(), "Check if string is empty.").

Steps to reproduce

With Create Block Theme 2.10.1 (the same code is on trunk):

echo CBT_Theme_Locale::escape_block_attribute_strings( '<!-- wp:post-excerpt {"moreText":""} /-->' );
// <!-- wp:post-excerpt {"moreText":"<?php esc_attr_e('', 'my-theme');?>"} /-->

Expected behavior

Empty attribute values are left as they are, e.g. "moreText":"". A possible fix is to skip empty strings in escape_block_attribute_strings() (or in escape_block_attribute()), matching the other two functions.

Drafted with AI assistance, reproduced and verified by me.

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