1

In en-US.csv file in our custom theme, I got a translation as below.

"We'll email you an order confirmation with details and tracking info.","Within 10 minutes we'll send an email to you with your <strong>order number</strong> and complete details.<br />When your order ships we'll email tracking information to you."

The problem is that the HTML does also appear along with the text when the order is placed. How to process HTML but not show the HTML like in the text?

2 Answers 2

3

Short answer is no way with translation

In templates where used this translation it will be escaped

For example in default success template

vendor/magento/module-checkout/view/frontend/templates/success.phtml

    <?php if ($block->getOrderId()) :?>
        <?php if ($block->getCanViewOrder()) :?>
            <p><?= $block->escapeHtml(__('Your order number is: %1.', sprintf('<a href="%s" class="order-number"><strong>%s</strong></a>', $block->escapeUrl($block->getViewOrderUrl()), $block->getOrderId())), ['a', 'strong']) ?></p>
        <?php  else :?>
            <p><?= $block->escapeHtml(__('Your order # is: <span>%1</span>.', $block->getOrderId()), ['span']) ?></p>
        <?php endif;?>
            <p><?= $block->escapeHtml(__('We\'ll email you an order confirmation with details and tracking info.')) ?></p>
    <?php endif;?>

You need to overwrite this template in your custom theme or module, or change template to your own with layout.

Links:

10
  • But I see entries in en_US.csv like "Your order # is: <span>%1</span>.","Your Confirmation # is: <span>%1</span>." How does this work?\ Jun 22 at 18:37
  • In answer in fragment of phtml file you can see few examples how to work with Phrase. %1 means first argument into Phrase. For example __('%2 #%1', '<a href="url">ID</a>', 'Order'), also you can allow tags with $block->escapeHtml(__('...'), ['a']); Jun 22 at 18:48
  • Can I add something like this <p><?= $block->escapeHtml(__('Within 10 minutes we\'ll send an email to you with your <strong>order number</strong> and complete details.<br />When your order ships we\'ll email tracking information to you.')) ?></p> in success.phtml in my custom theme? Jun 23 at 3:10
  • 1
    Sure. Just use <p><?= $block->escapeHtml(__('Within 10 minutes we\'ll send an email to you with your <strong>%1</strong> and complete details.<br />When your order ships we\'ll email tracking information to you.', $block->getOrderId()), ['strong']) ?></p> instead of original one Jun 23 at 8:17
  • 2
    The part ['strong'] means list of allowed tags, just extend it ['strong', 'br'] Jun 23 at 11:36
0

Try this:

<?= $block->escapeHtml(__("Within 10 minutes we'll send an email to you with your <strong>order number</strong> and complete details.<br />When your order ships we'll email tracking information to you."), ['strong','br']) ?>

Output: enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.