diff --git a/src/Visitor/Php/BasePHPVisitor.php b/src/Visitor/Php/BasePHPVisitor.php index fa2d5d7..cef48fd 100644 --- a/src/Visitor/Php/BasePHPVisitor.php +++ b/src/Visitor/Php/BasePHPVisitor.php @@ -27,15 +27,34 @@ protected function getStringArgument(Node\Expr\MethodCall $node, int $index): ?s return null; } - if (!$node->args[$index]->value instanceof Node\Scalar\String_) { - return null; - } - - $label = $node->args[$index]->value->value; + $label = $this->getStringValue($node->args[$index]->value); if (empty($label)) { return null; } return $label; } + + private function getStringValue(Node $node): ?string + { + if ($node instanceof Node\Scalar\String_) { + return $node->value; + } + + if ($node instanceof Node\Expr\BinaryOp\Concat) { + $left = $this->getStringValue($node->left); + if (null === $left) { + return null; + } + + $right = $this->getStringValue($node->right); + if (null === $right) { + return null; + } + + return $left.$right; + } + + return null; + } } diff --git a/tests/Resources/Github/Issue_125.php b/tests/Resources/Github/Issue_125.php new file mode 100644 index 0000000..2d5a6b3 --- /dev/null +++ b/tests/Resources/Github/Issue_125.php @@ -0,0 +1,17 @@ +trans( + 'github.'. + 'issue_125.'. + 'a' + ); + } +} diff --git a/tests/Smoke/AllExtractorsTest.php b/tests/Smoke/AllExtractorsTest.php index 7e251b9..452fb76 100644 --- a/tests/Smoke/AllExtractorsTest.php +++ b/tests/Smoke/AllExtractorsTest.php @@ -88,6 +88,8 @@ public function testNoException() $this->translationMissing($sc, 'github.issue_111.c'); $this->translationExists($sc, 'github.issue_111.d'); + $this->translationExists($sc, 'github.issue_125.a'); + /* * It is okey to increase the error count if you adding more fixtures/code. * We just need to be aware that it changes.