Skip to content

Commit

Permalink
Adding translation filter. Closes thecodingmachine#2, See thecodingma…
Browse files Browse the repository at this point in the history
  • Loading branch information
moufmouf committed Oct 7, 2015
1 parent 7fc6307 commit 68a4fbb
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Mouf/Html/Renderer/Twig/MoufTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ public function getFunctions()
);
}

/**
* Returns a list of filters to add to the existing list.
*
* @return array An array of filters
*/
public function getFilters()
{
return array(
new \Twig_SimpleFilter('t', [$this, 'translateFilter'], array('is_variadic' => true)),
);
}

public function toHtml($param)
{
if ($param == null) {
Expand Down Expand Up @@ -116,6 +128,12 @@ public function translate(array $args = array())
return call_user_func_array('iMsgNoEdit', $args);
}

public function translateFilter($text, array $args = array())
{
array_unshift($args, $text);
return call_user_func_array('iMsgNoEdit', $args);
}

public function createRelativeLink($param)
{
return ROOT_URL.$param;
Expand Down

0 comments on commit 68a4fbb

Please sign in to comment.