Skip to content

Commit

Permalink
Merge branch '3.3.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
CHItA committed Sep 2, 2021
2 parents 860663d + 86af3a2 commit aa06580
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
8 changes: 4 additions & 4 deletions phpBB/adm/style/overall_header.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

<script>
// <![CDATA[
var jump_page = '{LA_JUMP_PAGE}{L_COLON}';
var on_page = '{CURRENT_PAGE}';
var per_page = '{PER_PAGE}';
var base_url = '{BASE_URL|e('js')}';
var jump_page = "{{ lang_js('JUMP_PAGE') ~ lang_js('COLON') }}";
var on_page = '{{ CURRENT_PAGE }}';
var per_page = '{{ PER_PAGE }}';
var base_url = "{{ BASE_URL|e('js') }}";

/**
* Jump to page
Expand Down
15 changes: 15 additions & 0 deletions phpBB/phpbb/template/twig/extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace phpbb\template\twig;

use Twig\Error\RuntimeError;

class extension extends \Twig\Extension\AbstractExtension
{
/** @var \phpbb\template\context */
Expand Down Expand Up @@ -90,6 +92,7 @@ public function getFunctions()
return array(
new \Twig\TwigFunction('lang', array($this, 'lang')),
new \Twig\TwigFunction('lang_defined', array($this, 'lang_defined')),
new \Twig\TwigFunction('lang_js', [$this, 'lang_js']),
new \Twig\TwigFunction('get_class', 'get_class'),
);
}
Expand Down Expand Up @@ -198,4 +201,16 @@ public function lang_defined($key)
{
return call_user_func_array([$this->language, 'is_set'], [$key]);
}

/**
* Get output for language variable in JS code
*
* @throws RuntimeError When data passed to twig_escape_filter is not a UTF8 string
*/
public function lang_js(): string
{
$args = func_get_args();

return twig_escape_filter($this->environment, call_user_func_array([$this, 'lang'], $args), 'js');
}
}
15 changes: 15 additions & 0 deletions tests/template/template_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,21 @@ public function template_data()
"Value'\n1 O'Clock\nValue\\u0027\n1\\u0020O\\u0027Clock",
array('VARIABLE' => "Value'", '1_VARIABLE' => "1 O'Clock"),
),
array(
'lang_twig.html',
array(),
array(),
array(),
"VARIABLE\n1_VARIABLE\nVARIABLE\n1_VARIABLE",
),
array(
'lang_twig.html',
array(),
array(),
array(),
"Value'\n1 O'Clock\nValue\\u0027\n1\\u0020O\\u0027Clock",
array('VARIABLE' => "Value'", '1_VARIABLE' => "1 O'Clock"),
),
array(
'loop_nested_multilevel_ref.html',
array(),
Expand Down
5 changes: 5 additions & 0 deletions tests/template/templates/lang_twig.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{ lang('VARIABLE') }}
{{ lang('1_VARIABLE') }}

{{ lang_js('VARIABLE') }}
{{ lang_js('1_VARIABLE') }}

0 comments on commit aa06580

Please sign in to comment.