1

I have a store in three languages, and I installed an extension which have lines of code such as:

<?php echo $this->__('Email Address') ?>

And then I have this string translated in each of the three languages. This is working fine.

But then I want to add some new strings to translate. I opened up Mage_Adminhtml.csv under app/locale/es_ES (for the Spanish case), and found there the translation for 'Email Address' and the other strings that are working. So, at the end of the csv file, I added a new line with this text:

"Please login","Por favor, inicie sesión"

And then, in my .phtml file, I include <?php echo $this->__("Please login") ?>. But then I don't get any translations, I only get this string (Please login) no matter what language is chosen.

I saw on other posts that there are different ways of translating but this one seemed the most straigthforward. Could you please tell me what am I missing or doing wrong?

Thank you in advance :-)

  • on which page have you add text Please login? – Kul Dec 2 '16 at 10:07
  • Actually I downloaded an extension named 'Ask to login', and the string 'Please login' is not being translated, as well as some others. So I added this text to index.phtml, which is the file that contains this strings. – LeCodeur Dec 2 '16 at 10:15
0

Translations work on different levels, you could have them in a CSV files just like you do, in local.xml in a <translate> node inside your theme folder, or directly in the DB using "inline translation"

To me the cleanest and easiest way to maintain is what you are referring to.
But the issue with this is that some translation might overlap, as you can guess, there would be many occurrences of a string like Please login inside Magento. If you search through all the core CSV files you'll probably find it more than once. Then "how does Magento know which translation to use at a given location?" you'll ask.

Modules (Mage_Adminhtml, Mage_Catalog ...etc) have configuration files which indicate what translation files to use:

[...]/etc/config.xml:

<config>
    <frontend>
        <translate>
            <modules>
                <Company_Module>
                    <files>
                        <default>Company_Module.csv</default>
                    </files>
                </Company_Module>
            </modules>
        </translate>
    </frontend>
</config>

The sure way to have your translations being used it to use a Helper (the one in your Module) and then translate strings like this:
Mage::helper('myhelper')->__('Text to translate')

  • Thank for your explanation. I am new to Magento and don't really know what a Helper is. In my extension's Helper folder, I have a file called Data.php, which only has this code: <?php class Techbandhu_Asktologin_Helper_Data extends Mage_Core_Helper_Abstract{}. Where should I add this translation then? – LeCodeur Dec 2 '16 at 11:26
  • In Magento1 a Helper file is necessary, even if it has no content. You still have to add the translation to the CSV provided with the module (if it has one, otherwise add the config I put in my answer). Then you'll have to use my last line of code for Magento to know you're using your module's Helper and thus its translation file. – Julien Lachal Dec 2 '16 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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