[ticket/15330] Twig function to know if a language string is defined

PHPBB3-15330
This commit is contained in:
Rubén Calvo 2017-09-08 11:33:52 +02:00
parent b1fe0f9dbe
commit 21f3c53882

View file

@ -85,6 +85,7 @@ class extension extends \Twig_Extension
{ {
return array( return array(
new \Twig_SimpleFunction('lang', array($this, 'lang')), new \Twig_SimpleFunction('lang', array($this, 'lang')),
new \Twig_SimpleFunction('lang_defined', array($this, 'lang_defined')),
); );
} }
@ -136,7 +137,7 @@ class extension extends \Twig_Extension
* *
* @return mixed The sliced variable * @return mixed The sliced variable
*/ */
function loop_subset(\Twig_Environment $env, $item, $start, $end = null, $preserveKeys = false) public function loop_subset(\Twig_Environment $env, $item, $start, $end = null, $preserveKeys = false)
{ {
// We do almost the same thing as Twig's slice (array_slice), except when $end is positive // We do almost the same thing as Twig's slice (array_slice), except when $end is positive
if ($end >= 1) if ($end >= 1)
@ -165,7 +166,7 @@ class extension extends \Twig_Extension
* *
* @return string * @return string
*/ */
function lang() public function lang()
{ {
$args = func_get_args(); $args = func_get_args();
$key = $args[0]; $key = $args[0];
@ -182,4 +183,14 @@ class extension extends \Twig_Extension
return call_user_func_array(array($this->language, 'lang'), $args); return call_user_func_array(array($this->language, 'lang'), $args);
} }
/**
* Check if a language variable exist
*
* @return bool
*/
public function lang_defined($key)
{
return call_user_func_array([$this->language, 'is_set'], [$key]);
}
} }