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
You can use the locale emulation for this:
$storeId
would be the ID of another store with the specified language that you want to use.
$locale = Mage::app()->getLocale();
$locale->emulate($storeId); //push current locale to stack and replace with locale from specified store
//your magic here
$locale->revert(); //use last locale before last emulation
Best Answer
This is a good question really, but in the current implementation of the i18n tool there is no option to generate a dictionary for the storefront strings only.