Drupal 8  8.0.2
LocaleConfigManager Class Reference

Public Member Functions

 __construct (StorageInterface $config_storage, StringStorageInterface $locale_storage, ConfigFactoryInterface $config_factory, TypedConfigManagerInterface $typed_config, ConfigurableLanguageManagerInterface $language_manager, LocaleDefaultConfigStorage $default_config_storage)
 
 _setConfigManager (ConfigManagerInterface $config_manager)
 
 getTranslatableDefaultConfig ($name)
 
 getComponentNames (array $components=array())
 
 getStringNames (array $lids)
 
 deleteLanguageTranslations ($langcode)
 
 translateString ($name, $langcode, $source, $context)
 
 reset ()
 
 getStringTranslation ($name, $langcode, $source, $context)
 
 hasTranslation ($name, $langcode)
 
 getDefaultConfigLangcode ($name)
 
 getActiveConfigLangcode ($name)
 
 isSupported ($name)
 
 isUpdatingTranslationsFromLocale ()
 
 updateConfigTranslations (array $names, array $langcodes=array())
 

Protected Member Functions

 getTranslatableData (TypedDataInterface $element)
 
 processTranslatableData ($name, array $active, array $translatable, $langcode)
 
 saveTranslationOverride ($name, $langcode, array $data)
 
 saveTranslationActive ($name, array $data)
 
 deleteTranslationOverride ($name, $langcode)
 
 filterOverride (array $override_data, array $translatable)
 

Protected Attributes

 $configStorage
 
 $localeStorage
 
 $translations
 
 $configFactory
 
 $languageManager
 
 $typedConfigManager
 
 $isUpdatingFromLocale = FALSE
 
 $defaultConfigStorage
 

Detailed Description

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.

See Also

Constructor & Destructor Documentation

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

Creates a new typed configuration manager.

Parameters
\Drupal\Core\Config\StorageInterface$config_storageThe storage object to use for reading configuration data.
\Drupal\locale\StringStorageInterface$locale_storageThe locale storage to use for reading string translations.
\Drupal\Core\Config\ConfigFactoryInterface$config_factoryThe configuration factory
\Drupal\Core\Config\TypedConfigManagerInterface$typed_configThe typed configuration manager.
\Drupal\language\ConfigurableLanguageManagerInterface$language_managerThe language manager.
\Drupal\locale\LocaleDefaultConfigStorage$default_config_storageThe locale default configuration storage.

References Drupal\configFactory(), and Drupal\languageManager().

Here is the call graph for this function:

Member Function Documentation

_setConfigManager ( ConfigManagerInterface  $config_manager)

Sets the configuration manager service.

Parameters
\Drupal\Core\Config\ConfigManagerInterface$config_manager
deleteLanguageTranslations (   $langcode)

Deletes configuration for language.

Parameters
string$langcodeLanguage code to delete.

References Drupal\languageManager().

Here is the call graph for this function:

deleteTranslationOverride (   $name,
  $langcode 
)
protected

Deletes translated configuration data.

Parameters
string$nameConfiguration object name.
string$langcodeLanguage code.

References Drupal\languageManager().

Referenced by LocaleConfigManager\updateConfigTranslations().

Here is the call graph for this function:

Here is the caller graph for this function:

filterOverride ( array  $override_data,
array  $translatable 
)
protected

Filters override data based on default translatable items.

Parameters
array$override_dataConfiguration override data.
array$translatableTranslatable data array.
See Also
self::getTranslatableData()
Returns
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.

Referenced by LocaleConfigManager\updateConfigTranslations().

Here is the caller graph for this function:

getActiveConfigLangcode (   $name)

Returns the current language code for this active configuration.

Parameters
string$nameThe configuration name.
Returns
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.

Referenced by LocaleConfigManager\updateConfigTranslations().

Here is the caller graph for this function:

getComponentNames ( array  $components = array())

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.
Returns
array Array of configuration object names.
getDefaultConfigLangcode (   $name)

Returns the original language code for this shipped configuration.

Parameters
string$nameThe configuration name.
Returns
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.

References Drupal\configFactory().

Referenced by LocaleConfigManager\isSupported().

Here is the call graph for this function:

Here is the caller graph for this function:

getStringNames ( array  $lids)

Gets configuration names associated with strings.

Parameters
array$lidsArray with string identifiers.
Returns
array Array of configuration object names.
getStringTranslation (   $name,
  $langcode,
  $source,
  $context 
)

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

Parameters
string$nameName of the configuration location.
string$langcodeLanguage code to translate to.
string$sourceThe source string, should be English.
string$contextThe string context.
Returns
|FALSE The translation object if the string was not empty or FALSE otherwise.

References LocaleConfigManager\translateString().

Here is the call graph for this function:

getTranslatableData ( TypedDataInterface  $element)
protected

Gets translatable configuration data for a typed configuration element.

Parameters
\Drupal\Core\TypedData\TypedDataInterface$elementTyped configuration element.
Returns
array| 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.

References TypedDataInterface\getDataDefinition(), and TypedDataInterface\getValue().

Referenced by LocaleConfigManager\getTranslatableDefaultConfig().

Here is the call graph for this function:

Here is the caller graph for this function:

getTranslatableDefaultConfig (   $name)

Gets array of translated strings for Locale translatable configuration.

Parameters
string$nameConfiguration object name.
Returns
array Array of Locale translatable elements of the default configuration in $name.

References LocaleConfigManager\getTranslatableData(), and LocaleConfigManager\isSupported().

Referenced by LocaleConfigManager\updateConfigTranslations().

Here is the call graph for this function:

Here is the caller graph for this function:

hasTranslation (   $name,
  $langcode 
)

Checks whether a language has configuration translation.

Parameters
string$nameConfiguration name.
string$langcodeA language code.
Returns
bool A boolean indicating if a language has configuration translations.

References Drupal\languageManager().

Here is the call graph for this function:

isSupported (   $name)

Whether the given configuration is supported for interface translation.

Parameters
string$nameThe configuration name.
Returns
bool TRUE if interface translation is supported.

References LocaleConfigManager\getDefaultConfigLangcode().

Referenced by LocaleConfigManager\getTranslatableDefaultConfig().

Here is the call graph for this function:

Here is the caller graph for this function:

isUpdatingTranslationsFromLocale ( )

Indicates whether configuration translations are being updated from locale.

Returns
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.
processTranslatableData (   $name,
array  $active,
array  $translatable,
  $langcode 
)
protected

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$nameThe configuration name.
array$activeThe active configuration data.
array|\Drupal\Core\StringTranslation\TranslatableMarkup[]$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.
See Also
self::getTranslatableData().
Parameters
string$langcodeThe language code to process the array with.
Returns
array Processed translatable data array. Will only contain translations different from source strings or in case of untranslatable English, the source strings themselves.

References LocaleConfigManager\translateString().

Referenced by LocaleConfigManager\updateConfigTranslations().

Here is the call graph for this function:

Here is the caller graph for this function:

reset ( )

Reset static cache of configuration string translations.

Returns
$this
saveTranslationActive (   $name,
array  $data 
)
protected

Saves translated configuration data.

Parameters
string$nameConfiguration object name.
array$dataConfiguration data to be saved with translations merged in.

References Drupal\configFactory().

Referenced by LocaleConfigManager\updateConfigTranslations().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Saves translated configuration override.

Parameters
string$nameConfiguration object name.
string$langcodeLanguage code.
array$dataConfiguration data to be saved, that will be only the translated values.

References Drupal\languageManager().

Referenced by LocaleConfigManager\updateConfigTranslations().

Here is the call graph for this function:

Here is the caller graph for this function:

translateString (   $name,
  $langcode,
  $source,
  $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$nameName of the configuration location.
string$langcodeLanguage code to translate to.
string$sourceThe source string, should be English.
string$contextThe string context.
Returns
string|false Translated string if there is a translation, FALSE if not.

Referenced by LocaleConfigManager\getStringTranslation(), and LocaleConfigManager\processTranslatableData().

Here is the caller graph for this function:

updateConfigTranslations ( array  $names,
array  $langcodes = array() 
)

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$namesArray of names of configuration objects to update.
array$langcodes(optional) Array of language codes to update. Defaults to all configurable languages.
Returns
int Total number of configuration override and active configuration objects updated (saved or removed).

References LocaleConfigManager\deleteTranslationOverride(), LocaleConfigManager\filterOverride(), LocaleConfigManager\getActiveConfigLangcode(), LocaleConfigManager\getTranslatableDefaultConfig(), Drupal\languageManager(), NestedArray\mergeDeepArray(), LocaleConfigManager\processTranslatableData(), LocaleConfigManager\saveTranslationActive(), and LocaleConfigManager\saveTranslationOverride().

Here is the call graph for this function:


The documentation for this class was generated from the following file: