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

PHP Brackets in function parameter #229

Open
kdabek opened this issue Oct 10, 2019 · 3 comments
Open

PHP Brackets in function parameter #229

kdabek opened this issue Oct 10, 2019 · 3 comments

Comments

@kdabek
Copy link

kdabek commented Oct 10, 2019

If you use brackets in function parameter PHPFunctionsScanner will interpret this as a new function and the resulting parameter list is incorrect.

Example:

<?php

require_once 'vendor/autoload.php';

$quantity = 10;
$default = 5;

$string = <<<EOD
<?php
sprintf(_n("%d Comment", "%d Comments", ($quantity ?? $default), "domain"), ($quantity ?? $default));
EOD;

$scanner = new \Gettext\Utils\PhpFunctionsScanner($string);
$output = $scanner->getFunctions();

and output:

array(2) {
  [0]=>
  array(4) {
    [0]=>
    string(2) "_n"
    [1]=>
    int(2)
    [2]=>
    array(3) {
      [0]=>
      string(10) "%d Comment"
      [1]=>
      string(11) "%d Comments"
      [2]=>
      NULL
    }
    [3]=>
    NULL
  }
  [1]=>
  array(4) {
    [0]=>
    string(7) "sprintf"
    [1]=>
    int(2)
    [2]=>
    array(2) {
      [0]=>
      NULL
      [1]=>
      string(6) "domain"
    }
    [3]=>
    NULL
  }
}

as you can see "domain" is associated with sprintf function which is not true.

@oscarotero
Copy link
Member

I recommend to update to gettext/gettext v5, that use nikic/PHP-Parser to scan php code and its much more reliable.

@swissspidy
Copy link
Contributor

Would you accept PRs against v4 to fix this?

@oscarotero
Copy link
Member

Yes, sure.

NielsdeBlaauw added a commit to level-level/clarkson-wp-cli-twig-translations that referenced this issue Nov 14, 2023
This fixes an issue where gettext can not correctly find plural strings.

See php-gettext/Gettext#229
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