php-gettext / PHP-Scanner

PHP code scanner for gettext
MIT License
14 stars 5 forks source link

Parser Failing on Multi-Line Code #14

Closed BusterNeece closed 2 years ago

BusterNeece commented 2 years ago

In the process of trying to upgrade from php-gettext version 4.x to 5.x in my code, and the following example code:

<?php
$var = __(
  'Test string. This is a very long string, so I want to wrap it across '
  . 'multiple lines.'
);

Yields the error:

Invalid gettext function in (file). Some required arguments are not valid

I believe this is because the parser isn't correctly handling the multiline string inside the function call.

oscarotero commented 2 years ago

Fixed in v1.3.1. Thanks!

tvdijen commented 1 year ago

Hi @oscarotero! I'm running into the same error when scanning a PHP-files, specifically compiled Twig-templates. Other PHP-files will pass without problem. I haven't opened a separate issue yet, since I'm not sure if this is a bug or me misusing this library..

Would you mind taking a look at my code? An example of a compiled Twig-template can be found here. I'm trying to catch the ->trans(...) calls here.

I've been banging my head against the wall on this for quite some time, so your help would be much appreciated!

oscarotero commented 1 year ago

I think the problem is in this line: https://gist.github.com/tvdijen/fc1016fbaa3aeac5a2bd50dad2e73114#file-compiledtwigtemplate-php-L69

The trans function contains a expression instead a string with the id string of the text.

btw, there's a twig scanner (https://github.com/php-gettext/Twig-Scanner) but it's not stable enough so maybe it doesn't work either.

tvdijen commented 1 year ago

Thanks @oscarotero ! I did find the twig-scanner, but the warning in the readme, and the lack of a stable release held me from trying it. I also understand from the open issues that it lacks support for Twig filters, and it lacks PHP 8 support. I was hoping I could work around that by compiling the templates, but I guess it's not gonna work.