This commit is contained in:
Paolo A
2024-08-13 13:44:16 +00:00
parent 1bbb23088d
commit e796d76612
4001 changed files with 30101 additions and 40075 deletions

View File

@@ -34,11 +34,6 @@ abstract class AbstractOperation implements OperationInterface
protected $target;
protected $result;
/**
* @var array|null The domains affected by this operation
*/
private $domains;
/**
* This array stores 'all', 'new' and 'obsolete' messages for all valid domains.
*
@@ -62,6 +57,8 @@ abstract class AbstractOperation implements OperationInterface
*/
protected $messages;
private array $domains;
/**
* @throws LogicException
*/
@@ -77,12 +74,9 @@ abstract class AbstractOperation implements OperationInterface
$this->messages = [];
}
/**
* {@inheritdoc}
*/
public function getDomains(): array
{
if (null === $this->domains) {
if (!isset($this->domains)) {
$domains = [];
foreach ([$this->source, $this->target] as $catalogue) {
foreach ($catalogue->getDomains() as $domain) {
@@ -100,9 +94,6 @@ abstract class AbstractOperation implements OperationInterface
return $this->domains;
}
/**
* {@inheritdoc}
*/
public function getMessages(string $domain): array
{
if (!\in_array($domain, $this->getDomains())) {
@@ -116,9 +107,6 @@ abstract class AbstractOperation implements OperationInterface
return $this->messages[$domain][self::ALL_BATCH];
}
/**
* {@inheritdoc}
*/
public function getNewMessages(string $domain): array
{
if (!\in_array($domain, $this->getDomains())) {
@@ -132,9 +120,6 @@ abstract class AbstractOperation implements OperationInterface
return $this->messages[$domain][self::NEW_BATCH];
}
/**
* {@inheritdoc}
*/
public function getObsoleteMessages(string $domain): array
{
if (!\in_array($domain, $this->getDomains())) {
@@ -148,9 +133,6 @@ abstract class AbstractOperation implements OperationInterface
return $this->messages[$domain][self::OBSOLETE_BATCH];
}
/**
* {@inheritdoc}
*/
public function getResult(): MessageCatalogueInterface
{
foreach ($this->getDomains() as $domain) {
@@ -174,12 +156,12 @@ abstract class AbstractOperation implements OperationInterface
foreach ($this->getDomains() as $domain) {
$intlDomain = $domain.MessageCatalogueInterface::INTL_DOMAIN_SUFFIX;
switch ($batch) {
case self::OBSOLETE_BATCH: $messages = $this->getObsoleteMessages($domain); break;
case self::NEW_BATCH: $messages = $this->getNewMessages($domain); break;
case self::ALL_BATCH: $messages = $this->getMessages($domain); break;
default: throw new \InvalidArgumentException(sprintf('$batch argument must be one of ["%s", "%s", "%s"].', self::ALL_BATCH, self::NEW_BATCH, self::OBSOLETE_BATCH));
}
$messages = match ($batch) {
self::OBSOLETE_BATCH => $this->getObsoleteMessages($domain),
self::NEW_BATCH => $this->getNewMessages($domain),
self::ALL_BATCH => $this->getMessages($domain),
default => throw new \InvalidArgumentException(sprintf('$batch argument must be one of ["%s", "%s", "%s"].', self::ALL_BATCH, self::NEW_BATCH, self::OBSOLETE_BATCH)),
};
if (!$messages || (!$this->source->all($intlDomain) && $this->source->all($domain))) {
continue;
@@ -198,6 +180,8 @@ abstract class AbstractOperation implements OperationInterface
* stores the results.
*
* @param string $domain The domain which the operation will be performed for
*
* @return void
*/
abstract protected function processDomain(string $domain);
}

View File

@@ -25,7 +25,7 @@ use Symfony\Component\Translation\MessageCatalogueInterface;
class MergeOperation extends AbstractOperation
{
/**
* {@inheritdoc}
* @return void
*/
protected function processDomain(string $domain)
{
@@ -36,6 +36,18 @@ class MergeOperation extends AbstractOperation
];
$intlDomain = $domain.MessageCatalogueInterface::INTL_DOMAIN_SUFFIX;
foreach ($this->target->getCatalogueMetadata('', $domain) ?? [] as $key => $value) {
if (null === $this->result->getCatalogueMetadata($key, $domain)) {
$this->result->setCatalogueMetadata($key, $value, $domain);
}
}
foreach ($this->target->getCatalogueMetadata('', $intlDomain) ?? [] as $key => $value) {
if (null === $this->result->getCatalogueMetadata($key, $intlDomain)) {
$this->result->setCatalogueMetadata($key, $value, $intlDomain);
}
}
foreach ($this->source->all($domain) as $id => $message) {
$this->messages[$domain]['all'][$id] = $message;
$d = $this->source->defines($id, $intlDomain) ? $intlDomain : $domain;

View File

@@ -26,7 +26,7 @@ use Symfony\Component\Translation\MessageCatalogueInterface;
class TargetOperation extends AbstractOperation
{
/**
* {@inheritdoc}
* @return void
*/
protected function processDomain(string $domain)
{
@@ -37,6 +37,18 @@ class TargetOperation extends AbstractOperation
];
$intlDomain = $domain.MessageCatalogueInterface::INTL_DOMAIN_SUFFIX;
foreach ($this->target->getCatalogueMetadata('', $domain) ?? [] as $key => $value) {
if (null === $this->result->getCatalogueMetadata($key, $domain)) {
$this->result->setCatalogueMetadata($key, $value, $domain);
}
}
foreach ($this->target->getCatalogueMetadata('', $intlDomain) ?? [] as $key => $value) {
if (null === $this->result->getCatalogueMetadata($key, $intlDomain)) {
$this->result->setCatalogueMetadata($key, $value, $intlDomain);
}
}
// For 'all' messages, the code can't be simplified as ``$this->messages[$domain]['all'] = $target->all($domain);``,
// because doing so will drop messages like {x: x ∈ source ∧ x ∉ target.all ∧ x ∈ target.fallback}
//