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

5 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
  2. I might want to thank you for the endeavors you have made in composing this article. I am trusting the same best work from you later on too.. Magento extensions by Mageworx

    ReplyDelete
  3. That is very interesting; you are a very skilled blogger. I have shared your website in my social networks! A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article.
    Magento course in chennai

    ReplyDelete
  4. Very helpful post! Thanks for sharing. I'd also like to suggest one ready-made tool called Google Translate Integration Magento 2 Extension. This module allows to translate your Magento 2 store content to more than 100 languages. Know more here: https://marketplace.magento.com/solwin-googlelanguagetranslate.html

    ReplyDelete