WordPress / create-block-theme

A WordPress plugin to create block themes
https://wordpress.org/plugins/create-block-theme/
GNU General Public License v2.0
310 stars 44 forks source link

Localize option tries to localize already localized strings breaking the patters. #632

Closed matiasbenedetto closed 1 month ago

matiasbenedetto commented 1 month ago

What

The localize option tries to localize already localized strings, breaking the patterns.

Example output of saving TT4 theme using 'Localize Text' option enabled:

<!-- wp:paragraph {"align":"left"} -->
<p class="has-text-align-left"><?php echo __('Experience the fusion of imagination and expertise with Études <?php echo __('Architectural Solutions', 'twentytwentyfour');?>.', 'twentytwentyfour');?></p>
<!-- /wp:paragraph --></div>

Please observe that an echo statement is inside another echo statement, which will result in a parse error. This breaks the pattern where this is included.

Expected

The localize functionality should not try to localize already localized text.

matiasbenedetto commented 1 month ago

Adding more details:

What's the bug? 'Localize text' functionality collects the strings that should be translated in a theme as a list. Example:

Having that it tries to add translation marks to each of those strings in the templates. Example:

<?php echo __("Hi!", "my-theme"); ?>
<?php echo __("Good bye!", "my-theme"); ?>

The problem arises when a longer string contains a shorter string present in other element. In those cases the output is invalid PHP so the templates break.

<?php echo __("<?php echo __("Hi!", "my-theme"); ?> I'm glad you chose My Theme", "my-theme"); ?>