init web ems all
This commit is contained in:
169
phpMyAdmin/libraries/classes/Twig/I18n/NodeTrans.php
Executable file
169
phpMyAdmin/libraries/classes/Twig/I18n/NodeTrans.php
Executable file
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* hold PhpMyAdmin\Twig\I18n\NodeTrans class
|
||||
*
|
||||
* @package PhpMyAdmin\Twig\I18n
|
||||
*/
|
||||
namespace PhpMyAdmin\Twig\I18n;
|
||||
|
||||
use Twig\Compiler;
|
||||
use Twig\Extensions\Node\TransNode;
|
||||
use Twig\Node\Node;
|
||||
use Twig\Node\Expression\AbstractExpression;
|
||||
|
||||
/**
|
||||
* Class NodeTrans
|
||||
*
|
||||
* @package PhpMyAdmin\Twig\I18n
|
||||
*/
|
||||
class NodeTrans extends TransNode
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* The nodes are automatically made available as properties ($this->node).
|
||||
* The attributes are automatically made available as array items ($this['name']).
|
||||
*
|
||||
* @param Node $body Body of node trans
|
||||
* @param Node $plural Node plural
|
||||
* @param AbstractExpression $count Node count
|
||||
* @param Node $context Node context
|
||||
* @param Node $notes Node notes
|
||||
* @param int $lineno The line number
|
||||
* @param string $tag The tag name associated with the Node
|
||||
*/
|
||||
public function __construct(
|
||||
Node $body,
|
||||
Node $plural = null,
|
||||
AbstractExpression $count = null,
|
||||
Node $context = null,
|
||||
Node $notes = null,
|
||||
$lineno,
|
||||
$tag = null
|
||||
) {
|
||||
$nodes = array('body' => $body);
|
||||
if (null !== $count) {
|
||||
$nodes['count'] = $count;
|
||||
}
|
||||
if (null !== $plural) {
|
||||
$nodes['plural'] = $plural;
|
||||
}
|
||||
if (null !== $context) {
|
||||
$nodes['context'] = $context;
|
||||
}
|
||||
if (null !== $notes) {
|
||||
$nodes['notes'] = $notes;
|
||||
}
|
||||
|
||||
Node::__construct($nodes, array(), $lineno, $tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles the node to PHP.
|
||||
*
|
||||
* @param Compiler $compiler Node compiler
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function compile(Compiler $compiler)
|
||||
{
|
||||
$compiler->addDebugInfo($this);
|
||||
|
||||
list($msg, $vars) = $this->compileString($this->getNode('body'));
|
||||
|
||||
if ($this->hasNode('plural')) {
|
||||
list($msg1, $vars1) = $this->compileString($this->getNode('plural'));
|
||||
|
||||
$vars = array_merge($vars, $vars1);
|
||||
}
|
||||
|
||||
$function = $this->getTransFunction(
|
||||
$this->hasNode('plural'),
|
||||
$this->hasNode('context')
|
||||
);
|
||||
|
||||
if ($this->hasNode('notes')) {
|
||||
$message = trim($this->getNode('notes')->getAttribute('data'));
|
||||
|
||||
// line breaks are not allowed cause we want a single line comment
|
||||
$message = str_replace(array("\n", "\r"), ' ', $message);
|
||||
$compiler->write("// l10n: {$message}\n");
|
||||
}
|
||||
|
||||
if ($vars) {
|
||||
$compiler
|
||||
->write('echo strtr(' . $function . '(')
|
||||
->subcompile($msg)
|
||||
;
|
||||
|
||||
if ($this->hasNode('plural')) {
|
||||
$compiler
|
||||
->raw(', ')
|
||||
->subcompile($msg1)
|
||||
->raw(', abs(')
|
||||
->subcompile($this->hasNode('count') ? $this->getNode('count') : null)
|
||||
->raw(')')
|
||||
;
|
||||
}
|
||||
|
||||
$compiler->raw('), array(');
|
||||
|
||||
foreach ($vars as $var) {
|
||||
if ('count' === $var->getAttribute('name')) {
|
||||
$compiler
|
||||
->string('%count%')
|
||||
->raw(' => abs(')
|
||||
->subcompile($this->hasNode('count') ? $this->getNode('count') : null)
|
||||
->raw('), ')
|
||||
;
|
||||
} else {
|
||||
$compiler
|
||||
->string('%' . $var->getAttribute('name') . '%')
|
||||
->raw(' => ')
|
||||
->subcompile($var)
|
||||
->raw(', ')
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
$compiler->raw("));\n");
|
||||
} else {
|
||||
$compiler->write('echo ' . $function . '(');
|
||||
|
||||
if ($this->hasNode('context')) {
|
||||
$context = trim($this->getNode('context')->getAttribute('data'));
|
||||
$compiler->write('"' . $context . '", ');
|
||||
}
|
||||
|
||||
$compiler->subcompile($msg);
|
||||
|
||||
if ($this->hasNode('plural')) {
|
||||
$compiler
|
||||
->raw(', ')
|
||||
->subcompile($msg1)
|
||||
->raw(', abs(')
|
||||
->subcompile($this->hasNode('count') ? $this->getNode('count') : null)
|
||||
->raw(')')
|
||||
;
|
||||
}
|
||||
|
||||
$compiler->raw(");\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $plural Return plural or singular function to use
|
||||
* @param bool $hasMsgContext It has message context?
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getTransFunction($plural, $hasMsgContext = false)
|
||||
{
|
||||
if ($hasMsgContext) {
|
||||
return $plural ? '_ngettext' : '_pgettext';
|
||||
}
|
||||
|
||||
return $plural ? '_ngettext' : '_gettext';
|
||||
}
|
||||
}
|
||||
81
phpMyAdmin/libraries/classes/Twig/I18n/TokenParserTrans.php
Executable file
81
phpMyAdmin/libraries/classes/Twig/I18n/TokenParserTrans.php
Executable file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* hold PhpMyAdmin\Twig\I18n\TokenParserTrans class
|
||||
*
|
||||
* @package PhpMyAdmin\Twig\I18n
|
||||
*/
|
||||
namespace PhpMyAdmin\Twig\I18n;
|
||||
|
||||
use Twig\Extensions\TokenParser\TransTokenParser;
|
||||
use Twig\Token;
|
||||
|
||||
/**
|
||||
* Class TokenParserTrans
|
||||
*
|
||||
* @package PhpMyAdmin\Twig\I18n
|
||||
*/
|
||||
class TokenParserTrans extends TransTokenParser
|
||||
{
|
||||
/**
|
||||
* Parses a token and returns a node.
|
||||
*
|
||||
* @param Token $token Twig token to parse
|
||||
*
|
||||
* @return Twig_NodeInterface
|
||||
*
|
||||
* @throws \Twig\Error\SyntaxError
|
||||
*/
|
||||
public function parse(Token $token)
|
||||
{
|
||||
$lineno = $token->getLine();
|
||||
$stream = $this->parser->getStream();
|
||||
$count = null;
|
||||
$plural = null;
|
||||
$notes = null;
|
||||
$context = null;
|
||||
|
||||
if (!$stream->test(Token::BLOCK_END_TYPE)) {
|
||||
$body = $this->parser->getExpressionParser()->parseExpression();
|
||||
} else {
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
$body = $this->parser->subparse(array($this, 'decideForFork'));
|
||||
$next = $stream->next()->getValue();
|
||||
|
||||
if ('plural' === $next) {
|
||||
$count = $this->parser->getExpressionParser()->parseExpression();
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
$plural = $this->parser->subparse(array($this, 'decideForFork'));
|
||||
|
||||
if ('notes' === $stream->next()->getValue()) {
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
$notes = $this->parser->subparse(array($this, 'decideForEnd'), true);
|
||||
}
|
||||
} elseif ('context' === $next) {
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
$context = $this->parser->subparse(array($this, 'decideForEnd'), true);
|
||||
} elseif ('notes' === $next) {
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
$notes = $this->parser->subparse(array($this, 'decideForEnd'), true);
|
||||
}
|
||||
}
|
||||
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
|
||||
$this->checkTransString($body, $lineno);
|
||||
|
||||
return new NodeTrans($body, $plural, $count, $context, $notes, $lineno, $this->getTag());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the current token for a type.
|
||||
*
|
||||
* @param Token $token Twig token to test
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function decideForFork(Token $token)
|
||||
{
|
||||
return $token->test(array('plural', 'context', 'notes', 'endtrans'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user