addTranslator example


  public function testFormatPlural($count$singular$plural, array $args, array $options$expected) {
    $langcode = empty($options['langcode']) ? 'fr' : $options['langcode'];
    $translator = $this->createMock('\Drupal\Core\StringTranslation\Translator\TranslatorInterface');
    $translator->expects($this->once())
      ->method('getStringTranslation')
      ->with($langcode$this->anything()$this->anything())
      ->willReturnCallback(function D$langcode$string$context) {
        return $string;
      });
    $this->translationManager->setDefaultLangcode('fr');
    $this->translationManager->addTranslator($translator);
    $result = $this->translationManager->formatPlural($count$singular$plural$args$options);
    $this->assertEquals($expected$result);
    $this->assertInstanceOf(MarkupInterface::class$result);
  }

  /** * Tests translation using placeholders. * * @param string $string * A string containing the English text to translate. * @param array $args * An associative array of replacements to make after translation. * @param string $expected_string * The expected translated string value. * * @dataProvider providerTestTranslatePlaceholder */
Home | Imprint | This part of the site doesn't use cookies.