mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
Merge pull request #6275 from marc1706/ticket/16856
[ticket/16856] Add lang_js twig function as replacement for LA_
This commit is contained in:
commit
86af3a2ba4
4 changed files with 39 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
|
||||
namespace phpbb\template\twig;
|
||||
|
||||
use Twig\Error\RuntimeError;
|
||||
|
||||
class extension extends \Twig\Extension\AbstractExtension
|
||||
{
|
||||
/** @var \phpbb\template\context */
|
||||
|
@ -90,6 +92,7 @@ class extension extends \Twig\Extension\AbstractExtension
|
|||
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'),
|
||||
);
|
||||
}
|
||||
|
@ -198,4 +201,16 @@ class extension extends \Twig\Extension\AbstractExtension
|
|||
{
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -367,6 +367,21 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
|
|||
"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(),
|
||||
|
|
5
tests/template/templates/lang_twig.html
Normal file
5
tests/template/templates/lang_twig.html
Normal file
|
@ -0,0 +1,5 @@
|
|||
{{ lang('VARIABLE') }}
|
||||
{{ lang('1_VARIABLE') }}
|
||||
|
||||
{{ lang_js('VARIABLE') }}
|
||||
{{ lang_js('1_VARIABLE') }}
|
Loading…
Add table
Reference in a new issue