Commit 3d2cf1a0 authored by catch's avatar catch

Issue #2546618 by plach, dawehner, chx, bojanz: Replace the Symfony...

Issue #2546618 by plach, dawehner, chx, bojanz: Replace the Symfony Translation component with a custom interface since we don't use it
parent bc05470d
......@@ -120,7 +120,8 @@
"drupal/update": "self.version",
"drupal/user": "self.version",
"drupal/views": "self.version",
"drupal/views_ui": "self.version"
"drupal/views_ui": "self.version",
"symfony/translation": "~2.4"
},
"minimum-stability": "dev",
"prefer-stable": true,
......@@ -128,7 +129,8 @@
"psr-4": {
"Drupal\\Core\\": "lib/Drupal/Core",
"Drupal\\Component\\": "lib/Drupal/Component",
"Drupal\\Driver\\": "../drivers/lib/Drupal/Driver"
"Drupal\\Driver\\": "../drivers/lib/Drupal/Driver",
"Symfony\\Component\\Translation\\": "lib/Symfony/Component/Translation"
},
"files": [
"lib/Drupal.php"
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "e789e5736fbe96c9b9502e89b53dcebe",
"hash": "5916317ae84f5caeb1bb254f4fe65775",
"packages": [
{
"name": "behat/mink",
......@@ -2916,67 +2916,6 @@
"homepage": "https://symfony.com",
"time": "2015-08-31 16:44:53"
},
{
"name": "symfony/translation",
"version": "v2.7.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/Translation.git",
"reference": "485877661835e188cd78345c6d4eef1290d17571"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Translation/zipball/485877661835e188cd78345c6d4eef1290d17571",
"reference": "485877661835e188cd78345c6d4eef1290d17571",
"shasum": ""
},
"require": {
"php": ">=5.3.9"
},
"conflict": {
"symfony/config": "<2.7"
},
"require-dev": {
"psr/log": "~1.0",
"symfony/config": "~2.7",
"symfony/intl": "~2.4",
"symfony/phpunit-bridge": "~2.7",
"symfony/yaml": "~2.2"
},
"suggest": {
"psr/log": "To use logging capability in translator",
"symfony/config": "",
"symfony/yaml": ""
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.7-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\Translation\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Translation Component",
"homepage": "https://symfony.com",
"time": "2015-09-06 08:36:38"
},
{
"name": "symfony/validator",
"version": "v2.7.4",
......
......@@ -7,7 +7,7 @@
namespace Drupal\Core\TypedData\Validation;
use Symfony\Component\Translation\TranslatorInterface;
use Drupal\Core\Validation\TranslatorInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\ConstraintViolationList;
......@@ -68,7 +68,7 @@ class ConstraintViolationBuilder implements ConstraintViolationBuilderInterface
/**
* The translator.
*
* @var \Symfony\Component\Translation\TranslatorInterface
* @var \Drupal\Core\Validation\TranslatorInterface
*/
protected $translator;
......@@ -117,7 +117,7 @@ class ConstraintViolationBuilder implements ConstraintViolationBuilderInterface
* The property string.
* @param mixed $invalidValue
* The invalid value.
* @param \Symfony\Component\Translation\TranslatorInterface $translator
* @param \Drupal\Core\Validation\TranslatorInterface $translator
* The translator.
* @param null $translationDomain
* (optional) The translation domain.
......
......@@ -7,7 +7,7 @@
namespace Drupal\Core\TypedData\Validation;
use Symfony\Component\Translation\TranslatorInterface;
use Drupal\Core\Validation\TranslatorInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\ConstraintViolationList;
......@@ -38,7 +38,7 @@ class ExecutionContext implements ExecutionContextInterface {
protected $root;
/**
* @var \Symfony\Component\Translation\TranslatorInterface
* @var \Drupal\Core\Validation\TranslatorInterface
*/
protected $translator;
......@@ -117,7 +117,7 @@ class ExecutionContext implements ExecutionContextInterface {
* The validator.
* @param mixed $root
* The root.
* @param \Symfony\Component\Translation\TranslatorInterface $translator
* @param \Drupal\Core\Validation\TranslatorInterface $translator
* The translator.
* @param string $translationDomain
* (optional) The translation domain.
......
......@@ -7,7 +7,7 @@
namespace Drupal\Core\TypedData\Validation;
use Symfony\Component\Translation\TranslatorInterface;
use Drupal\Core\Validation\TranslatorInterface;
use Symfony\Component\Validator\Context\ExecutionContextFactoryInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
......@@ -21,7 +21,7 @@
class ExecutionContextFactory implements ExecutionContextFactoryInterface {
/**
* @var TranslatorInterface
* @var \Drupal\Core\Validation\TranslatorInterface
*/
protected $translator;
......@@ -33,7 +33,7 @@ class ExecutionContextFactory implements ExecutionContextFactoryInterface {
/**
* Constructs a new ExecutionContextFactory instance.
*
* @param \Symfony\Component\Translation\TranslatorInterface $translator
* @param \Drupal\Core\Validation\TranslatorInterface $translator
* The translator instance.
* @param string $translationDomain
* (optional) The translation domain.
......
......@@ -7,8 +7,6 @@
namespace Drupal\Core\Validation;
use Symfony\Component\Translation\TranslatorInterface;
/**
* Translates strings using Drupal's translation system.
*
......
<?php
/**
* @file
* Contains \Drupal\Core\Validation\TranslatorInterface.
*/
namespace Drupal\Core\Validation;
use Symfony\Component\Translation\TranslatorInterface as SymfonyTranslatorInterface;
/**
* Defines an interface used in validation.
*
* This extends the interface used by the Symfony validator in order to indicate
* that the Drupal code is actually independent from the Symfony translation
* component.
*
* @see https://github.com/symfony/symfony/pull/6189
* @see https://github.com/symfony/symfony/issues/15714
*/
interface TranslatorInterface extends SymfonyTranslatorInterface {
}
Symfony component interfaces included as part of the Drupal codebase are used to
provide Drupal-specific implementations of Symfony subsystems that are not
available as standalone components and thus cannot be cherry-picked.
A composer.json "replace" entry is used in order to bypass the composer.json
dependency onto the Symfony components originally including the interfaces
provided here.
......@@ -16,10 +16,8 @@
use Drupal\Core\TypedData\Validation\RecursiveValidator;
use Drupal\Core\Validation\ConstraintManager;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\Translation\IdentityTranslator;
use Symfony\Component\Validator\ConstraintValidatorFactory;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\DefaultTranslator;
/**
* @coversDefaultClass \Drupal\Core\TypedData\Validation\RecursiveContextualValidator
......@@ -82,7 +80,12 @@ protected function setUp() {
$container->set('typed_data_manager', $this->typedDataManager);
\Drupal::setContainer($container);
$translator = new IdentityTranslator();
$translator = $this->getMock('Drupal\Core\Validation\TranslatorInterface');
$translator->expects($this->any())
->method('trans')
->willReturnCallback(function($id) {
return $id;
});
$this->contextFactory = new ExecutionContextFactory($translator);
$this->validatorFactory = new ConstraintValidatorFactory();
$this->recursiveValidator = new RecursiveValidator($this->contextFactory, $this->validatorFactory, $this->typedDataManager);
......
......@@ -12,7 +12,7 @@
'Zend\\Diactoros\\' => array($vendorDir . '/zendframework/zend-diactoros/src'),
'Symfony\\Component\\Yaml\\' => array($vendorDir . '/symfony/yaml'),
'Symfony\\Component\\Validator\\' => array($vendorDir . '/symfony/validator'),
'Symfony\\Component\\Translation\\' => array($vendorDir . '/symfony/translation'),
'Symfony\\Component\\Translation\\' => array($baseDir . '/lib/Symfony/Component/Translation'),
'Symfony\\Component\\Serializer\\' => array($vendorDir . '/symfony/serializer'),
'Symfony\\Component\\Routing\\' => array($vendorDir . '/symfony/routing'),
'Symfony\\Component\\Process\\' => array($vendorDir . '/symfony/process'),
......
......@@ -3130,69 +3130,6 @@
"description": "Symfony Serializer Component",
"homepage": "https://symfony.com"
},
{
"name": "symfony/translation",
"version": "v2.7.4",
"version_normalized": "2.7.4.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/Translation.git",
"reference": "485877661835e188cd78345c6d4eef1290d17571"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Translation/zipball/485877661835e188cd78345c6d4eef1290d17571",
"reference": "485877661835e188cd78345c6d4eef1290d17571",
"shasum": ""
},
"require": {
"php": ">=5.3.9"
},
"conflict": {
"symfony/config": "<2.7"
},
"require-dev": {
"psr/log": "~1.0",
"symfony/config": "~2.7",
"symfony/intl": "~2.4",
"symfony/phpunit-bridge": "~2.7",
"symfony/yaml": "~2.2"
},
"suggest": {
"psr/log": "To use logging capability in translator",
"symfony/config": "",
"symfony/yaml": ""
},
"time": "2015-09-06 08:36:38",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.7-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"Symfony\\Component\\Translation\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Translation Component",
"homepage": "https://symfony.com"
},
{
"name": "symfony/validator",
"version": "v2.7.4",
......
CHANGELOG
=========
2.7.0
-----
* added DataCollectorTranslator for collecting the translated messages.
2.6.0
-----
* added possibility to cache catalogues
* added TranslatorBagInterface
* added LoggingTranslator
* added Translator::getMessages() for retrieving the message catalogue as an array
2.5.0
-----
* added relative file path template to the file dumpers
* added optional backup to the file dumpers
* changed IcuResFileDumper to extend FileDumper
2.3.0
-----
* added classes to make operations on catalogues (like making a diff or a merge on 2 catalogues)
* added Translator::getFallbackLocales()
* deprecated Translator::setFallbackLocale() in favor of the new Translator::setFallbackLocales() method
2.2.0
-----
* QtTranslationsLoader class renamed to QtFileLoader. QtTranslationsLoader is deprecated and will be removed in 2.3.
* [BC BREAK] uniformized the exception thrown by the load() method when an error occurs. The load() method now
throws Symfony\Component\Translation\Exception\NotFoundResourceException when a resource cannot be found
and Symfony\Component\Translation\Exception\InvalidResourceException when a resource is invalid.
* changed the exception class thrown by some load() methods from \RuntimeException to \InvalidArgumentException
(IcuDatFileLoader, IcuResFileLoader and QtFileLoader)
2.1.0
-----
* added support for more than one fallback locale
* added support for extracting translation messages from templates (Twig and PHP)
* added dumpers for translation catalogs
* added support for QT, gettext, and ResourceBundles
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Translation\Catalogue;
use Symfony\Component\Translation\MessageCatalogue;
use Symfony\Component\Translation\MessageCatalogueInterface;
/**
* Base catalogues binary operation class.
*
* @author Jean-François Simon <contact@jfsimon.fr>
*/
abstract class AbstractOperation implements OperationInterface
{
/**
* @var MessageCatalogueInterface
*/
protected $source;
/**
* @var MessageCatalogueInterface
*/
protected $target;
/**
* @var MessageCatalogue
*/
protected $result;
/**
* @var null|array
*/
private $domains;
/**
* @var array
*/
protected $messages;
/**
* @param MessageCatalogueInterface $source
* @param MessageCatalogueInterface $target
*
* @throws \LogicException
*/
public function __construct(MessageCatalogueInterface $source, MessageCatalogueInterface $target)
{
if ($source->getLocale() !== $target->getLocale()) {
throw new \LogicException('Operated catalogues must belong to the same locale.');
}
$this->source = $source;
$this->target = $target;
$this->result = new MessageCatalogue($source->getLocale());
$this->domains = null;
$this->messages = array();
}
/**
* {@inheritdoc}
*/
public function getDomains()
{
if (null === $this->domains) {
$this->domains = array_values(array_unique(array_merge($this->source->getDomains(), $this->target->getDomains())));
}
return $this->domains;
}
/**
* {@inheritdoc}
*/
public function getMessages($domain)
{
if (!in_array($domain, $this->getDomains())) {
throw new \InvalidArgumentException(sprintf('Invalid domain: %s.', $domain));
}
if (!isset($this->messages[$domain]['all'])) {
$this->processDomain($domain);
}
return $this->messages[$domain]['all'];
}
/**
* {@inheritdoc}
*/
public function getNewMessages($domain)
{
if (!in_array($domain, $this->getDomains())) {
throw new \InvalidArgumentException(sprintf('Invalid domain: %s.', $domain));
}
if (!isset($this->messages[$domain]['new'])) {
$this->processDomain($domain);
}
return $this->messages[$domain]['new'];
}
/**
* {@inheritdoc}
*/
public function getObsoleteMessages($domain)
{
if (!in_array($domain, $this->getDomains())) {
throw new \InvalidArgumentException(sprintf('Invalid domain: %s.', $domain));
}
if (!isset($this->messages[$domain]['obsolete'])) {
$this->processDomain($domain);
}
return $this->messages[$domain]['obsolete'];
}
/**
* {@inheritdoc}
*/
public function getResult()
{
foreach ($this->getDomains() as $domain) {
if (!isset($this->messages[$domain])) {
$this->processDomain($domain);
}
}
return $this->result;
}
/**
* @param string $domain
*/
abstract protected function processDomain($domain);
}
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Translation\Catalogue;
/**
* Diff operation between two catalogues.
*
* @author Jean-François Simon <contact@jfsimon.fr>
*/
class DiffOperation extends AbstractOperation
{
/**
* {@inheritdoc}
*/
protected function processDomain($domain)
{
$this->messages[$domain] = array(
'all' => array(),
'new' => array(),
'obsolete' => array(),
);
foreach ($this->source->all($domain) as $id => $message) {
if ($this->target->has($id, $domain)) {
$this->messages[$domain]['all'][$id] = $message;
$this->result->add(array($id => $message), $domain);
if (null !== $keyMetadata = $this->source->getMetadata($id, $domain)) {
$this->result->setMetadata($id, $keyMetadata, $domain);
}
} else {
$this->messages[$domain]['obsolete'][$id] = $message;
}
}
foreach ($this->target->all($domain) as $id => $message) {
if (!$this->source->has($id, $domain)) {
$this->messages[$domain]['all'][$id] = $message;
$this->messages[$domain]['new'][$id] = $message;
$this->result->add(array($id => $message), $domain);
if (null !== $keyMetadata = $this->target->getMetadata($id, $domain)) {
$this->result->setMetadata($id, $keyMetadata, $domain);
}
}
}
}
}
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Translation\Catalogue;
/**
* Merge operation between two catalogues.
*
* @author Jean-François Simon <contact@jfsimon.fr>
*/
class MergeOperation extends AbstractOperation
{
/**
* {@inheritdoc}
*/
protected function processDomain($domain)
{
$this->messages[$domain] = array(
'all' => array(),
'new' => array(),
'obsolete' => array(),
);
foreach ($this->source->all($domain) as $id => $message) {
$this->messages[$domain]['all'][$id] = $message;
$this->result->add(array($id => $message), $domain);
if (null !== $keyMetadata = $this->source->getMetadata($id, $domain)) {
$this->result->setMetadata($id, $keyMetadata, $domain);
}
}
foreach ($this->target->all($domain) as $id => $message) {
if (!$this->source->has($id, $domain)) {
$this->messages[$domain]['all'][$id] = $message;
$this->messages[$domain]['new'][$id] = $message;
$this->result->add(array($id => $message), $domain);
if (null !== $keyMetadata = $this->target->getMetadata($id, $domain)) {
$this->result->setMetadata($id, $keyMetadata, $domain);
}
}
}
}
}