You are here

class StringTranslation in Service Container 7.2

Same name and namespace in other branches
  1. 7 src/StringTranslation/StringTranslation.php \Drupal\service_container\StringTranslation\StringTranslation

Provides a t() based string translation.

@codeCoverageIgnore

Hierarchy

Expanded class hierarchy of StringTranslation

1 file declares its use of StringTranslation
StringTranslationTest.php in tests/src/StringTranslation/StringTranslationTest.php
Contains \Drupal\Tests\service_container\StringTranslation\StringTranslationTest

File

src/StringTranslation/StringTranslation.php, line 18
Contains \Drupal\service_container\StringTranslation\StringTranslation.

Namespace

Drupal\service_container\StringTranslation
View source
class StringTranslation implements TranslationInterface {

  /**
   * The Drupal7 service.
   *
   * @var \Drupal\service_container\Legacy\Drupal7
   */
  protected $drupal7;

  /**
   * Constructs a new StringTranslation instance.
   *
   * @param \Drupal\service_container\Legacy\Drupal7 $drupal7
   *   The Drupal7 service.
   */
  public function __construct(Drupal7 $drupal7) {
    $this->drupal7 = $drupal7;
  }

  /**
   * {@inheritdoc}
   */
  public function translate($string, array $args = array(), array $options = array()) {
    return $this->drupal7
      ->t($string, $args, $options);
  }

  /**
   * {@inheritdoc}
   */
  public function formatPlural($count, $singular, $plural, array $args = array(), array $options = array()) {
    return $this->drupal7
      ->format_plural($count, $singular, $plural, $args, $options);
  }

  /**
   * {@inheritdoc}
   */
  public function formatPluralTranslated($count, $translation, array $args = array(), array $options = array()) {
    throw new \BadMethodCallException('StringTranslation::formatPluralTranslated is not implemented.');
  }

  /**
   * {@inheritdoc}
   */
  public function getNumberOfPlurals($langCode = NULL) {
    throw new \BadMethodCallException('StringTranslation::getNumberOfPlurals is not implemented.');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
StringTranslation::$drupal7 protected property The Drupal7 service.
StringTranslation::formatPlural public function Formats a string containing a count of items. Overrides TranslationInterface::formatPlural
StringTranslation::formatPluralTranslated public function Formats an already translated string containing a count of items. Overrides TranslationInterface::formatPluralTranslated
StringTranslation::getNumberOfPlurals public function Returns the number of plurals supported by a given language. Overrides TranslationInterface::getNumberOfPlurals
StringTranslation::translate public function Translates a string to the current language or to a given language. Overrides TranslationInterface::translate
StringTranslation::__construct public function Constructs a new StringTranslation instance.