You are here

trait StringTranslationTrait in Simple hierarchical select 2.0.x

Custom enhancements for the StringTranslationTrait.

Using this trait will override the core functions t() and formatPlural() and adds a default context. To override the context, set a protected variable named $translationContext in your class.

Hierarchy

See also

\Drupal\Core\StringTranslation\StringTranslationTrait

3 files declare their use of StringTranslationTrait
EntityReferenceShsFormatter.php in src/Plugin/Field/FieldFormatter/EntityReferenceShsFormatter.php
OptionsShsWidget.php in src/Plugin/Field/FieldWidget/OptionsShsWidget.php
ShsTaxonomyIndexTid.php in src/Plugin/views/filter/ShsTaxonomyIndexTid.php

File

src/StringTranslationTrait.php, line 18

Namespace

Drupal\shs
View source
trait StringTranslationTrait {

  /**
   * Default string translation context.
   *
   * @var string
   */
  protected $translationContext = 'shs';
  use StringTranslationTraitCore {
    t as tCore;
    formatPlural as formatPluralCore;
  }

  /**
   * {@inheritdoc}
   */
  protected function t($string, array $args = [], array $options = []) {
    if (empty($options['context'])) {
      $options['context'] = $this->translationContext;
    }
    return $this
      ->tCore($string, $args, $options);
  }

  /**
   * {@inheritdoc}
   */
  protected function formatPlural($count, $singular, $plural, array $args = [], array $options = []) {
    if (empty($options['context'])) {
      $options['context'] = $this->translationContext;
    }
    return $this
      ->formatPluralCore($count, $singular, $plural, $args, $options);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::$translationContext protected property Default string translation context.
StringTranslationTrait::formatPlural protected function
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items. Aliased as: formatPluralCore
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function
StringTranslationTrait::t protected function Translates a string to the current language or to a given language. Aliased as: tCore