Magento 2 Language Packages

Magento 2 Language Package Explained

Magento is multi-lingual platform. It helps you to reach customers from different countries. Localization does not require change of codebase. Links to magento 2 language package for multiple languages can be found in the bottom of this article. Typically a developer use translation functionality for one of reasons:

  • localization – exactly when a phrase needs to be translated into different language
  • customization – when phrase needs to be changed. For example – “Add to Compare -> Compare”
  • to prepare your module/theme for localization. More merchants may use your theme if it supports localization.

Magento supports two types of language packages:

  • Translated Module and theme packages. Magento auto-discovers packages included in the i18n directory of a module or theme. When installing themes and extensions, consider checking for multiple language versions to download and use.
  • An entire dictionary in one directory. Use and distribute the dictionary as a standalone component (similar to modules and themes).

Magento 2 module / theme language package

It is basically a dictionary file(s) located in in module or theme. Like

__/vendor
     |__/magento
     | |__/module-developer
     |   |__/i18n
     |   |   |-- de_DE.csv
     |       |-- en_US.csv
     |       |-- es_ES.csv
     |       |-- fr_FR.csv

Dictionary file is a comma-separated value file with at least two columns: original phrase from code and translated phrase

"Next","Siguiente"
"Previous","Anterior"
"Please wait...","Por favor, espere..."
"Loading...","Cargando..."
"All","Todo","lib"
"more","más","lib"
"Save","Guardar"

If you do follow magento coding standards you can easily create dictionary file using magento console command.

php bin/magento i18n:collect-phrases -o "/var/www//magento2/app/code/ExampleCorp/SampleModule/i18n/es_ES.csv" /var/www/html/magento2/app/code/ExampleCorp/SampleModule

It will collect phrases from your module. Translate 2nd column of a file and it is ready.

Magento 2 language package

Another type of language packages is standalone component which contain entire magento dictionary. In addition to the .csv file that contains the language dictionary, the language package contains meta-information:

  • license.txt license file. Can be omitted
  • composer.json that contains any dependencies for the language package and a mapping to its defined locale
  • registration.php to register your language package as component
  • language.xml to declare a language package.

Sample composer.json

{
    "name": "magento/language-en_us",
    "description": "English (United States) language",
    "version": "100.2.0",
    "license": [
        "OSL-3.0",
        "AFL-3.0"
    ],
    "require": {
        "magento/framework": "101.0.*"
    },
    "type": "magento2-language",
    "autoload": {
        "files": [
            "registration.php"
        ]
    }
}

Sample registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::LANGUAGE,
    'magento_en_us',
    __DIR__
);

Sample language.xml

<?xml version="1.0"?>
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
    <code>en_US</code>
    <vendor>Magento</vendor>
    <package>en_US</package>
</language>

More information can be found on Magento portal under Create a language package section.

List of available packages

  • ru_RU – Russian Language Package.
  • de_DE – German Language Package.
  • de_CH – Swiss Language Package.
  • fr_FR – French Language Package.
  • da_DK – Danish Language Package.
  • es_AR – Spanish (Argentina) Language Package.
  • es_ES – Spanish Language Package.
  • pt_BR – Portuguese Brazil Language Package.
  • it_IT – Italian Language.
  • nl_NL – Dutch Language Package.
  • pl_PL – Polish Language Package.
  • tr_TR – Turkish Language Package.
  • ro_RO – Romanian Language Package.
  • fi_FL – Finnish Language Package.
  • ko_KR – Korean Language Package.
  • sk_SK – Slovakian Language Package.
  • sl_SI – Slovenian Language Package.
  • en_GB – British Language Package.

Complete CLI commands list – Magento 2 Command-Line Interface (CLI) Commands List

Leave a Reply

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