5

I'm attempting to translate the error messages returned by the Postcode Anywhere module. They're displayed in browser alerts, so are created in JavaScript.

I managed to translate one using the inline script method as below:

alert( Translator.translate(error) );

Translator.add('PostalCode Required', '<?php echo $this->__('Translated text here'); ?>');

I don't really like that though because it means I have inline JavaScript, and a translation held within a template file when all my other translations are held in the global locale folder. In an attempt to make this cleaner, I've tried to use the newer jstranslate method but I can't get it functioning correctly.

Edit: Here's a link to the tutorial I followed: http://en.herveguetin.com/translate-javascript-with-jstranslator-xml.html

I have a module config.xml defining a module like so (Client is used to replace the real name for privacy purposes):

<modules>
    <Client_PostcodeAnywhere>
        <version>0.0.1</version>
    </Client_PostcodeAnywhere>
</modules>

Inside the frontend -> layout sections of the config.xml file I have added:

<jstranslate>
    <file>jstranslator.xml</file>
</jstranslate>

Inside the frontend section of the config.xml I have added:

<translate>
    <modules>
        <client_postcodeanywhere>
            <files>
                <default>Client_PostcodeAnywhere.csv</default>
            </files>
        </client_postcodeanywhere>
    </modules>
</translate>

I have created the jstranslator.xml file in the same location as the module config.xml file:

<jstranslator>
    <client-postcodeanywhere-required translate="message" module="client_postcodeanywhere">
        <message>PostalCode Required</message>
    </client-postcodeanywhere-required>
</jstranslator>

I have created the Client_PostcodeAnywhere.csv file in my fr_FR folder within global locale folder (translating English to French):

"PostalCode Required","Translated text here"

I don't get a translation after doing this and I don't know why. Does anyone understand what the xml tags in the jstranslator file need to be? Mine is called 'client-postcodeanywhere-required' but I don't even know what that means.

2
  • Can anyone explain what the tags in <jstranslator> actually mean? For example, <client-postcodeanywhere-required> is just something I made up. Jan 28, 2014 at 9:53
  • 1
    It doesn't matter, just make up something that makes sense to you and is unique. Jul 9, 2015 at 12:12

2 Answers 2

1

Requirements

  • A module must be declared
  • This module must be ready to receive translations (.csv files + Helpers and translate node must be declared in the module's config.xml)
3
  • The module is declared, see the second code block. That's part of a module config.xml. The 3rd, 4th and 5th code blocks are where I have followed instructions on using jstranlate to setup the module to receive translations. Does that make sense? Jan 28, 2014 at 9:02
  • Is Helper defined? Jan 28, 2014 at 9:08
  • What is a translate node and how is it declared in config.xml?
    – hakre
    Feb 13, 2015 at 8:21
1

My example code does work. I think I may have had a mismatch in naming somewhere but this is functioning as expected now.

Your Answer

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

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