WordPress / wporg-main-2022

A block-based child theme for WordPress.org, plus local environment
72 stars 26 forks source link

Parser: Enable translating link destinations #291

Closed ryelle closed 1 year ago

ryelle commented 1 year ago

This updates the button parser and list item parser to allow translating link destinations as well as link text.

For buttons, the block parser can interpret the destination as its own item to translate, so only the link is wrapped in _e().

<div class="wp-block-button">
  <a class="wp-block-button__link wp-element-button" href="<?php _e( 'https://wordpress.org/hosting/', 'wporg' ); ?>">
    <?php _e( 'See all recommended hosts', 'wporg' ); ?>
  </a>
</div>

For list items, it makes more sense to fall back to the same behavior as paragraphs and other default blocks, where the whole link element is translated.

<li><?php _e( '<a href="https://learn.wordpress.org/course/getting-started-with-wordpress-get-setup/">WordPress courses ↗</a>', 'wporg' ); ?></li>

See #266.

How to test the changes in this Pull Request:

  1. Check that the tests pass
  2. Try re-running yarn build:patterns
  3. There should be no visual changes to updated pages