Skip to content

Commit

Permalink
Added new tl filter/function to translate language #1618
Browse files Browse the repository at this point in the history
This addresses issues with the PR.  It uses a new twig filter that gives full access to the langauges->translate() function.
  • Loading branch information
rhukster committed Aug 28, 2017
1 parent 3572833 commit 550b51f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions system/src/Grav/Common/Twig/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public function getFilters()
new \Twig_SimpleFilter('sort_by_key', [$this, 'sortByKeyFilter']),
new \Twig_SimpleFilter('starts_with', [$this, 'startsWithFilter']),
new \Twig_SimpleFilter('t', [$this, 'translate']),
new \Twig_SimpleFilter('tl', [$this, 'translateLanguage']),
new \Twig_SimpleFilter('ta', [$this, 'translateArray']),
new \Twig_SimpleFilter('truncate', ['\Grav\Common\Utils', 'truncate']),
new \Twig_SimpleFilter('truncate_html', ['\Grav\Common\Utils', 'truncateHTML']),
Expand Down Expand Up @@ -127,6 +128,7 @@ public function getFunctions()
new \Twig_SimpleFunction('regex_replace', [$this, 'regexReplace']),
new \Twig_SimpleFunction('string', [$this, 'stringFunc']),
new \Twig_simpleFunction('t', [$this, 'translate']),
new \Twig_simpleFunction('tl', [$this, 'translateLanguage']),
new \Twig_simpleFunction('ta', [$this, 'translateArray']),
new \Twig_SimpleFunction('url', [$this, 'urlFunc']),
new \Twig_SimpleFunction('json_decode', [$this, 'jsonDecodeFilter']),
Expand Down Expand Up @@ -610,6 +612,20 @@ public function translate()
return $this->grav['language']->translate(func_get_args());
}

/**
* Translate Strings
*
* @param $args
* @param array|null $languages
* @param bool $array_support
* @param bool $html_out
* @return mixed
*/
public function translateLanguage($args, array $languages = null, $array_support = false, $html_out = false)
{
return $this->grav['language']->translate($args, $languages, $array_support, $html_out);
}

/**
* @param $key
* @param $index
Expand Down

0 comments on commit 550b51f

Please sign in to comment.