Unverified Commit 5b6ee132 authored by alexpott's avatar alexpott
Browse files

Issue #3255250 by murilohp, daffie, longwave, Gábor Hojtsy: [Symfony 5]...

Issue #3255250 by murilohp, daffie, longwave, Gábor Hojtsy: [Symfony 5] TranslatorInterface::transChoice() is deprecated

(cherry picked from commit c274b2b8)
parent d78321e6
......@@ -42,8 +42,14 @@ public function trans($id, array $parameters = [], $domain = NULL, $locale = NUL
/**
* {@inheritdoc}
*
* @deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. Use
* \Drupal\Core\Validation\DrupalTranslator::trans() instead.
*
* @see https://www.drupal.org/node/3255250
*/
public function transChoice($id, $number, array $parameters = [], $domain = NULL, $locale = NULL) {
@trigger_error(__NAMESPACE__ . '\DrupalTranslator::transChoice() is deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. Use DrupalTranslator::trans() instead. See https://www.drupal.org/node/3255250', E_USER_DEPRECATED);
// Violation messages can separated singular and plural versions by "|".
$ids = explode('|', $id);
......
<?php
namespace Drupal\KernelTests\Core\Validation;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\StringTranslation\PluralTranslatableMarkup;
use Drupal\Core\StringTranslation\TranslationManager;
use Drupal\Core\Validation\DrupalTranslator;
use Drupal\Tests\UnitTestCase;
/**
* Tests the for translator.
*
* @coversDefaultClass \Drupal\Core\Validation\DrupalTranslator
*
* @group validation
*/
class DrupalTranslatorTest extends UnitTestCase {
/**
* {@inheritDoc}
*/
public function setUp(): void {
parent::setUp();
// Set up a mock container as transChoice() will call for the
// 'string_translation' service.
$plural_translatable_markup = $this->getMockBuilder(PluralTranslatableMarkup::class)
->disableOriginalConstructor()
->getMock();
$translation_manager = $this->getMockBuilder(TranslationManager::class)
->onlyMethods(['formatPlural'])
->disableOriginalConstructor()
->getMock();
$translation_manager->expects($this->any())
->method('formatPlural')
->willReturn($plural_translatable_markup);
$container = new ContainerBuilder();
$container->set('string_translation', $translation_manager);
\Drupal::setContainer($container);
}
/**
* Test transChoice deprecation message.
*
* @covers ::transChoice
* @group legacy
*/
public function testDeprecation() {
$this->expectDeprecation('Drupal\Core\Validation\DrupalTranslator::transChoice() is deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. Use DrupalTranslator::trans() instead. See https://www.drupal.org/node/3255250');
$translator = new DrupalTranslator();
$this->assertInstanceOf(
PluralTranslatableMarkup::class,
$translator->transChoice('There is one apple | There are @count apples', 1)
);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment