Magento – How to add a new language – Magento 2.0.1

language-packagelocalisationmagento2

I am trying to create a new store view for the Tamil Language, but the language does not get listed while choosing the language from admin.

short description of what I have done

1) I have successfully created Tamil Store View. Please refer the screenshot for your easy reference.

tamil store view

2) Next, I am trying to add Tamil Language Package

2.1 collect phrases

create the folder /var/www/html/magento2/app/i18n/tamil/tn_tn/

after that run the below command and get a success message

php bin/magento i18n:collect-phrases -o "/var/www/html/magento2/app/i18n/tamil/tn_tn/dictionary.csv" -m "/var/www/html/magento2/"

2.2 composer.json

{
    "name": "tamil/tn"
    ,"type": "magento2-language"
    ,"description": "Tamil language"
    ,"authors": [{
    "name": "Bilal Usean",
    "email": "yyyyyy@yyyyy.yyy",
    "role": "Developer"
    }]  
    ,"extra": {"map": [["*", "tamil/tn_tn"]]}
}

2.3 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>tn_TN</code>
    <vendor>tamil</vendor>
    <package>tn_tn</package>
</language>

2.4 registration.php

<?php

\Magento\Framework\Component\ComponentRegistrar::register(
   \Magento\Framework\Component\ComponentRegistrar::LANGUAGE,
   'tamil_tn_tn',
   __DIR__
);

2.5 Translate

dictionary.csv contains 8000+ rows of phrases for the sample I have taken one (open in gedit)

"We found other products you might like!","We found other products you might like!",module,Magento_Catalog

tn_TN.csv I have translated above particular line (contains one row)(open in gedit)

"We found other products you might like!","நீங்கள் விரும்பக்கூடிய மற்ற பொருட்கள் காணப்படும் !",module,Magento_Catalog

2.6 Language pack

run the below command for creating the language pack and get a success message Successfully saved tn_TN language package.

php bin/magento i18n:pack -d app/i18n/tamil/tn_tn/tn_TN.csv tn_tn tn_TN

It will create directory (tn_tn pack)

<magento-root>/tn_tn/vendor/magento/module-catalog/i18n/tn_TN.csv

someone noted it, collect phrases and lang pack commands are different from the official doc, please refer this link for why am I using like this way.

Overall structure of my language package

enter image description here

After that clear cache, run setup:upgrade, indexer:reindex but I can't found my Tamil language pack in newly created Tamil store view locale options.

easy for your reference

I would like to mention one more, I have researched about existing lang pack /var/www/html/magento2/vendor/magento/language-de_de (composer.json, language.xml, registration.php) but unable to find the exact name of the locale like listed in admin(German (Germany)). So I confused any step I missed to create locale.

why Tamil language package does not get installed?

Best Answer

Step 1: collect the phrases

First, you need to find out the phrases that you need to translate.

You can do so by running:

php bin/magento i18n:collect-phrases -o "/path/to/magento2/app/i18n/vendor/lg_lg/dictionary.csv"

Note that vendor is the same as when you develop module and lg_lg is the lang code of your language.

Step 2: create the composer.json file

Go to your app/i18n/vendor/lg_lg folder and create the composer.json file:

{
    "name": "vendor/lg"
    ,"type": "magento2-language"
    ,"description": "Tamil language"
    ,"authors": [{
        "name": "Bilal Usean",
        "email": "bla@bla.com",
        "role": "Developer"
    }]  
    ,"extra": {"map": [["*", "vendor/lg_lg"]]}
}

Step 3: create the language.xml file

Still in your app/i18n/vendor/lg_lg folder you need to create a language.xml file:

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

Step 4: create the registration.php file

Still in the same folder, you need to create a registration.php file:

<?php

\Magento\Framework\Component\ComponentRegistrar::register(
   \Magento\Framework\Component\ComponentRegistrar::LANGUAGE,
   'vendor_lg_lg',
   __DIR__
);

Step 5: translate

Still in your folder, you can start writing your translations in a lg_lg.csv file based on the dictionary you retrieved in step 1. You can use the offical guide to follow the translation guidelines: http://devdocs.magento.com/guides/v2.0/config-guide/cli/config-cli-subcommands-i18n.html#config-cli-subcommands-xlate-dict-trans

Step 6: create the language pack

Run the following command:

php bin/magento i18n:pack app/i18n/vendor/lg_lg/lg_lg.csv lg_Lg lg_LG

Important note

For this to work, your .csv file name must exactly match the locale, including the characters' case.

Official documentation: http://devdocs.magento.com/guides/v2.0/config-guide/cli/config-cli-subcommands-i18n.html#config-cli-subcommands-xlate-example2

Related Topic