Upgrade 1-11.38

This commit is contained in:
xesmyd
2026-03-30 14:10:30 +02:00
parent f2a7e6d1fc
commit ac648ef29d
24665 changed files with 69682 additions and 2205004 deletions
@@ -24,6 +24,8 @@ use Symfony\Component\Translation\Extractor\ExtractorInterface;
class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
{
const MESSAGE_TOKEN = 300;
const METHOD_ARGUMENTS_TOKEN = 1000;
const DOMAIN_TOKEN = 1001;
/**
* Prefix for new found message.
@@ -38,6 +40,28 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
* @var array
*/
protected $sequences = array(
array(
'->',
'trans',
'(',
self::MESSAGE_TOKEN,
',',
self::METHOD_ARGUMENTS_TOKEN,
',',
self::DOMAIN_TOKEN,
),
array(
'->',
'transChoice',
'(',
self::MESSAGE_TOKEN,
',',
self::METHOD_ARGUMENTS_TOKEN,
',',
self::METHOD_ARGUMENTS_TOKEN,
',',
self::DOMAIN_TOKEN,
),
array(
'->',
'trans',
@@ -61,7 +85,7 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
foreach ($files as $file) {
$this->parseTokens(token_get_all(file_get_contents($file)), $catalog);
if (PHP_VERSION_ID >= 70000) {
if (\PHP_VERSION_ID >= 70000) {
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
gc_mem_caches();
}
@@ -105,11 +129,32 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
}
}
private function skipMethodArgument(\Iterator $tokenIterator)
{
$openBraces = 0;
for (; $tokenIterator->valid(); $tokenIterator->next()) {
$t = $tokenIterator->current();
if ('[' === $t[0] || '(' === $t[0]) {
++$openBraces;
}
if (']' === $t[0] || ')' === $t[0]) {
--$openBraces;
}
if ((0 === $openBraces && ',' === $t[0]) || (-1 === $openBraces && ')' === $t[0])) {
break;
}
}
}
/**
* Extracts the message from the iterator while the tokens
* match allowed message tokens.
*/
private function getMessage(\Iterator $tokenIterator)
private function getValue(\Iterator $tokenIterator)
{
$message = '';
$docToken = '';
@@ -155,16 +200,26 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
for ($key = 0; $key < $tokenIterator->count(); ++$key) {
foreach ($this->sequences as $sequence) {
$message = '';
$domain = 'messages';
$tokenIterator->seek($key);
foreach ($sequence as $item) {
foreach ($sequence as $sequenceKey => $item) {
$this->seekToNextRelevantToken($tokenIterator);
if ($this->normalizeToken($tokenIterator->current()) == $item) {
if ($this->normalizeToken($tokenIterator->current()) === $item) {
$tokenIterator->next();
continue;
} elseif (self::MESSAGE_TOKEN == $item) {
$message = $this->getMessage($tokenIterator);
} elseif (self::MESSAGE_TOKEN === $item) {
$message = $this->getValue($tokenIterator);
if (count($sequence) === ($sequenceKey + 1)) {
break;
}
} elseif (self::METHOD_ARGUMENTS_TOKEN === $item) {
$this->skipMethodArgument($tokenIterator);
} elseif (self::DOMAIN_TOKEN === $item) {
$domain = $this->getValue($tokenIterator);
break;
} else {
break;
@@ -172,7 +227,7 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
}
if ($message) {
$catalog->set($message, $this->prefix.$message);
$catalog->set($message, $this->prefix.$message, $domain);
break;
}
}
+25 -9
View File
@@ -15,6 +15,7 @@ use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
use Symfony\Component\Translation\Translator as BaseTranslator;
use Symfony\Component\Translation\MessageSelector;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Translation\Exception\InvalidArgumentException;
/**
* Translator.
@@ -37,6 +38,14 @@ class Translator extends BaseTranslator implements WarmableInterface
*/
private $resourceLocales;
/**
* Holds parameters from addResource() calls so we can defer the actual
* parent::addResource() calls until initialize() is executed.
*
* @var array
*/
private $resources = array();
/**
* Constructor.
*
@@ -51,7 +60,7 @@ class Translator extends BaseTranslator implements WarmableInterface
* @param array $loaderIds An array of loader Ids
* @param array $options An array of options
*
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
*/
public function __construct(ContainerInterface $container, MessageSelector $selector, $loaderIds = array(), array $options = array())
{
@@ -60,14 +69,12 @@ class Translator extends BaseTranslator implements WarmableInterface
// check option names
if ($diff = array_diff(array_keys($options), array_keys($this->options))) {
throw new \InvalidArgumentException(sprintf('The Translator does not support the following options: \'%s\'.', implode('\', \'', $diff)));
throw new InvalidArgumentException(sprintf('The Translator does not support the following options: \'%s\'.', implode('\', \'', $diff)));
}
$this->options = array_merge($this->options, $options);
$this->resourceLocales = array_keys($this->options['resource_files']);
if (null !== $this->options['cache_dir'] && $this->options['debug']) {
$this->loadResources();
}
$this->addResourceFiles($this->options['resource_files']);
parent::__construct($container->getParameter('kernel.default_locale'), $selector, $this->options['cache_dir'], $this->options['debug']);
}
@@ -93,6 +100,11 @@ class Translator extends BaseTranslator implements WarmableInterface
}
}
public function addResource($format, $resource, $locale, $domain = null)
{
$this->resources[] = array($format, $resource, $locale, $domain);
}
/**
* {@inheritdoc}
*/
@@ -104,7 +116,12 @@ class Translator extends BaseTranslator implements WarmableInterface
protected function initialize()
{
$this->loadResources();
foreach ($this->resources as $key => $params) {
list($format, $resource, $locale, $domain) = $params;
parent::addResource($format, $resource, $locale, $domain);
}
$this->resources = array();
foreach ($this->loaderIds as $id => $aliases) {
foreach ($aliases as $alias) {
$this->addLoader($alias, $this->container->get($id));
@@ -112,14 +129,13 @@ class Translator extends BaseTranslator implements WarmableInterface
}
}
private function loadResources()
private function addResourceFiles($filesByLocale)
{
foreach ($this->options['resource_files'] as $locale => $files) {
foreach ($filesByLocale as $locale => $files) {
foreach ($files as $key => $file) {
// filename is domain.locale.format
list($domain, $locale, $format) = explode('.', basename($file), 3);
$this->addResource($format, $file, $locale, $domain);
unset($this->options['resource_files'][$locale][$key]);
}
}
}