Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser Failing on Multi-Line Code #14

Closed
BusterNeece opened this issue Mar 17, 2022 · 4 comments
Closed

Parser Failing on Multi-Line Code #14

BusterNeece opened this issue Mar 17, 2022 · 4 comments

Comments

@BusterNeece
Copy link
Contributor

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 added a commit that referenced this issue Mar 18, 2022
@oscarotero
Copy link
Member

Fixed in v1.3.1.
Thanks!

@tvdijen
Copy link

tvdijen commented Jul 10, 2022

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
Copy link
Member

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
Copy link

tvdijen commented Jul 11, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants