WordPress / create-block-theme

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

The HTML within a paragraph gets converted into a translation string on theme save #573

Open pshemek opened 6 months ago

pshemek commented 6 months ago

I ended up with:

<!-- wp:paragraph {"style":{"typography":{"fontStyle":"normal","fontWeight":"500"}}} -->
<p style="font-style:normal;font-weight:500">
<?php echo __('<a href="mailto:email@example.com" data-type="mailto" data-id="mailto:email@example.com">email@example.com</a><br>Tel.: +48 000 000 000', 'mytheme');?>
</p>
<!-- /wp:paragraph -->

while the more desirable would be:

<!-- wp:paragraph {"style":{"typography":{"fontStyle":"normal","fontWeight":"500"}}} -->
<p style="font-style:normal;font-weight:500">
<a href="mailto:email@example.com" data-type="mailto" data-id="mailto:email@example.com"><?php echo __('email@example.com', 'mytheme'); ?></a><br><?php echo __('Tel.: +48 000 000 000', 'mytheme');?>
</p>
<!-- /wp:paragraph -->

I am aware it may be difficult to implement, but I'm just reporting the situations when I was forced to edit the generated template or pattern manually to make it deliverable.

I'm not even sure that every paragraph should be converted into a translation, but I have no idea how we could distinguish between the ones we want and the ones we don't.

pbking commented 6 months ago

Oh, great example! Thanks for logging.

Yes, I can see how this could be improved to ensure that it's only the content of elements (and not the entire nested elements) that need to be escaped.

creativecoder commented 6 months ago

It looks like WP_HTML_Tag_Processor doesn't yet support parsing or operating on child nodes, unfortunately, which would make this easier to solve. But I do believe that functionality is planned for the future.

shivapoudel commented 3 months ago

I have a paragraph with links and while saving translation it escapes and presents me the anchor markup within a paragraph. Is there any way we can escape that translation with comments?

iamtakashi commented 1 month ago

I've just experienced this with the theme I'm working on now. It'd be great if the issue gets resolved soon. I appreciate any help you can provide.

iamtakashi commented 1 week ago

@mikachan, Could anyone from the team please look into this issue? We have to fix it manually every time we save the theme.

<p><a href="#">Watch</a> Djokovic vs. Alcaraz with live commentary</p> becomes

<p><?php esc_html_e('<a href="#">Watch</a> Djokovic vs. Alcaraz with live commentary', 'tiebreak');?></p>

mikachan commented 1 week ago

Thanks for the ping, @iamtakashi. We have a potential fix in https://github.com/WordPress/create-block-theme/pull/719, although finding a good solution is difficult. However, I'm hoping we'll be able to merge that PR soon.

iamtakashi commented 1 week ago

Thanks for your response, @mikachan. The PR makes me feel a little relieved. I, too, hope that fixes the issue! It has been a headache for themers for a while.