magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.51k stars 9.31k forks source link

Error when creating language pack #3303

Closed dynamogold-bkre closed 8 years ago

dynamogold-bkre commented 8 years ago

Using a clean 2.0.2 CE, I created an language pack doing the following in the magento root directory: ./bin/magento i18n:collect-phrases -o var/tmp/de_DE.csv -m ./ ./bin/magento i18n:pack --allow-duplicates var/tmp/de_DE.csv app/i18n/DynamoGold/de_de/ de_DE

This results in an (silent) error. I found the following in the php_error.log:

[05-Feb-2016 13:59:31 UTC] PHP Parse error: syntax error, unexpected '' is not found'' (T_CONSTANT_ENCAPSED_STRING), expecting ';' in /Applications/MAMP/htdocs/BIGO/shop2.birkengold.com/setup/src/Magento/Setup/Module/I18n/Dictionary/Phrase.php(278) : eval()'d code on line 1

It breaks when parsing line 44 of var/tmp/de_DE.csv: "Entity type model '%1' is not found","Entity type model '%1' is not found",module,Magento_AdvancedPricingImportExport

The error seems to occur when single quotes are not correctly escaped. I think this happens already during i18n:collect-phrase, but I am not sure.

I fixed this by changing setup/src/Magento/Setup/Module/i18n/Disctionary/Phrase.php to

private function getCompiledString($string) { $encloseQuote = $this->getQuote() == Phrase::QUOTE_DOUBLE ? Phrase::QUOTE_DOUBLE : Phrase::QUOTE_SINGLE; //find all occurrences of ' and ", with no \ before it. preg_match_all('/(?<!\)[\'"]/', $string, $matches); if (count($matches[0]) % 2 !== 0) { $string = addslashes($string); } $escapedString = str_replace("\'", "'", $string); $escapedString = str_replace("'", "\'", $escapedString); $evalString = 'return ' . $encloseQuote . $escapedString. $encloseQuote . ';'; $result = @eval($evalString);

return is_string($result) ? $result : $string; }

Please look at the two lines before $evalString = ...

This is obvisousely a dirty hack, but someone needs to take care of this since it is currently not possible to create language packs even on a Magento 2 CE installation out of the box

amenk commented 8 years ago

In https://community.magento.com/t5/Technical-Issues/Problem-with-i18n-translation-collection-command-PHP-Parse-error/td-p/24879 the user niro says, it is only happening with PHP7

francesco-carrella commented 8 years ago

+1 Same issue on php v7.0 here

mazhalai commented 8 years ago

Internal ticket MAGETWO-50078

Zatara7 commented 8 years ago

Hi @dynamogold-bkre I was able to collect phrases then running the pack command with no problems. This logic has been changed in the past few weeks so please checkout the develop branch and let us know if you face any more problems. Thank you.