class TranslatableStringAdapter
An adapter for interoperable string translation.
This class is designed to adapt Drupal's style of string translation so it can be used with the Symfony-inspired architecture used by Composer Stager.
If this object is cast to a string, it will be translated by Drupal's translation system. It will ONLY be translated by Composer Stager if the trans() method is explicitly called.
@internal This is an internal part of Package Manager and may be changed or removed at any time without warning. External code should not interact with this class.
Hierarchy
- class \Drupal\Component\Render\FormattableMarkup implements \Drupal\Component\Render\MarkupInterface, \Drupal\Component\Render\Countable
- class \Drupal\Core\StringTranslation\TranslatableMarkup extends \Drupal\Component\Render\FormattableMarkup uses \Drupal\Component\Utility\ToStringTrait
- class \Drupal\package_manager\TranslatableStringAdapter extends \Drupal\Core\StringTranslation\TranslatableMarkup implements \PhpTuf\ComposerStager\API\Translation\Value\TranslatableInterface, \PhpTuf\ComposerStager\API\Translation\Value\TranslationParametersInterface
- class \Drupal\Core\StringTranslation\TranslatableMarkup extends \Drupal\Component\Render\FormattableMarkup uses \Drupal\Component\Utility\ToStringTrait
Expanded class hierarchy of TranslatableStringAdapter
1 file declares its use of TranslatableStringAdapter
- TranslatableStringTest.php in core/
modules/ package_manager/ tests/ src/ Kernel/ TranslatableStringTest.php
File
-
core/
modules/ package_manager/ src/ TranslatableStringAdapter.php, line 27
Namespace
Drupal\package_managerView source
final class TranslatableStringAdapter extends TranslatableMarkup implements TranslatableInterface, TranslationParametersInterface {
/**
* {@inheritdoc}
*/
public function getAll() : array {
return $this->getArguments();
}
/**
* {@inheritdoc}
*/
public function trans(?TranslatorInterface $translator = NULL, ?string $locale = NULL) : string {
// This method is NEVER used by Drupal to translate the underlying string;
// it exists solely for Composer Stager's translation system to
// transparently translate Drupal strings using its own architecture.
return $translator->trans($this->getUntranslatedString(), $this, $this->getOption('context'), $locale ?? $this->getOption('langcode'));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.