Magento 1.9 – Translate Text in PHP File

inline-translationslocalisationmagento-1.9

How I can translate this text in a php file, I want to translate $message

  if (!$this->_getSession()->getNoCartRedirect(true)) {
            if (!$cart->getQuote()->getHasError()) {
                $notifysymbol = "<img src='".Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA)."/noticeicons/1489953827_warning.png' >";
                $message = $this->__('<div class="notit"><span class="notification-symbol">%s</span><div class="rowt2"> <span class="added_cart">Product added to cart</span><br/><span class="small-text"> Go to the checkout to complete your purchase or add more products</span></div></div>',$notifysymbol);
                $this->_getSession()->addSuccess($message);
            }
            $this->_goBack();
        }

enter image description here

and this is the text in the Custom field:

<div class="notit"><span class="notification-symbol">%s</span><div class="rowt2"> <span class="added_cart">Product added to cart</span><br/><span class="small-text"> Go to the checkout to complete your purchase or add more products</span></div></div>

The text is the core_translate table too

enter image description here

Best Answer

The $message is already translatable, because you use $this->__() to generate it. So, you can enable Inline Translation to translate it.

However, it is not best practise to use HTML code inside a translatable string. Imagine you string will some time be changed by your client - this will surely result in errors when HTML code needs to be changed. I would suggest the following solution:

<?php
    $headline = $this->__('Product added to cart');
    $text = $this->__('Go to the checkout to complete your purchase or add more products');
    $message = $this->__('<div class="notit"><span class="notification-symbol">%s</span><div class="rowt2"> <span class="added_cart">%s</span><br/><span class="small-text">%s</span></div></div>', $notifysymbol, $headline, $text);
Related Topic