Many merchants were in a situation where, upon expanding an online business, they needed to provide a localized version of their store, adjusted to local markets and languages. Creating multi-language (localized) store in Magento 2 is very much easy and in every aspect configurable.
The first step in creating a multi-language store is to download and install a language pack for Magento 2. If you need to make an adjustment on a specific language or need to adjust to a specific local situation, then you can easily make all those changes.
As always, in Magento translation terms we are talking about .csv (comma-separated value), translation dictionary – file with at least two columns: the original phrase in the en_US locale and a translation of that phrase in another locale.
"Address","Adresse"
In Magento 2 we have language package which is basically a collection of translation dictionaries for a particular language together with meta-information.
There are two types of language packages:
- Module and theme packages. Included in the i18n directory of a module or theme, the Magento application auto-discovers these packages.
- An entire dictionary in one directory. This is intended to be used and distributed as a standalone component (similar to modules and themes).
You can use the ready-to-use language packages prepared by other users or you can create your own. You can create localizations based on existing, or parent, translations using language inheritance.
Inheritance means (among other things) that if you missed or omitted localizing some phrases or terms, parent translations are used. You can customize your translations even further by creating more than one version of a translation for the same language.
Why would you need to add a dictionary for a theme?
You have two basic use cases (I’m sure you can think of some others too):
- if you want to replace certain strings from the parent theme. For example, use “Compare” instead of “Add to Compare”.
- if you want your theme to be ready for localization.
Translation dictionaries
Magento translates words and phrases when all of the following conditions are met:
- The Magento code base has the necessary translation dictionaries for a language
- This language is configured by the store administrator to be used in the specified scope (that is, storefront)
The Magento application automatically assembles translation dictionaries located in modules’ i18n directory into a dictionary per language. For example, Croatian (hr_HR) translation dictionaries might be located in module and theme directories similar to the following:
app/code/Inchoo/Checkout/i18n/hr_HR.csv
app/design/frontend/Inchoo/multilanguagetheme/i18n/hr_HR.csv
Assembling the preceding hr_HR.csv files across all modules and the current theme results in a Croatian translation of the entire application area (storefront or the Admin).
Language packages
Magento enables you to create the following types of language packages:
- A set of .csv files for modules and themes. These package files are intended to be deployed in modules.
- Language packages that contain an entire dictionary in one directory.
In addition to the .csv file that contains the language dictionary, the language package contains meta-information:
- composer.json that contains any dependencies for the language package and a mapping to its defined locale
- language.xml, in which you declare a language package
Manually translate words and phrases
Translating the names, titles and phrases used in Magento involves the following steps:
- Generate a dictionary of your instance using the translation dictionary tool.
- Translate the terms.
- If desired, package your translations in a language package.
To sum up, there are two types of translations in Magento 2
- Translation dictionaries, which are a convenient way to translate some words and phrases, such as those for a custom module or theme. (Compare / Add To Compare)
- Language packages, which enable you to translate any or all words and phrases in the Magento application (Magento in Croatian language for example).
In most cases, if you are creating a multi-language store, you will use an already created language pack, install it and configure it.
So, your first step will be to obtain the language pack for a desired language. You can easily search the Magento marketplace for a specific language pack, download it and follow installation instructions.
In my next post I’m going to explain how to configure and deploy a Magento 2 store in two different languages, so stay tuned.