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

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_manager
View 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'));
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
FormattableMarkup::$arguments protected property The arguments to replace placeholders with.
FormattableMarkup::$string protected property The string containing placeholders.
FormattableMarkup::jsonSerialize public function Returns a representation of the object for use in JSON serialization.
FormattableMarkup::placeholderEscape protected static function Escapes a placeholder replacement value if needed.
FormattableMarkup::placeholderFormat protected static function Replaces placeholders in a string with values.
ToStringTrait::_die protected function For test purposes, wrap die() in an overridable method.
ToStringTrait::__toString public function Implements the magic __toString() method.
TranslatableMarkup::$options protected property The translation options.
TranslatableMarkup::$stringTranslation protected property The string translation service.
TranslatableMarkup::$translatedMarkup protected property The translated markup without placeholder replacements.
TranslatableMarkup::count public function Returns the string length. Overrides FormattableMarkup::count
TranslatableMarkup::getArguments public function Gets all arguments from this translated string.
TranslatableMarkup::getOption public function Gets a specific option from this translated string.
TranslatableMarkup::getOptions public function Gets all options from this translated string.
TranslatableMarkup::getStringTranslation protected function Gets the string translation service.
TranslatableMarkup::getUntranslatedString public function Gets the untranslated string value stored in this translated string.
TranslatableMarkup::render public function Renders the object as a string. Overrides ToStringTrait::render 1
TranslatableMarkup::__construct public function Constructs a new class instance. Overrides FormattableMarkup::__construct 2
TranslatableMarkup::__sleep public function Magic __sleep() method to avoid serializing the string translator. 1
TranslatableStringAdapter::getAll public function
TranslatableStringAdapter::trans public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.