I have successfully created new rules for the prototype validation, now I need to translate the error messages (Location: String in Javascript). However, I can only translate all the messages, my new custom ones don't appear to be translatable. How do I change this?
We had exactly the same problem with one of our magento projects. We found that the function in app/design/frontend/default/default/template/page/htmlhead.phtml had been commented out:
<?php echo $this->helper('core/js')->getTranslatorScript() ?>
After putting this in, it still did not work, because translations had not been inserted into translate file. Check out those two things and it should start working.
Alan.
To expand on this, you must add the translation strings to Mage/Core/Helper/Js.php.
you can edit app/local/ur_language/Mage_Core.csv, adding in the first Column the original string and in the second one the translated, in that file are stored all the javascript translations.
To translate custom javascript error messages you need also to add them to the following file: \app\code\core\Mage\Core\Helper\Js.php
find a function *_getTranslateData()* and you'll see a bunch of messages already in there. just add your message somewhere in the array like this:
'This is my validation message' => $this->__('This is my validation message')
(don't forget a comma , )
and then put translation in some translate file.
In the file where you use this message (I use it in opcheckout.js file) you need to wrap text in Translator.translate('This is my validation message')
.
I haven't figured out yet if it's important which translate file that is. You can try Mage_Core.csv .
I needed it in Mage_Checkout.csv and it works in there.
Anyway, for those who are interested in more, I noticed that these javascript messages are printed in header of every html page and some worrie that it messes with the SEO. Anyway this is printed in file \app\design\frontend\bmled\default\template\page\html\head.phtml with the code
<?php echo $this->helper('core/js')->getTranslatorScript() ?>
Check for more here: http://www.magentocommerce.com/boards/viewthread/9307/
Oh and if you don't like this solution, mabey this will suite you better. Check here: http://blog.baobaz.com/en/tag/magento-translation
I hope this helps, I just hope this works everywhere, so far I tested it on Onepage Checkout only. cheers, jazkat