Translation with a custom translation file fails for certain words in Magento

I am developing my own module for installing Magento (version 1.6.2.0). I registered the translation file for the module in the config.xml file and started adding German translations. The module adds new behavior to the end of Magento.

During the translation, I noticed the strange behavior of Magento. Some words are not translated by Magento, although translation is provided in the module's csv file.

When I change the key to a different value, the translation works as expected, so Magento seems to see and read the cvs file.

At the moment, I notice this behavior for the keys "City" and "Shop".

The contents of the csv file:

"City","Stadt" "City1","Stadt" 

I use the following line to translate lines.

 Mage::helper('mymodule')->__('City') // returns "City" 

When I change the key to "City1", everything works as expected.

  Mage::helper('mymodule')->__('City1') // returns "Stadt" 

After that, I searched the German csv translation file (provided by the German Magento community) to translate the "City" key and found it in the "adminhtml module".

  Mage::helper('adminhtml')->__('City') // returns "Stadt" 

So, this also works as expected.

I do not know what I am doing wrong. As I said, the same behavior is observed for the line "Store".

Any ideas on this?

+7
source share
2 answers

Finally, I solved the translation problem. The reason is the wrong configuration in the config.xml file. I found this by debugging code in which Magento reads in translation files. When this happens, a parameter called scope appears, which is read from one of the XML elements of the config.xml file.

This element must have a module name, for example. <MyCompany_MyModule> . In the tutorial that I performed to set up the translation, this XML element was called <translations> , which was wrong.

I guess this could be right for an earlier version of Magento. Because of this, it was difficult to detect that errors occur only for keys that were also defined in other module translation files. Keys that were defined only in my translation file worked as expected.

The correct configuration should look like this.

 <frontend> ... <translate> <modules> <MyCompany_MyModule> <files> <default>MyCompany_MyModule.csv</default> </files> </MyCompany_MyModule> </modules> </translate> ... </frontend> <adminhtml> ... <translate> <modules> <MyCompany_MyModule> <files> <default>MyCompany_MyModule.csv</default> </files> </MyCompany_MyModule> </modules> </translate> ... </adminhtml> 
+8
source

It's hard to say without your code at hand, but I assume that the translation area of โ€‹โ€‹your module is somehow lost (for some reason), causing Magento to back off.

Afaik, in Magento 1.6.2.0, the following translation files also define the City key:

 /app/locale/<language>_<region>/Mage_Checkout.csv /app/locale/<language>_<region>/Mage_Customer.csv /app/locale/<language>_<region>/Mage_Persistent.csv /app/locale/<language>_<region>/Mage_Sales.csv /app/locale/<language>_<region>/Mage_Shipping.csv /app/locale/<language>_<region>/Mage_XmlConnect.csv 

I would try to change the translation for City in these .csv files one by one to find out where the translation actually comes from.

Once you find the file Magento is backing off to, you also know in which translation area you must override in order to make your City translation used.

For example, if you find that the translation change in Mage_Shipping.csv really affects, then you are editing the translation file ( My_Module.csv ) to contain

 "Mage_Shipping::City","Stadt" 
+4
source

All Articles