I want to define the translation dictionary of Magento 2 frontend web in Chinese, and I following the following doc:
As a learning exercise, I try to collect all the phrases in M2 upon a new installation. So in my Magento 2 setup, I issue the following command to try to collect all the phrases within M2:
php bin/magento i18n:collect-phrases -m -o "/var/www/html/tmp/i18n/zh_HK.csv" /var/www/html/
However, the command returned with the following error:
PHP Parse error: syntax error, unexpected 'Gateway' (T_STRING), expecting ';' in /var/www/html/setup/src/Magento/Setup/Module/I18n/Dictionary/Phrase.php(274) : eval()'d code on line 1
Is it a know issue in M2? What is the most appropriate way in developing a language pack for Traditional Chinese. I am willing to contribute my work too.
Solved! Go to Solution.
Please note that you use an old i18n:collect-phrases syntax which is supported by Magento 2.0.0 release but is not supported by the latest Magento 2 develoment version: https://mage2.pro/t/347
As the old syntax works on your Magento 2 version then your Magento 2 version is old too (maybe Magento 2.0.0 release?).
I recommend to update the code to the latest Magento 2.0.0 development version and use the new i18n:collect-phrases syntax: now you can specify or -m option or the folder to parse (/var/www/html/) but not the both.
I can not reproduce your error on the latest Magento 2. development version.
Thanks for the advice and I found that I am using the original 2.0.0 version.
I have followed your advice to clone the latest Magento2 development version, but still encounter the same error.
Now I can use the following command for collect-phrases:
php bin/magento i18n:collect-phrases -o "tmp/zh_HK.csv" -m
However, after a while, I saw the following error:
PHP Parse error: syntax error, unexpected 'Gateway' (T_STRING), expecting ';' in /Users/clarence/workspace/magento/magento2-demo/setup/src/Magento/Setup/Module/I18n/Dictionary/Phrase.php(274) : eval()'d code on line 1
Parse error: syntax error, unexpected 'Gateway' (T_STRING), expecting ';' in /Users/clarence/workspace/magento/magento2-demo/setup/src/Magento/Setup/Module/I18n/Dictionary/Phrase.php(274) : eval()'d code on line 1
I found the file tmp/zh_HK.csv had a few lines generated. Seems to me that magento tool hit some problematic strings that cause the parser to stop collecting phrases.
What you suggest for me to check which file or which phrase is having the issue? Or is there anyway I can tell magento to continue processing instead of abort processing?
Log the $evalString variable just before calling the eval function: https://github.com/magento/magento2/blob/2.0.0/setup/src/Magento/Setup/Module/I18n/Dictionary/Phrase...
How to write a message to system log: https://mage2.pro/t/15
So you will find what exactly the code leads you to the failure.
I followed your advice and is able to identify which code cause the problem.
Found that during collection, the tool will fail if it encounter any string contains the single quote (i.e. "'") character in it.
For example, the following code will cause the tool fail and abort:
$message = __('Some string: ' . $some_var . ' other string');
Also, for the label and comments, etc., if the content include single quote character, it will fail too.
There are quite a number of programs include those strings that will cause the error in collecting phrases.
I try to modify the code, take away the single quote characters and the tool can proceed to collect the phrases.
I believe those codes need to be updated in order to become "translatable".
Thanks a lot for the advice.
We have got this error on php7-beta and resolved by changing php version to 5.6