Skip to content

Commit

Permalink
Merge pull request #12 from JBlond/twig-trans-11
Browse files Browse the repository at this point in the history
Twig trans 11
  • Loading branch information
JBlond authored Feb 23, 2025
2 parents 2209ec3 + 0f9973d commit 3883295
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ echo $tpl->render(['key1' => 'value1', 'key2' => 'value2']);
## Requirements

* PHP 7.2 or greater
* PHP Multibyte String ' gettext'
* PHP Multibyte String
* 'gettext'
* Twig >= 3.0

### Optional Requirements
Expand Down
14 changes: 7 additions & 7 deletions src/jblond/TwigTrans/TransNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace jblond\TwigTrans;

use Twig\Attribute\YieldReady;
use Twig\Compiler;
use Twig\Node\Expression\AbstractExpression;
use Twig\Node\Expression\ConstantExpression;
Expand All @@ -15,6 +16,7 @@
* Class TransNode
* @package jblond\TwigTrans
*/
#[YieldReady]
class TransNode extends Node
{
/**
Expand All @@ -24,15 +26,13 @@ class TransNode extends Node
* @param AbstractExpression|null $count
* @param Node|null $notes
* @param int $lineNo
* @param string|null $tag
*/
public function __construct(
Node $body,
Node $plural = null,
AbstractExpression $count = null,
Node $notes = null,
int $lineNo = 0,
?string $tag = null
?Node $plural = null,
?AbstractExpression $count = null,
?Node $notes = null,
int $lineNo = 0
) {
$nodes = ['body' => $body];
if (null !== $count) {
Expand All @@ -45,7 +45,7 @@ public function __construct(
$nodes['notes'] = $notes;
}

parent::__construct($nodes, [], $lineNo, $tag);
parent::__construct($nodes, [], $lineNo);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions tests/TwigTrans/Node/TransTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getTests(): array

$body = new NameExpression('foo', 0);
$node = new TransNode($body, null, null, null, 0);
$tests[] = [$node, sprintf('echo gettext(%s);', $this->getVariableGetter('foo'))];
$tests[] = [$node, sprintf('echo gettext(%s);', NodeTestCase::createVariableGetter('foo'))];

$body = new ConstantExpression('Hello', 0);
$node = new TransNode($body, null, null, null, 0);
Expand All @@ -74,7 +74,7 @@ public function getTests(): array
$node,
sprintf(
'echo strtr(gettext("J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));',
$this->getVariableGetter('foo')
NodeTestCase::createVariableGetter('foo')
)
];

Expand All @@ -97,8 +97,8 @@ public function getTests(): array
sprintf(
'echo strtr(ngettext("Hey %%name%%, I have one apple", "Hey %%name%%, I have %%count%% apples", ' .
'abs(12)), array("%%name%%" => %s, "%%name%%" => %s, "%%count%%" => abs(12), ));',
$this->getVariableGetter('name'),
$this->getVariableGetter('name')
NodeTestCase::createVariableGetter('name'),
NodeTestCase::createVariableGetter('name')
)
];

Expand All @@ -122,7 +122,7 @@ public function getTests(): array
$node,
sprintf(
'echo strtr(gettext("J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));',
$this->getVariableGetter('foo')
NodeTestCase::createVariableGetter('foo')
)
];

Expand Down

0 comments on commit 3883295

Please sign in to comment.