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
- trait \Drupal\shs\StringTranslationTrait uses StringTranslationTrait
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\shsView 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
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | property | Default string translation context. | |
StringTranslationTrait:: |
protected | function | ||
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. Aliased as: formatPluralCore | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | ||
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. Aliased as: tCore |