Merge #16675 - Upgrade to Motranslator 4
Pull-request: #16675 Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
commit
44c2f0cd5b
@ -50,7 +50,7 @@
|
|||||||
"phpmyadmin/motranslator": "^5.0",
|
"phpmyadmin/motranslator": "^5.0",
|
||||||
"phpmyadmin/shapefile": "^3.0.1",
|
"phpmyadmin/shapefile": "^3.0.1",
|
||||||
"phpmyadmin/sql-parser": "^5.0",
|
"phpmyadmin/sql-parser": "^5.0",
|
||||||
"phpmyadmin/twig-i18n-extension": "^3.0",
|
"phpmyadmin/twig-i18n-extension": "^4.0",
|
||||||
"phpseclib/phpseclib": "^3.0",
|
"phpseclib/phpseclib": "^3.0",
|
||||||
"symfony/config": "^5.2.3",
|
"symfony/config": "^5.2.3",
|
||||||
"symfony/dependency-injection": "^5.2.3",
|
"symfony/dependency-injection": "^5.2.3",
|
||||||
|
|||||||
@ -10,6 +10,7 @@ use PhpMyAdmin\Routing;
|
|||||||
use PhpMyAdmin\Tests\Stubs\DbiDummy;
|
use PhpMyAdmin\Tests\Stubs\DbiDummy;
|
||||||
use PhpMyAdmin\Twig\AssetExtension;
|
use PhpMyAdmin\Twig\AssetExtension;
|
||||||
use PhpMyAdmin\Twig\CoreExtension;
|
use PhpMyAdmin\Twig\CoreExtension;
|
||||||
|
use PhpMyAdmin\Twig\Extensions\Node\TransNode;
|
||||||
use PhpMyAdmin\Twig\I18nExtension;
|
use PhpMyAdmin\Twig\I18nExtension;
|
||||||
use PhpMyAdmin\Twig\MessageExtension;
|
use PhpMyAdmin\Twig\MessageExtension;
|
||||||
use PhpMyAdmin\Twig\PluginsExtension;
|
use PhpMyAdmin\Twig\PluginsExtension;
|
||||||
@ -122,6 +123,10 @@ final class CacheWarmupCommand extends Command
|
|||||||
'auto_reload' => true,
|
'auto_reload' => true,
|
||||||
'cache' => $tmpDir,
|
'cache' => $tmpDir,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// Add this to know at what line the code was for getDebugInfo to work
|
||||||
|
TransNode::$enableAddDebugInfo = true;
|
||||||
|
|
||||||
$twig->setExtensions([
|
$twig->setExtensions([
|
||||||
new AssetExtension(),
|
new AssetExtension(),
|
||||||
new CoreExtension(),
|
new CoreExtension(),
|
||||||
|
|||||||
@ -1,156 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace PhpMyAdmin\Twig\I18n;
|
|
||||||
|
|
||||||
use PhpMyAdmin\Twig\Extensions\Node\TransNode;
|
|
||||||
use Twig\Compiler;
|
|
||||||
use Twig\Node\Expression\AbstractExpression;
|
|
||||||
use Twig\Node\Node;
|
|
||||||
use function array_merge;
|
|
||||||
use function str_replace;
|
|
||||||
use function trim;
|
|
||||||
|
|
||||||
class NodeTrans extends TransNode
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* 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|null $plural Node plural
|
|
||||||
* @param AbstractExpression $count Node count
|
|
||||||
* @param Node|null $context Node context
|
|
||||||
* @param Node|null $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,
|
|
||||||
?AbstractExpression $count,
|
|
||||||
?Node $context,
|
|
||||||
?Node $notes,
|
|
||||||
int $lineno,
|
|
||||||
string $tag
|
|
||||||
) {
|
|
||||||
$nodes = ['body' => $body];
|
|
||||||
if ($count !== null) {
|
|
||||||
$nodes['count'] = $count;
|
|
||||||
}
|
|
||||||
if ($plural !== null) {
|
|
||||||
$nodes['plural'] = $plural;
|
|
||||||
}
|
|
||||||
if ($context !== null) {
|
|
||||||
$nodes['context'] = $context;
|
|
||||||
}
|
|
||||||
if ($notes !== null) {
|
|
||||||
$nodes['notes'] = $notes;
|
|
||||||
}
|
|
||||||
|
|
||||||
Node::__construct($nodes, [], $lineno, $tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compiles the node to PHP.
|
|
||||||
*
|
|
||||||
* @param Compiler $compiler Node compiler
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function compile(Compiler $compiler)
|
|
||||||
{
|
|
||||||
$compiler->addDebugInfo($this);
|
|
||||||
|
|
||||||
[$msg, $vars] = $this->compileString($this->getNode('body'));
|
|
||||||
|
|
||||||
$msg1 = null;
|
|
||||||
if ($this->hasNode('plural')) {
|
|
||||||
[$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(["\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 ($var->getAttribute('name') === 'count') {
|
|
||||||
$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?
|
|
||||||
*/
|
|
||||||
protected function getTransFunction($plural, bool $hasMsgContext = false): string
|
|
||||||
{
|
|
||||||
if ($hasMsgContext) {
|
|
||||||
return $plural ? '_ngettext' : '_pgettext';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $plural ? '_ngettext' : '_gettext';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,74 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace PhpMyAdmin\Twig\I18n;
|
|
||||||
|
|
||||||
use PhpMyAdmin\Twig\Extensions\TokenParser\TransTokenParser;
|
|
||||||
use Twig\Error\SyntaxError;
|
|
||||||
use Twig\Token;
|
|
||||||
|
|
||||||
class TokenParserTrans extends TransTokenParser
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Parses a token and returns a node.
|
|
||||||
*
|
|
||||||
* @param Token $token Twig token to parse
|
|
||||||
*
|
|
||||||
* @return NodeTrans
|
|
||||||
*
|
|
||||||
* @throws 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([$this, 'decideForFork']);
|
|
||||||
$next = $stream->next()->getValue();
|
|
||||||
|
|
||||||
if ($next === 'plural') {
|
|
||||||
$count = $this->parser->getExpressionParser()->parseExpression();
|
|
||||||
$stream->expect(Token::BLOCK_END_TYPE);
|
|
||||||
$plural = $this->parser->subparse([$this, 'decideForFork']);
|
|
||||||
|
|
||||||
if ($stream->next()->getValue() === 'notes') {
|
|
||||||
$stream->expect(Token::BLOCK_END_TYPE);
|
|
||||||
$notes = $this->parser->subparse([$this, 'decideForEnd'], true);
|
|
||||||
}
|
|
||||||
} elseif ($next === 'context') {
|
|
||||||
$stream->expect(Token::BLOCK_END_TYPE);
|
|
||||||
$context = $this->parser->subparse([$this, 'decideForEnd'], true);
|
|
||||||
} elseif ($next === 'notes') {
|
|
||||||
$stream->expect(Token::BLOCK_END_TYPE);
|
|
||||||
$notes = $this->parser->subparse([$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(['plural', 'context', 'notes', 'endtrans']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -5,20 +5,15 @@ declare(strict_types=1);
|
|||||||
namespace PhpMyAdmin\Twig;
|
namespace PhpMyAdmin\Twig;
|
||||||
|
|
||||||
use PhpMyAdmin\Twig\Extensions\I18nExtension as TwigI18nExtension;
|
use PhpMyAdmin\Twig\Extensions\I18nExtension as TwigI18nExtension;
|
||||||
use PhpMyAdmin\Twig\I18n\TokenParserTrans;
|
use PhpMyAdmin\Twig\Extensions\Node\TransNode;
|
||||||
use Twig\TokenParser\TokenParserInterface;
|
|
||||||
use Twig\TwigFilter;
|
use Twig\TwigFilter;
|
||||||
|
|
||||||
class I18nExtension extends TwigI18nExtension
|
class I18nExtension extends TwigI18nExtension
|
||||||
{
|
{
|
||||||
/**
|
public function __construct()
|
||||||
* Returns the token parser instances to add to the existing list.
|
|
||||||
*
|
|
||||||
* @return TokenParserInterface[]
|
|
||||||
*/
|
|
||||||
public function getTokenParsers()
|
|
||||||
{
|
{
|
||||||
return [new TokenParserTrans()];
|
TransNode::$notesLabel = '// l10n: ';
|
||||||
|
TransNode::$enableMoTranslator = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,6 +24,7 @@ class I18nExtension extends TwigI18nExtension
|
|||||||
public function getFilters()
|
public function getFilters()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
// This is just a performance override
|
||||||
new TwigFilter('trans', '_gettext'),
|
new TwigFilter('trans', '_gettext'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2200,11 +2200,6 @@ parameters:
|
|||||||
count: 2
|
count: 2
|
||||||
path: libraries/classes/Transformations.php
|
path: libraries/classes/Transformations.php
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Parameter \\#1 \\$node of method Twig\\\\Compiler\\:\\:subcompile\\(\\) expects Twig\\\\Node\\\\Node, Twig\\\\Node\\\\Node\\|null given\\.$#"
|
|
||||||
count: 3
|
|
||||||
path: libraries/classes/Twig/I18n/NodeTrans.php
|
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Parameter \\#1 \\$stack of function array_push expects array, array\\<int, string\\>\\|string given\\.$#"
|
message: "#^Parameter \\#1 \\$stack of function array_push expects array, array\\<int, string\\>\\|string given\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
|
|||||||
@ -2602,15 +2602,6 @@
|
|||||||
<code>$row['comment']</code>
|
<code>$row['comment']</code>
|
||||||
</PossiblyNullArrayAccess>
|
</PossiblyNullArrayAccess>
|
||||||
</file>
|
</file>
|
||||||
<file src="libraries/classes/Twig/I18n/NodeTrans.php">
|
|
||||||
<PossiblyNullArgument occurrences="5">
|
|
||||||
<code>$msg1</code>
|
|
||||||
<code>$msg1</code>
|
|
||||||
<code>$this->hasNode('count') ? $this->getNode('count') : null</code>
|
|
||||||
<code>$this->hasNode('count') ? $this->getNode('count') : null</code>
|
|
||||||
<code>$this->hasNode('count') ? $this->getNode('count') : null</code>
|
|
||||||
</PossiblyNullArgument>
|
|
||||||
</file>
|
|
||||||
<file src="libraries/classes/TwoFactor.php">
|
<file src="libraries/classes/TwoFactor.php">
|
||||||
<InvalidPropertyFetch occurrences="1">
|
<InvalidPropertyFetch occurrences="1">
|
||||||
<code>$cls::$id</code>
|
<code>$cls::$id</code>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user