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

}

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