Magento 2 Translations overview
Overview of translations
The Magneto application enables you to localize your store for multiple regions and markets. We improved the localization and customization of Magneto instances by making translation dictionaries easier to update and by maintaining a reduced amount of code coupling and duplication.
A translation dictionary is a comma-separated value (.csv) file with at least two columns: the original phrase in the en_US locale and a translation of that phrase in an another locale. Sample translation from English (en_US) to Arabic_Egypt (ar_EG):
"Add to Cart","اضف الى السلة"
"Add to Compare","اضف الى المقارنات"
"Add to Wishlist","اضف الى قائمة الامنيات"
"Additional Product Info","معلو مات اضافية عن المنتج"
"Address %1 of %2","عنوان %1 ال %2"
A language package is basically a collection of translation dictionaries for a particular language together with meta-information. You can also distribute language packages to other merchants if you wish.
To create a language package, the .csv file requires additional columns that specify the themes or modules in which the translations were found. For more information, see Generate a translation dictionary.
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.
Changes in Magento 2
The language package (i18n directory) can now be moved and saved to any directory of your extension.The phrases for translations are enabled in the Phrase class.
It is recommended, but not enforced, that you do not place variables inside __() functions or new Phrase() calls. The scanner that collects the phrases from the code cannot interpret and collect the value of the variable when it is in these locations. Instead, you should place the full text in the __() function or new Phrase() call. If you need to specify a variable in these cases, ensure that it is translated correctly wherever it is defined as a string literal.
Why you might need to add a dictionary for a theme
You might need to add a dictionary for the default language (en_US) in the following cases:
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.
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.
Only one variant of translation can be used for a word or phrase in a package. Otherwise, Magento returns an error.
Anyone can submit translations on the storefront using the Text Editor. Changes made in the Text Editor are not recorded in an instance’s dictionary; instead, they are stored in the database. In the storefront, an inline translation of a phrase overwrites the translation stated in a dictionary. However, inline translations are theme-specific and do not apply if another theme is assigned.
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 specified scope (that is, storefront)
The Magento application automatically assembles translation dictionaries located in modules’ i18n directory into a dictionary per language. For example, Brazilian Portuguese (pt_BR) translation dictionaries might be located in module and theme directories similar to the following:
stands for the Magento_Checkout module directory. Its actual location in your code base depends on the way Magento was installed. See Conventional notations for paths to modules and themes for details.Assembling the preceding pt_BR.csv files across all modules and the current theme results in a Portuguese translation of the entire application area (storefront or the Admin).
Magento enables you to create the following types of language packages:
A set of .csv files for modules and themes. These packages files are intended to be deployed in modules. For example:
Language packages that contain a entire dictionary in one directory.
You can distribute this language package as a standalone component (similar to modules and themes). Interestingly, it violates Magento’s modularity principles on purpose; that is, so that a system integrator can translate variations provided by extensions.
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.
Magento DevDocs :