TranslatableStringFactory.php

Namespace

Drupal\package_manager

File

core/modules/package_manager/src/TranslatableStringFactory.php

View source
<?php

declare (strict_types=1);
namespace Drupal\package_manager;

use Drupal\Core\StringTranslation\TranslationInterface;
use PhpTuf\ComposerStager\API\Translation\Factory\TranslatableFactoryInterface;
use PhpTuf\ComposerStager\API\Translation\Service\DomainOptionsInterface;
use PhpTuf\ComposerStager\API\Translation\Value\TranslatableInterface;
use PhpTuf\ComposerStager\API\Translation\Value\TranslationParametersInterface;

/**
 * Creates translatable strings that can interoperate with Composer Stager.
 *
 * @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.
 */
final class TranslatableStringFactory implements TranslatableFactoryInterface {
    public function __construct(TranslatableFactoryInterface $decorated, TranslationInterface $translation) {
    }
    
    /**
     * {@inheritdoc}
     */
    public function createDomainOptions() : DomainOptionsInterface {
        return $this->decorated
            ->createDomainOptions();
    }
    
    /**
     * {@inheritdoc}
     */
    public function createTranslatableMessage(string $message, ?TranslationParametersInterface $parameters = NULL, ?string $domain = NULL) : TranslatableInterface {
        return new TranslatableStringAdapter($message, $parameters?->getAll() ?? [], [
            'context' => $domain ?? '',
        ], $this->translation);
    }
    
    /**
     * {@inheritdoc}
     */
    public function createTranslationParameters(array $parameters = []) : TranslationParametersInterface {
        return $this->decorated
            ->createTranslationParameters($parameters);
    }

}

Classes

Title Deprecated Summary
TranslatableStringFactory Creates translatable strings that can interoperate with Composer Stager.

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