Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Extract the trans function in separate method #193

Closed
wants to merge 5 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/Twig/Extensions/Node/Trans.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function compile(Twig_Compiler $compiler)
$vars = array_merge($vars, $vars1);
}

$function = !$this->hasNode('plural') ? 'gettext' : 'ngettext';
$function = $this->getTransFunction($this->hasNode('plural'));

if ($this->hasNode('notes')) {
$message = trim($this->getNode('notes')->getAttribute('data'));
Expand Down Expand Up @@ -151,4 +151,14 @@ protected function compileString(Twig_Node $body)

return array(new Twig_Node(array(new Twig_Node_Expression_Constant(trim($msg), $body->getLine()))), $vars);
}

/**
* @param bool $plural Return plural or singular function to use
*
* @return string
*/
protected function getTransFunction($plural = false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about removing the default value?

{
return !$plural ? 'gettext' : 'ngettext';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe remove the ! and flip the results, save an OP without draw back

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've kept it as it was in the previous version. Will update it now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's weird but the build fails with the reversed check.

}
}