Update website

This commit is contained in:
Guilhem Lavaux 2025-03-24 09:27:39 +01:00
parent a0b0d3dae7
commit ae7ef6ad45
3151 changed files with 566766 additions and 48 deletions

View file

@ -0,0 +1,17 @@
# Change Log
## [Unreleased] -
## [3.0.0] - 2020-06-14
* Add a .gitattributes file
* Support Twig 3
* Remove extra field from composer.json
* Add support field in composer.json
* Require php >= 7.1
* Setup and apply phpmyadmin/coding-standard
* Apply changes for php 8.0 compatibility (https://github.com/twigphp/Twig/issues/3327)
## [2.0.0] - 2020-01-14
* First release of this library.

View file

@ -0,0 +1,20 @@
Copyright (c) 2010-2019 Fabien Potencier
Copyright (c) 2019 phpMyAdmin contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View file

@ -0,0 +1,44 @@
{
"name": "phpmyadmin/twig-i18n-extension",
"description": "Internationalization support for Twig via the gettext library",
"keywords": ["i18n","gettext"],
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "The phpMyAdmin Team",
"email": "developers@phpmyadmin.net",
"homepage": "https://www.phpmyadmin.net/team/"
}
],
"support": {
"issues": "https://github.com/phpmyadmin/twig-i18n-extension/issues",
"source": "https://github.com/phpmyadmin/twig-i18n-extension"
},
"require": {
"php": ">=7.1",
"twig/twig": "^1.42.3|^2.0|^3.0"
},
"require-dev": {
"phpmyadmin/coding-standard": "^2.0",
"phpunit/phpunit": "^7 || ^8 || ^9"
},
"scripts": {
"phpunit": "phpunit",
"phpcs": "phpcs",
"phpcbf": "phpcbf"
},
"autoload": {
"psr-4": { "PhpMyAdmin\\Twig\\Extensions\\": "src/" }
},
"autoload-dev": {
"psr-4": { "PhpMyAdmin\\Tests\\Twig\\Extensions\\": "test/" }
},
"config":{
"sort-packages": true
}
}

View file

@ -0,0 +1,45 @@
<?php
/*
* This file is part of Twig.
*
* (c) 2010-2019 Fabien Potencier
* (c) 2019 phpMyAdmin contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PhpMyAdmin\Twig\Extensions;
use PhpMyAdmin\Twig\Extensions\TokenParser\TransTokenParser;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
class I18nExtension extends AbstractExtension
{
/**
* {@inheritdoc}
*/
public function getTokenParsers()
{
return [new TransTokenParser()];
}
/**
* {@inheritdoc}
*/
public function getFilters()
{
return [
new TwigFilter('trans', 'gettext'),
];
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'i18n';
}
}

View file

@ -0,0 +1,168 @@
<?php
/*
* This file is part of Twig.
*
* (c) 2010-2019 Fabien Potencier
* (c) 2019 phpMyAdmin contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PhpMyAdmin\Twig\Extensions\Node;
use Twig\Compiler;
use Twig\Node\CheckToStringNode;
use Twig\Node\Expression\AbstractExpression;
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Expression\FilterExpression;
use Twig\Node\Expression\NameExpression;
use Twig\Node\Expression\TempNameExpression;
use Twig\Node\Node;
use Twig\Node\PrintNode;
use function array_merge;
use function count;
use function sprintf;
use function str_replace;
use function trim;
/**
* Represents a trans node.
*
* Author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class TransNode extends Node
{
public function __construct(Node $body, ?Node $plural, ?AbstractExpression $count, ?Node $notes, int $lineno = 0, ?string $tag = null)
{
$nodes = ['body' => $body];
if ($count !== null) {
$nodes['count'] = $count;
}
if ($plural !== null) {
$nodes['plural'] = $plural;
}
if ($notes !== null) {
$nodes['notes'] = $notes;
}
parent::__construct($nodes, [], $lineno, $tag);
}
/**
* {@inheritdoc}
*/
public function compile(Compiler $compiler)
{
$compiler->addDebugInfo($this);
[$msg, $vars] = $this->compileString($this->getNode('body'));
if ($this->hasNode('plural')) {
[$msg1, $vars1] = $this->compileString($this->getNode('plural'));
$vars = array_merge($vars, $vars1);
}
$function = $this->getTransFunction($this->hasNode('plural'));
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('// notes: ' . $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 . '(')
->subcompile($msg);
if ($this->hasNode('plural')) {
$compiler
->raw(', ')
->subcompile($msg1)
->raw(', abs(')
->subcompile($this->hasNode('count') ? $this->getNode('count') : null)
->raw(')');
}
$compiler->raw(");\n");
}
}
/**
* Keep this method protected instead of private
* Twig/I18n/NodeTrans from phpmyadmin/phpmyadmin uses it
*/
protected function compileString(Node $body): array
{
if ($body instanceof NameExpression || $body instanceof ConstantExpression || $body instanceof TempNameExpression) {
return [$body, []];
}
$vars = [];
if (count($body)) {
$msg = '';
foreach ($body as $node) {
if ($node instanceof PrintNode) {
$n = $node->getNode('expr');
while ($n instanceof FilterExpression) {
$n = $n->getNode('node');
}
while ($n instanceof CheckToStringNode) {
$n = $n->getNode('expr');
}
$msg .= sprintf('%%%s%%', $n->getAttribute('name'));
$vars[] = new NameExpression($n->getAttribute('name'), $n->getTemplateLine());
} else {
$msg .= $node->getAttribute('data');
}
}
} else {
$msg = $body->getAttribute('data');
}
return [new Node([new ConstantExpression(trim($msg), $body->getTemplateLine())]), $vars];
}
private function getTransFunction(bool $plural): string
{
return $plural ? 'ngettext' : 'gettext';
}
}

View file

@ -0,0 +1,108 @@
<?php
/*
* This file is part of Twig.
*
* (c) 2010-2019 Fabien Potencier
* (c) 2019 phpMyAdmin contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PhpMyAdmin\Twig\Extensions\TokenParser;
use PhpMyAdmin\Twig\Extensions\Node\TransNode;
use Twig\Error\SyntaxError;
use Twig\Node\Expression\NameExpression;
use Twig\Node\Node;
use Twig\Node\PrintNode;
use Twig\Node\TextNode;
use Twig\Token;
use Twig\TokenParser\AbstractTokenParser;
use function sprintf;
class TransTokenParser extends AbstractTokenParser
{
/**
* {@inheritdoc}
*/
public function parse(Token $token)
{
$lineno = $token->getLine();
$stream = $this->parser->getStream();
$count = null;
$plural = null;
$notes = 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 === '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 TransNode($body, $plural, $count, $notes, $lineno, $this->getTag());
}
/**
* @return bool
*/
public function decideForFork(Token $token)
{
return $token->test(['plural', 'notes', 'endtrans']);
}
/**
* @return bool
*/
public function decideForEnd(Token $token)
{
return $token->test('endtrans');
}
/**
* {@inheritdoc}
*/
public function getTag()
{
return 'trans';
}
/**
* @return void
*
* @throws SyntaxError
*/
protected function checkTransString(Node $body, $lineno)
{
foreach ($body as $i => $node) {
if ($node instanceof TextNode
||
($node instanceof PrintNode && $node->getNode('expr') instanceof NameExpression)
) {
continue;
}
throw new SyntaxError(sprintf('The text to be translated with "trans" can only contain references to simple variables'), $lineno);
}
}
}