Skip to content

Localize Text doesn't localize string attributes of non-core blocks #869

Open

Description

@iamtakashi

What happens

"Localize Text" only localizes attributes of core blocks. get_localizable_block_attributes() is a fixed list (Search, pagination links, Navigation Link, Read More, …):

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

String attributes of other blocks are exported as-is. For example, WooCommerce's Mini-Cart shopping button:

<!-- wp:woocommerce/mini-cart-shopping-button-block {"startShoppingButtonLabel":"Shop"} -->

Expected

User-facing string attributes of any block are wrapped in esc_attr__().

Suggested fix

Instead of a hardcoded list, localize string attributes whose block.json definition has "role": "content" (the same signal the editor uses for content-only editing), and keep the list as a fallback for core blocks that don't declare it.

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

Activity

  1. prasadkarmalkar commented on Oct 28, 2026

    @prasadkarmalkar

    Hi! I'd like to take this one.

    I confirmed the cause in escape_block_attribute_strings(). The block name from the block comment is passed as 'core/' . $block_name. Core blocks are serialized without a namespace (wp:search), so that works for them. A namespaced block like wp:woocommerce/mini-cart-shopping-button-block becomes core/woocommerce/…, which never matches, so it's skipped.

    My plan:

    • Resolve the full block name properly (add core/ only when there's no namespace).
    • For non-core blocks, look the block up in WP_Block_Type_Registry and localize string attributes declared with "role": "content".
    • Keep the existing list for core blocks, so core behaviour doesn't change.
    • Skip url, href, src, id, and slug even if they're marked role: content. For example, core/navigation-link marks url as content, and localizing it would be wrong.

    Let me know if the approach looks good or any change requried.

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