Magento uses a system for translating text in the template files using:
$this->__('text to be translated.');
or
Mage::helper('modulename')->__('text to be translated.');.
This works quite well.
But when I add text to a javascript file I can’t use these two methods.
Is there a way I could do a similar thing with the translations for javascript files?
You can do it in a template file yourfile.phtml. The JavaScript
js/mage/translate.jsfile must be included in your HTML header (Magento does it by default).Since Magento 1.7, you can add a file jstranslator.xml into your module under the etc/ folder and set the following string like that:
Then translate the string as you do it for PHP thanks to the CSV file. This will add the translation to the JavaScript code like the following
var Translator = new Translate(...).