Skip to content

Commit

Permalink
Fix: Change output to yield
Browse files Browse the repository at this point in the history
  • Loading branch information
JBlond committed Feb 23, 2025
1 parent 3883295 commit ba1ec2c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/jblond/TwigTrans/TransNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function compile(Compiler $compiler): void

if ($vars) {
$compiler
->write('echo strtr(' . $function . '(')
->write('yield strtr(' . $function . '(')
->subcompile($msg)
;

Expand Down Expand Up @@ -113,7 +113,7 @@ public function compile(Compiler $compiler): void
$compiler->raw("));\n");
} else {
$compiler
->write('echo ' . $function . '(')
->write('yield ' . $function . '(')
->subcompile($msg)
;

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

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

$body = new ConstantExpression('Hello', 0);
$node = new TransNode($body, null, null, null, 0);
$tests[] = [$node, 'echo gettext("Hello");'];
$tests[] = [$node, 'yield gettext("Hello");'];

$body = new Node([
new TextNode('Hello', 0),
], [], 0);
$node = new TransNode($body, null, null, null, 0);
$tests[] = [$node, 'echo gettext("Hello");'];
$tests[] = [$node, 'yield gettext("Hello");'];

$body = new Node([
new TextNode('J\'ai ', 0),
Expand All @@ -73,7 +73,7 @@ public function getTests(): array
$tests[] = [
$node,
sprintf(
'echo strtr(gettext("J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));',
'yield strtr(gettext("J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));',
NodeTestCase::createVariableGetter('foo')
)
];
Expand All @@ -95,7 +95,7 @@ public function getTests(): array
$tests[] = [
$node,
sprintf(
'echo strtr(ngettext("Hey %%name%%, I have one apple", "Hey %%name%%, I have %%count%% apples", ' .
'yield strtr(ngettext("Hey %%name%%, I have one apple", "Hey %%name%%, I have %%count%% apples", ' .
'abs(12)), array("%%name%%" => %s, "%%name%%" => %s, "%%count%%" => abs(12), ));',
NodeTestCase::createVariableGetter('name'),
NodeTestCase::createVariableGetter('name')
Expand All @@ -121,7 +121,7 @@ public function getTests(): array
$tests[] = [
$node,
sprintf(
'echo strtr(gettext("J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));',
'yield strtr(gettext("J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));',
NodeTestCase::createVariableGetter('foo')
)
];
Expand All @@ -130,12 +130,12 @@ public function getTests(): array
$body = new ConstantExpression('Hello', 0);
$notes = new TextNode('Notes for translators', 0);
$node = new TransNode($body, null, null, $notes, 0);
$tests[] = [$node, "// notes: Notes for translators\necho gettext(\"Hello\");"];
$tests[] = [$node, "// notes: Notes for translators\nyield gettext(\"Hello\");"];

$body = new ConstantExpression('Hello', 0);
$notes = new TextNode("Notes for translators\nand line breaks", 0);
$node = new TransNode($body, null, null, $notes, 0);
$tests[] = [$node, "// notes: Notes for translators and line breaks\necho gettext(\"Hello\");"];
$tests[] = [$node, "// notes: Notes for translators and line breaks\nyield gettext(\"Hello\");"];

$count = new ConstantExpression(5, 0);
$body = new TextNode('There is 1 pending task', 0);
Expand All @@ -149,7 +149,7 @@ public function getTests(): array
$tests[] = [
$node,
"// notes: Notes for translators\n" .
'echo strtr(ngettext("There is 1 pending task", "There are %count% pending tasks", abs(5)),' .
'yield strtr(ngettext("There is 1 pending task", "There are %count% pending tasks", abs(5)),' .
' array("%count%" => abs(5), ));'
];

Expand Down

0 comments on commit ba1ec2c

Please sign in to comment.