Get Free Audit

How to Internationalize a Magento Store

Nov 9, 2017

2054 Denis Minich

How to Internationalize a Magento Store

The article is a must-have for those who are interested in getting a web store internationalized. In order to handle multiple languages, you should follow the essential internationalization steps described below.

Ways to implement internationalization in Magento

There are three ways to implement internationalization in Magento:

  1. It’s possible to create different websites for every language. The approach allows dividing customers, orders, templates, catalogs, and domains according to the language. Multisiting helps to have absolutely different frontends while being managed from the same admin panel.
  2. An additional store can be created for your website. The approach helps to divide the catalog. It means you can sell different products for different regions while having the only website with common customer and order databases. Besides, the same template can be applied to these stores.
  3. Create a new store view. In this case, you can divide templates based on languages and translate text in the catalogs and blocks.

For illustration purposes, the structure is presented in the picture below:

How to Internationalize a Magento Store_2 (2)

Magento translate classes and files

As for Magento 1, if you want to get the phrase translated into the class or template file, you need to use the following type of functions  __(“your phrase”). The function is placed in the abstract class Mage_Core_Helper_Abstract which is on the path app/code/core/Mage/Core/Helper/Abstract.php. The function calls getTranslator() and passes the argument for translation.

In Magento 2 the same function type __(“your phrase”)  is used. But if compared with Magento 1, the function creates and returns the object Phrase “return new \Magento\Framework\Phrase($text, $argc)”. As you can see, it is translated in the class \Magento\Framework\Phrase. More information about renderer you can find in the file  /vendor/magento/framework/Phrase/README.md. In such a manner, translation is initiated by the method _initTranslate() in the file \Magento\Framework\App\Area.php.

Advantages and disadvantages of using subdomains and subcategories

As for subdirectories,
There are following advantages:

  • separate folders can be targeted
  • easier to transfer
  • more SEO optimized
  • easy to manage

Disadvantages are as follows:

  • SERP limited
  • URL can be messy on large websites
  • the only hosting can be used

As for subdomains,
There are following advantages:

  • the only domain is used
  • particular subdomain can be placed in different countries
  • the best usability

Disadvantages are as follows:

  • extra building is required
  • more difficult to maintain several subdomains

Which method is used for translating strings and where it is generally available

The method Mage_Core_Helper_Abstract::__() is used for translating strings in Magento 1. It is available in blocks, helpers and controllers.

In Magento 2 the method __() is also used, but in the file /vendor/magento/magento2-base/app/functions.php. Moreover, it is available in blocks, helpers and controllers.

In what way does the developer mode influence how Magento handles translations

If the developer mode is enabled, global translations get disabled in case of duplicating. It means that the string can be translated only within the module, if the string is specified in the translation file of the module.

Igor Dragun
Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Igor

How many options exist to add a custom translation for any given string

In Magento there are three options to add a custom translation:

  • module translation
  • theme translation
  • inline translation

1. Module translation:
In Magento 1 you need to create the file Namespace_Modulename.csv in the folder app/locale/languagecode_COUNTRYCODE/.

In Magento 2 you need to create the file languagecode_COUNTRYCODE.csv in the folder /app/code/Namespace/Modulename/i18n/.

2. Theme translation:
In Magento 1 you need to create the file translate.csv in the folder app/design/frontend/{package}/{theme}/locale/ languagecode_COUNTRYCODE.

In Magento 2 you need to create the file languagecode_COUNTRYCODE.csv and put in the folder /app/design/{area}/{package}/{theme}/locale/i18n/.

The strings in the files *.csv  should be as follows: “Text”,”Translate text”.

3. Inline translation
You need to go to System -> Configuration -> Developer:

How to Internationalize a Magento Store_1

You need to select “Store View” and make inline translation enabled.

What is the priority of translation options

In Magento 1 translations are loaded in the following order:

  1. module file /app/locale/languagecode_COUNTRYCODE/Namespace_Modulename.csv
  2. theme CSV file /app/design/{area}/{package}/{theme}/locale/languagecode_COUNTRYCODE/translate.csv
  3. database file (table core_translate)

In Magento 2 the order hasn’t changed. The only thing that has changed is files location in point 1 and 2.

  1. /app/code/Namespace/Modulename/i18n/languagecode_COUNTRYCODE.csv
  2. /app/design/{area}/{package}/{theme}/i18n/languagecode_COUNTRYCODE.csv

It means that database translation has top priority while module translation has the lowest priority.

How translation conflicts are processed by Magento when two modules translate the same string

There’s a conflict when two modules translate the same string. In this case, Magento creates two keys to keep data for each module.

For example:

  • For Namespace_Module1  “Text”, “Text 1” –  “Namespace_Module1:: Text”, “Text 2”
  • For Namespace_Module2  “Text”, “Text 2”  – “Namespace_Module2:: Text”, “Text 2”

Now we can get translation from module 1 in the following way: Mage::helper(‘Namespace_Module1’)->__(‘Text’). The same way is suitable for module 2.

As for Magento 2, translations from all modules are loaded, then it is loaded from the current one (focusing on the current controller). In most cases, the issue is solved.

Igor Dragun
Partner With Us Looking for a partner to grow your business? We are the right company to bring your webstore to success. Talk to Igor

1 comment

  1. The post which you have shared is really amazing on the tricks to internationalize a magento store .Apart from that Great collection of magento blogs and different ideas on it. Thanks for sharing this with us we are really greatful to you for the same.

Post a new comment

BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *