I'm developing a custom module for my Magento installation (version 1.6.2.0). I registered a translation file for the module in the config.xml and started to add German translations. The module adds some new behavior to the Magento back end.
While doing the translation I noticed a strange behavior of Magento. Certain words don't get translated by Magento although a 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 "Store".
Content of the csv file:
"City","Stadt"
"City1","Stadt"
I use the following line to translate the strings.
Mage::helper('mymodule')->__('City') // returns "City"
When I change the key to "City1" every thing works as expected.
Mage::helper('mymodule')->__('City1') // returns "Stadt"
After this I searched the German translation csv files (provided by the German Magento Community) for a translation for the key "City" and found one in the "adminhtml module".
Mage::helper('adminhtml')->__('City') // returns "Stadt"
So this also works as expected.
I don't know what I'm doing wrong. As I said the same behavior occurs for the string "Store".
Any ideas on this?
Finally I solved the translation problem. The reason was a wrong configuration in the config.xml. I found it out by debugging the code where Magento reads in the translation files. When this happens there's a parameter called scope which is read from one of the XML elements of the config.xml file.
This element should normally have the name of the module, e.g. <MyCompany_MyModule>
. In the tutorial I followed to configure the translation, this XML-element was named <translations>
which was wrong.
I guess that this might have been correct for an earlier version of Magento. What made it hard to find out was that the errors only occur for keys which were also defined in other modules's translation files. Keys which were only defined in my translation file worked as expected.
An 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>
Hard to say without having your code at hand, but my guess would be that the translation scope of your module somehow gets lost (for whatever reason) causing Magento to fallback.
Afaik, in Magento 1.6.2.0 the following translation files also define the key City
:
/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'd try to change the translation for City
in these .csv
files one by one, to find out where the translation in question is actually coming from.
Once you found the file to which Magento is falling back, you also know, which translation scope you need to override, to force your translation of City
to be used.
For example, if you find changing the translation in Mage_Shipping.csv
does take affect, then you edit your translation file (My_Module.csv
) to contain
"Mage_Shipping::City","Stadt"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With