Magento translation

Table of Content

Magento has three different methods how to add translation:

  • inline translation
  • theme translation
  • module translation
    Often it is difficult to choose the correct method,

There are different ways to achieve translation in Magento so you can find multiple directory containing static csv files and also a database table. All the modes have the same structure: key/value. For example: "String to translate","String translated".

Inline Translation

(database table: core_translate):

Following best practices in Magento, you should use inline-translation aka database saved translation in rare cases. It is harder to maintain and can be buggy. It has first precedence, so any translation you do via inline translation will override the other ‘modes’.

pros

  • no files;
  • the simplest way. Just enable option in Admin panel and add translation directly on the frontend part;

cons

  • limited with 255 symbols. You cannot translate big texts with this method, and you cannot change this behaviour according to MySQL limitation;
  • buggy. It is not alway possible to understand what wrongs with translation and why it doesn’t show the translated text;
  • use only for short text, e.g. label, title, etc.

Theme level Translation

(file in app/design/frontend/your_package/your_theme/en_EN/translate.csv):

You can place any string to be translated in the translate.csv. It has second precedence.

pros

  • all translation can concentrated in one file;

cons

  • need to add translation per each theme separately;

Locale Translation

(file in app/locale/ru_RU/Module_Name.csv):

The suggested way to do translation as it will keep translation separated by each module and is easier to maintain. For example: Mage_Catalog.csv etc. Each module in Magento can specify its csv file containing translation and sometimes the same string has different modules trying to translate, so if your translation does not work check between multiple file by a quick editor search. It will be overridden by the two above modes.

pros

  • flexibility. Each module contain translation in separated file;

cons

  • complexity. The first time you will need help from a developer to explain where translations laying.

Note: Magento will load all the CSV files and build up a giant tree and caches it. So before scratching your head because the string is not translated as you wished in the frontend:

  1. clean the cache.
  2. check for any same key string which comes after your translated string. For example: in the same CSV Line 100 will override Line 1 if the key string are the same.
  3. check for any same key string in the mode which has higher precedence. For example: inline translation will override any CSV based translated string.

Other methods

Category Translation

Switch between store view and translate your content, but avoid duplication of CSS/JS in your HTML markup. It is the best approach for big texts and the simplest way for edit the texts in Admin panel for non-technical people.

pros

  • a simple and handy way to add/edit translation;

cons

  • control you HTML markup strictly, it has to be identical per store view;
  • it is very simple to break HTML markup which is almost imposible to restore.

CMS Block Translation

This method allow to create separate static block with text per store and include it in Category or Page, but it is complex to switch between blocks in different store views and maintain HTML markup identical.
The better approach is to install mb/translate module that allow to use '{{translate text="Your text here"}}' directive in CMS blocks. Use this approach with short text up to 255 symbols to allow people translate text using Inline translation on Frontend, otherwise use it without limitation and add translation to a corresponded CSV file directly.

Useful links

Leave a Reply

Your email address will not be published. Required fields are marked *