2

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

2 Answers 2

2

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);
9
  • Hi I use Inline Translations but I can't see any modifications after press on Submit and clear and refresh the cache. I edit my post I add my translation window for this text.
    – Robert
    Commented Apr 13, 2017 at 22:38
  • Can you check the core_translate table in the database if your edit is there? Commented Apr 13, 2017 at 22:40
  • yes is there I put an image into my post to see it there
    – Robert
    Commented Apr 13, 2017 at 22:43
  • The strange thing is this: the translation is for the Excellence_Ajax module, and the php code is in the app/code/core/Mage/Checkout/controllers/CartController.php file
    – Robert
    Commented Apr 13, 2017 at 22:46
  • Ok, first of all - please don't edit core files. ;) This will make patches and updates impossible. You can write your own modules for anything, or at least copy the file+path to app/code/local. Second, have you tried changing the prefix for string in the database to Mage_Checkout? Commented Apr 13, 2017 at 22:49
0

I found the same question on StackOverflow. Try this out:

One argument, in one place:

Mage::helper('module')->__('Hi %s, there is an error', $name);

Two arguments, in two places:

Mage::helper('module')->__('Hi %s, there is an error with code %s', $name, $code);

One argument, in two places:

Mage::helper('module')->__('Hi %1$s, there is an error. Your name is %1$s', $name);

Two arguments, swapping places:

// Template or block file
Mage::helper('module')->__('Hi %1$s %2$s, there is an error', $firstname, $lastname);

// CSV translation
"Hi %1$s %2$s, there is an error", "%2$s, %1$s received an error"
1
  • thank you but how will look this on my code?
    – Robert
    Commented Apr 13, 2017 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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