mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
Merge pull request #4937 from rubencm/ticket/15330
[ticket/15330] Twig function to know if a language string is defined
This commit is contained in:
commit
ad24ecae11
1 changed files with 13 additions and 2 deletions
|
@ -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 exists
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function lang_defined($key)
|
||||||
|
{
|
||||||
|
return call_user_func_array([$this->language, 'is_set'], [$key]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue