class CustomStrings extends StaticTranslation (View source)

String translator using overrides from variables.

This is a high performance way to provide a handful of string replacements. See settings.php for examples.

Traits

Provides dependency injection friendly methods for serialization.

Properties

protected array $translations

String translations

from  StaticTranslation
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 Settings $settings

The settings read only object.

Methods

__construct(Settings $settings)

Constructs a CustomStrings object.

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

Retrieves English string to given language.

reset()

Resets translation cache.

array
getLanguage(string $langcode)

Retrieves translations for a given language.

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

Details

__construct(Settings $settings)

Constructs a CustomStrings object.

Parameters

Settings $settings

The settings read only object.

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.

reset()

Resets translation cache.

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

protected array getLanguage(string $langcode)

Retrieves translations for a given language.

Parameters

string $langcode

The langcode of the language.

Return Value

array

A multidimensional array of translations, indexed by the context the source string belongs to. The second level is using original strings as keys. An empty array will be returned when no translations are available.

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}