3

In order to build this CSV app/code/Vendor/Module/i18n/en_US.csv, I want to get an array from my module with all the translation-ready strings from all files types (.php, .phtml, .js, .xml).

.php & .phtml

__('string')

.js

$.mage.__('string')

.xml

<group id="general" translate="label" type="text" sortOrder="120" showInDefault="1" showInWebsite="1" showInStore="1">

and

<field id="showmethod" translate="label" type="select" sortOrder="280" showInDefault="1" showInWebsite="1" showInStore="0">

and

<argument name="header" xsi:type="string" translate="true">Report Date</argument>

and

<item name="label" xsi:type="string" translate="true">CSV</item>

...

How can I get a list (array) of all the translation-ready strings from a module for creating a CSV file?

17
+50

Magento 2 already has a command that can collect all the texts from a certain folder that are translatable.
Since one module can mean 1 folder, let's say your module name is app/code/Vendor/Module you can collect all translatable texts like this:

bin/magento i18n:collect-phrases app/code/Vendor/Module/ -o app/code/Vendor/Module/i18n/en_US_raw.csv

Just make sure the folder i18n exists inside your module.
After you are done translating what you need to move the file en_US_raw.csv to a file name corresponding to your language code inside the same folder.
For Romanian, for example, the file name should be ro_RO.csv.

2
  • Hey @Marius, I Update my question, sorry for my first question, I hope so as well now my question.
    – St3phan
    Oct 20 '17 at 13:56
  • It works perfectly
    – St3phan
    Nov 7 '17 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.