How to generate a translation dictionary of a module in Magento 2?

Dec 17th, 2018 2 min to read

In this article, you will come to know how one can generate a translation dictionary of a module in Magento 2.

You can generate a translation dictionary to use by itself (for example, to translate words and phrases in a custom module) or for use by a language package.

Work with translation dictionaries

To translate words and phrases, you must:

  • Run the translation collection command to extract translatable words and phrases from enabled components.
  • Translate the words and phrases.

After that:

  • You can package the translation dictionaries into a language package and provide the package to the Magento store administrator.
  • In the Magento Admin, the store administrator configures the translations.

Command options:

php bin/magento i18n:collect-phrases [-o|--output="<csv file path and name>"] [-m|--magento] <path to directory to translate>

The following table explains the parameters and values of the above command:

ParameterValue Required?
<path to directory to translate>Path to a directory that has translatable code; in other words, PHP, PHTML, or XML files that have phrases to translate.
The tool starts searching in the path you entered and searches all the files and subdirectories it contains.
Do not use this parameter if you use -m|–magento.

Yes (dictionaries), no (packages).
-m|–magento Required to create a language package from this translation dictionary.
If used, searches the directories that contain bin/magento. This option adds themes or modules to each line in the dictionary.
An example follows:
“No Items Found”,”No Items Found”,module,Magento_Wishlist
-o|–output=”<path>” Specifies the absolute file system path and file name of the translation dictionary .csv file to create. The value you enter is case-sensitive. The name of the .csv file must exactly match the locale name, including the characters’ case.
If you omit this parameter, the output is directed to stdout.

To create a language pack from a translation dictionary, you must use the -m|–magento option.

Example: Create a translation dictionary for a module or theme

Collect phrases from your module:

Run below command from Magento root directory to generate translation directory for a module.

php bin/magento i18n:collect-phrases -o 	app/code/ExampleCorp/SampleModule/i18n/en_US.csv app/code/ExampleCorp/SampleModule
Speak your Mind

Post a Comment

Got a question? Have a feedback? Please feel free to leave your ideas, opinions, and questions in the comments section of our post! ❤️

* This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Grow your online business like 3,480 subscribers

    * This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

    Thank You!

    We are reviewing your submission, and will be in touch shortly.