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

  1. $ cd /root/dir/magento
  2. $ 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

  1. $ 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.
  1. # app/i18n/app_name/vi_VN/composer.json
  2. {
  3.     "name": "app_name/language-vi_vn",
  4.     "description": "Vietnamese language",
  5.     "version": "100.0.0",
  6.     "license": [
  7.         "OSL-3.0",
  8.         "AFL-3.0"
  9.     ],
  10.     "require": {
  11.         "magento/framework": "100.0.*"
  12.     },
  13.     "type": "magento2-language",
  14.     "autoload": {
  15.         "files": [
  16.             "registration.php"
  17.         ]
  18.     }
  19. }

  1. # app/i18n/app_name/vi_VN/registration.php
  2. <?php
  3. \Magento\Framework\Component\ComponentRegistrar::register(
  4.     \Magento\Framework\Component\ComponentRegistrar::LANGUAGE,
  5.     'magento_vi_vn',
  6.     __DIR__
  7. );

  1. # app/i18n/app_name/vi_VN/language.xml
  2. # PLEASE NOTICE MANUAL IS WRONG
  3. # package MUST BE LOWER CASE
  4. <?xml version="1.0"?>
  5. <language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
  6.     <code>vi_VN</code>
  7.     <vendor>app_name</vendor>
  8.     <package>vi_vn</package>
  9.     <sort_order>100</sort_order>
  10. </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

6 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. 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