create-block-theme icon indicating copy to clipboard operation
create-block-theme copied to clipboard

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

Open pshemek opened this issue 10 months ago • 7 comments

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 protected]" data-type="mailto" data-id="mailto:[email protected]">[email protected]</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 protected]" data-type="mailto" data-id="mailto:[email protected]"><?php echo __('[email protected]', '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.

pshemek avatar Apr 19 '24 13:04 pshemek

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.

pbking avatar Apr 19 '24 13:04 pbking

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.

creativecoder avatar Apr 19 '24 16:04 creativecoder

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?

shivapoudel avatar Jul 13 '24 01:07 shivapoudel

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 avatar Sep 05 '24 15:09 iamtakashi