Translation method does not work

someVar = <?php echo $this->__("Yes") ?>

seems to not work. Even when I try console.log(<?php echo $this->__("Yes") ?>). Isn't $this->__() supposed to return just string?

I have the translation in the *.csv file and I know it's the correct one, because I work with other translations from that file in the same template.

Solutions

Thanks to @David Manners for the note, it was helpful. Nevertheless, what solved my problem was using this: '<?php echo Mage::helper('module_name')->__("Yes") ?>'.

Make sure that in JavaScript your script is still encapsulated in quotations. Try the following code taking note of the semicolon and quotations.

someVar = '<?php echo $this->__("Yes") ?>';

Similar questions

Magento 2 - discount depend on Payment Method does not work
I go to Magento 2 Admin > Marketing > Promotions > Cart Price Rules and create a new Rule: Bank Transfer Payment: Tab Rule Information: Conditions tab: Actions Tab: Then I enable Bank Transfer Payment method, go to checkout page, click on Bank Transfer Payment but the Discount Percent Price does not show up in Order Summary. Please give me an advic...
Translation doesn't work on breadcrumbs added by xml
I'm building a custom page. I add breadcrumbs like this (and it works well). The problem is label not translated in front-end. It shows Home / All Brands instead of translated version. The things I made sure: Help me to figure it out, please. Thank you.
Translation function with multiple variables doesn't work
I have a problem using translate function. This works: But this doesn't: And the problem is, that I would like to translate this as: "Please call %2$s to speak to %1$s." so the order is important. Do you have any ideas why the second example doesn't work? I would appreciate any suggestions :).
Italian translation in a multi-language site don't work
I've a multilanguage site in Magento 1.9. I set Italian like default language. There are some words in the footer that aren't translate. I added this words into csv file but the problem remains. It's shown in the following image: "QUICK LINKS", for example, remains in English language. I Found this string in only in the file page.xml and I try to c...
Magento2. Knockout. Translation doesn't work
Please advice is there any pre-requirements to translate in *.html files Works: Don't want to work: Translation in i18n/en_US.csv exists. Am I doing something wrong?
Javascript translation doesn't work
I've got problem with default translation built in magento 2. A made static content deploy, file js-transation.json generated properly but strings didn't translated. Site: test-php.pl Version magento 2.1

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.