How to create language package on Magento 2

This blog explains how to create language package on Magento 2. Here's the example of Vietnamese language.


1. Generate dictionary file

$ cd /root/dir/magento
$ bin/magento i18n:collect-phrases --output="app/design/frontend/vendor_name/theme_name/i18n/vi_VN.csv" --magento ./

2. Create language pack and register it

$ bin/magento i18n:pack -d app/design/frontend/app_name/theme_name/i18n/vi_VN.csv ./ vi_VN

3. Modify config files

Add & modify these 3 files.
# app/i18n/app_name/vi_VN/composer.json
{
    "name": "app_name/language-vi_vn",
    "description": "Vietnamese language",
    "version": "100.0.0",
    "license": [
        "OSL-3.0",
        "AFL-3.0"
    ],
    "require": {
        "magento/framework": "100.0.*"
    },
    "type": "magento2-language",
    "autoload": {
        "files": [
            "registration.php"
        ]
    }
}

# app/i18n/app_name/vi_VN/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::LANGUAGE,
    'magento_vi_vn',
    __DIR__
);

# app/i18n/app_name/vi_VN/language.xml
# PLEASE NOTICE MANUAL IS WRONG
# package MUST BE LOWER CASE
<?xml version="1.0"?>
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
    <code>vi_VN</code>
    <vendor>app_name</vendor>
    <package>vi_vn</package>
    <sort_order>100</sort_order>
</language>

Reference

http://devdocs.magento.com/guides/v2.0/config-guide/cli/config-cli-subcommands-i18n.html#m2devgde-xlate-files
If you liked this article

Let's subscribe the updates of Scuti!
Share on Google Plus

About Tomohide Kakeya

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

2 Comments:

  1. Please help.
    After refresh frondend I get an error as the following:
    Notice: Undefined offset: 1 in /var/www/html/megamart/vendor/magento/framework/App/Language/Dictionary.php on line 183
    What was happening ? Thanks

    ReplyDelete
    Replies
    1. I can't give you exact answer with only this information but CSV format is correct? I see this person also encountered the same problem.
      http://magento.stackexchange.com/questions/101692/problem-when-create-a-language-package-for-magento-2

      Delete