class LocaleConfigManager (View source)

Manages configuration supported in part by interface translation.

This manager is responsible to update configuration overrides and active translations when interface translation data changes. This allows Drupal to translate user roles, views, blocks, etc. after Drupal has been installed using the locale module's storage. When translations change in locale, LocaleConfigManager::updateConfigTranslations() is invoked to update the corresponding storage of the translation in the original config object or an override.

In turn when translated configuration or configuration language overrides are changed, it is the responsibility of LocaleConfigSubscriber to update locale storage.

By design locale module only deals with sources in English.

Properties

protected StorageInterface $configStorage

The storage instance for reading configuration data.

protected StringStorageInterface $localeStorage

The string storage for reading and writing translations.

protected array $translations

Array with preloaded string translations.

protected ConfigFactoryInterface $configFactory

The configuration factory.

protected ConfigurableLanguageManagerInterface $languageManager

The language manager.

protected TypedConfigManagerInterface $typedConfigManager

The typed config manager.

protected bool $isUpdatingFromLocale

Whether or not configuration translations are being updated from locale.

protected LocaleDefaultConfigStorage $defaultConfigStorage

The locale default config storage instance.

protected ConfigManagerInterface $configManager

The configuration manager.

Methods

__construct(StorageInterface $config_storage, StringStorageInterface $locale_storage, ConfigFactoryInterface $config_factory, TypedConfigManagerInterface $typed_config, ConfigurableLanguageManagerInterface $language_manager, LocaleDefaultConfigStorage $default_config_storage, ConfigManagerInterface $config_manager)

Creates a new typed configuration manager.

array
getTranslatableDefaultConfig(string $name)

Gets array of translated strings for Locale translatable configuration.

getTranslatableData(TypedDataInterface $element)

Gets translatable configuration data for a typed configuration element.

array
processTranslatableData(string $name, array $active, array $translatable, string $langcode)

Process the translatable data array with a given language.

saveTranslationOverride(string $name, string $langcode, array $data)

Saves translated configuration override.

saveTranslationActive(string $name, array $data)

Saves translated configuration data.

deleteTranslationOverride(string $name, string $langcode)

Deletes translated configuration data.

array
getComponentNames(array $components = [])

Gets configuration names associated with components.

array
getStringNames(array $lids)

Gets configuration names associated with strings.

deleteLanguageTranslations(string $langcode)

Deletes configuration for language.

string|false
translateString(string $name, string $langcode, string $source, string $context)

Translates string using the localization system.

$this
reset()

Reset static cache of configuration string translations.

getStringTranslation(string $name, string $langcode, string $source, string $context)

Get the translation object for the given source/context and language.

bool
hasTranslation(string $name, string $langcode)

Checks whether a language has configuration translation.

null|string
getDefaultConfigLangcode(string $name)

Returns the original language code for this shipped configuration.

null|string
getActiveConfigLangcode(string $name)

Returns the current language code for this active configuration.

bool
isSupported(string $name)

Whether the given configuration is supported for interface translation.

bool
isUpdatingTranslationsFromLocale()

Indicates whether configuration translations are being updated from locale.

int
updateConfigTranslations(array $names, array $langcodes = [])

Updates all configuration translations for the names / languages provided.

array
filterOverride(array $override_data, array $translatable)

Filters override data based on default translatable items.

Details

__construct(StorageInterface $config_storage, StringStorageInterface $locale_storage, ConfigFactoryInterface $config_factory, TypedConfigManagerInterface $typed_config, ConfigurableLanguageManagerInterface $language_manager, LocaleDefaultConfigStorage $default_config_storage, ConfigManagerInterface $config_manager)

Creates a new typed configuration manager.

Parameters

StorageInterface $config_storage

The storage object to use for reading configuration data.

StringStorageInterface $locale_storage

The locale storage to use for reading string translations.

ConfigFactoryInterface $config_factory

The configuration factory

TypedConfigManagerInterface $typed_config

The typed configuration manager.

ConfigurableLanguageManagerInterface $language_manager

The language manager.

LocaleDefaultConfigStorage $default_config_storage

The locale default configuration storage.

ConfigManagerInterface $config_manager

The configuration manager.

array getTranslatableDefaultConfig(string $name)

Gets array of translated strings for Locale translatable configuration.

Parameters

string $name

Configuration object name.

Return Value

array

Array of Locale translatable elements of the default configuration in $name.

protected array|TranslatableMarkup getTranslatableData(TypedDataInterface $element)

Gets translatable configuration data for a typed configuration element.

Parameters

TypedDataInterface $element

Typed configuration element.

Return Value

array|TranslatableMarkup

A nested array matching the exact structure under $element with only the elements that are translatable wrapped into a TranslatableMarkup. If the provided $element is not traversable, the return value is a single TranslatableMarkup.

protected array processTranslatableData(string $name, array $active, array $translatable, string $langcode)

Process the translatable data array with a given language.

If the given language is translatable, will return the translated copy which will only contain strings that had translations. If the given language is English and is not translatable, will return a simplified array of the English source strings only.

Parameters

string $name

The configuration name.

array $active

The active configuration data.

array $translatable

The translatable array structure. A nested array matching the exact structure under of the default configuration for $name with only the elements that are translatable wrapped into a TranslatableMarkup.

string $langcode

The language code to process the array with.

Return Value

array

Processed translatable data array. Will only contain translations different from source strings or in case of untranslatable English, the source strings themselves.

See also

\Drupal\locale\self::getTranslatableData()

protected saveTranslationOverride(string $name, string $langcode, array $data)

Saves translated configuration override.

Parameters

string $name

Configuration object name.

string $langcode

Language code.

array $data

Configuration data to be saved, that will be only the translated values.

protected saveTranslationActive(string $name, array $data)

Saves translated configuration data.

Parameters

string $name

Configuration object name.

array $data

Configuration data to be saved with translations merged in.

protected deleteTranslationOverride(string $name, string $langcode)

Deletes translated configuration data.

Parameters

string $name

Configuration object name.

string $langcode

Language code.

array getComponentNames(array $components = [])

Gets configuration names associated with components.

Parameters

array $components

(optional) Array of component lists indexed by type. If not present or it is an empty array, it will update all components.

Return Value

array

Array of configuration object names.

array getStringNames(array $lids)

Gets configuration names associated with strings.

Parameters

array $lids

Array with string identifiers.

Return Value

array

Array of configuration object names.

deleteLanguageTranslations(string $langcode)

Deletes configuration for language.

Parameters

string $langcode

Language code to delete.

string|false translateString(string $name, string $langcode, string $source, string $context)

Translates string using the localization system.

So far we only know how to translate strings from English so the source string should be in English. Unlike regular t() translations, strings will be added to the source tables only if this is marked as default data.

Parameters

string $name

Name of the configuration location.

string $langcode

Language code to translate to.

string $source

The source string, should be English.

string $context

The string context.

Return Value

string|false

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

$this reset()

Reset static cache of configuration string translations.

Return Value

$this

TranslationString|false getStringTranslation(string $name, string $langcode, string $source, string $context)

Get the translation object for the given source/context and language.

Parameters

string $name

Name of the configuration location.

string $langcode

Language code to translate to.

string $source

The source string, should be English.

string $context

The string context.

Return Value

TranslationString|false

The translation object if the string was not empty or FALSE otherwise.

bool hasTranslation(string $name, string $langcode)

Checks whether a language has configuration translation.

Parameters

string $name

Configuration name.

string $langcode

A language code.

Return Value

bool

A boolean indicating if a language has configuration translations.

null|string getDefaultConfigLangcode(string $name)

Returns the original language code for this shipped configuration.

Parameters

string $name

The configuration name.

Return Value

null|string

Language code of the default configuration for $name. If the default configuration data for $name did not contain a language code, it is assumed to be English. The return value is NULL if no such default configuration exists.

null|string getActiveConfigLangcode(string $name)

Returns the current language code for this active configuration.

Parameters

string $name

The configuration name.

Return Value

null|string

Language code of the current active configuration for $name. If the configuration data for $name did not contain a language code, it is assumed to be English. The return value is NULL if no such active configuration exists.

bool isSupported(string $name)

Whether the given configuration is supported for interface translation.

Parameters

string $name

The configuration name.

Return Value

bool

TRUE if interface translation is supported.

bool isUpdatingTranslationsFromLocale()

Indicates whether configuration translations are being updated from locale.

Return Value

bool

Whether or not configuration translations are currently being updated. If TRUE, LocaleConfigManager is in control of the process and the reference data is locale's storage. Changes made to active configuration and overrides in this case should not feed back to locale storage. On the other hand, when not updating from locale and configuration translations change, we need to feed back to the locale storage.

int updateConfigTranslations(array $names, array $langcodes = [])

Updates all configuration translations for the names / languages provided.

To be used when interface translation changes result in the need to update configuration translations to keep them in sync.

Parameters

array $names

Array of names of configuration objects to update.

array $langcodes

(optional) Array of language codes to update. Defaults to all configurable languages.

Return Value

int

Total number of configuration override and active configuration objects updated (saved or removed).

protected array filterOverride(array $override_data, array $translatable)

Filters override data based on default translatable items.

Parameters

array $override_data

Configuration override data.

array $translatable

Translatable data array. self::getTranslatableData()

Return Value

array

Nested array of any items of $override_data which did not have keys in $translatable. May be empty if $override_data only had items which were also in $translatable.