class LocaleTranslation implements TranslatorInterface, DestructableInterface (View source)

String translator using the locale module.

Full featured translation system using locale's string storage and database caching.

Traits

Provides dependency injection friendly methods for serialization.

Properties

protected array $_serviceIds

An array of service IDs keyed by property name used for serialization.

from  DependencySerializationTrait
protected array $_entityStorages

An array of entity type IDs keyed by the property name of their storages.

from  DependencySerializationTrait
protected StringStorageInterface $storage

Storage for strings.

protected ConfigFactoryInterface $configFactory

The configuration factory.

protected array $translations

Cached translations.

protected CacheBackendInterface $cache

The cache backend that should be used.

protected LockBackendInterface $lock

The lock backend that should be used.

protected bool $translateEnglish

The translate english configuration value.

protected LanguageManagerInterface $languageManager

The language manager.

protected RequestStack $requestStack

The request stack.

Methods

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

__construct(StringStorageInterface $storage, CacheBackendInterface $cache, LockBackendInterface $lock, ConfigFactoryInterface $config_factory, LanguageManagerInterface $language_manager, RequestStack $request_stack)

Constructs a translator using a string storage.

string|false
getStringTranslation(string $langcode, string $string, string $context)

Retrieves English string to given language.

bool
canTranslateEnglish()

Gets translate english configuration value.

reset()

Resets translation cache.

destruct()

Performs destruct operations.

Details

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

__construct(StringStorageInterface $storage, CacheBackendInterface $cache, LockBackendInterface $lock, ConfigFactoryInterface $config_factory, LanguageManagerInterface $language_manager, RequestStack $request_stack)

Constructs a translator using a string storage.

Parameters

StringStorageInterface $storage

Storage to use when looking for new translations.

CacheBackendInterface $cache

The cache backend.

LockBackendInterface $lock

The lock backend.

ConfigFactoryInterface $config_factory

The config factory.

LanguageManagerInterface $language_manager

The language manager.

RequestStack $request_stack

The request stack.

string|false getStringTranslation(string $langcode, string $string, string $context)

Retrieves English string to given language.

Parameters

string $langcode

Language code to translate to.

string $string

The source string.

string $context

The string context.

Return Value

string|false

Translated string if there is a translation, FALSE if not.

protected bool canTranslateEnglish()

Gets translate english configuration value.

Return Value

bool

TRUE if english should be translated, FALSE if not.

reset()

Resets translation cache.

Since most translation systems implement some form of caching, this provides a way to delete that cache.

destruct()

Performs destruct operations.