In Magento 1 I use this code:
<?php echo $this->__('some <a href="%s">text here</a>', Mage::getUrl('some/url/here')); ?>
How can I use in Magento 2?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.Sign up to join this community
Your solution might look something like this:
<a href="<?php echo $block->escapeUrl($this->getBaseUrl().'customer/address/');?>"> <?php echo $block->escapeHtml(__('Street Address %1', $_i)); ?> </a>
All URLs and translated content should be escaped to prevent XSS. Also, HTML tags shouldn't be translated.
Also, you can wrap this code by an own method.
HTML code should not be used directly in a translation string, instead use a placeholder (i.e.
%1) to represent it, and put it's value in a subsequent parameter to the translation method.
<?= __('some %1text here%2', '<a href="' . $block->getUrl('some/url/here') .'">', '</a>') ?>
The Magento core team uses this approach throughout their code base.
For example in...