Drupal 8  8.0.2
LocaleConfigSubscriber Class Reference
Inheritance diagram for LocaleConfigSubscriber:

Public Member Functions

 __construct (ConfigFactoryInterface $config_factory, LocaleConfigManager $locale_config_manager)
 
 onConfigSave (ConfigCrudEvent $event)
 
 onOverrideChange (LanguageConfigOverrideCrudEvent $event)
 

Static Public Member Functions

static getSubscribedEvents ()
 

Protected Member Functions

 updateLocaleStorage (StorableConfigBase $config, $langcode, array $reference_config=array())
 
 processTranslatableData ($name, array $config, array $translatable, $langcode, array $reference_config=array())
 
 resetExistingTranslations ($name, $translatable, $reference_config, $langcode)
 
 saveCustomizedTranslation ($name, $source, $context, $new_translation, $langcode)
 

Protected Attributes

 $configFactory
 
 $localeConfigManager
 

Detailed Description

Updates strings translation when configuration translations change.

This reacts to the updates of translated active configuration and configuration language overrides. When those updates involve configuration which was available as default configuration, we need to feed back changes to any item which was originally part of that configuration to the interface translation storage. Those updated translations are saved as customized, so further community translation updates will not undo user changes.

This subscriber does not respond to deleting active configuration or deleting configuration translations. The locale storage is additive and we cannot be sure that only a given configuration translation used a source string. So we should not remove the translations from locale storage in these cases. The configuration or override would itself be deleted either way.

By design locale module only deals with sources in English.

See Also

Constructor & Destructor Documentation

__construct ( ConfigFactoryInterface  $config_factory,
LocaleConfigManager  $locale_config_manager 
)

Constructs a LocaleConfigSubscriber.

Parameters
\Drupal\Core\Config\ConfigFactoryInterface$config_factoryThe configuration factory.
\Drupal\locale\LocaleConfigManager$locale_config_managerThe typed configuration manager.

References Drupal\configFactory().

Here is the call graph for this function:

Member Function Documentation

static getSubscribedEvents ( )
static
onConfigSave ( ConfigCrudEvent  $event)

Updates the locale strings when a translated active configuration is saved.

Parameters
\Drupal\Core\Config\ConfigCrudEvent$eventThe configuration event.

References ConfigCrudEvent\getConfig(), and LocaleConfigSubscriber\updateLocaleStorage().

Here is the call graph for this function:

onOverrideChange ( LanguageConfigOverrideCrudEvent  $event)

Updates the locale strings when a configuration override is saved/deleted.

Parameters
\Drupal\language\Config\LanguageConfigOverrideCrudEvent$eventThe language configuration event.

References Drupal\configFactory(), LanguageConfigOverrideCrudEvent\getLanguageConfigOverride(), and LocaleConfigSubscriber\updateLocaleStorage().

Here is the call graph for this function:

processTranslatableData (   $name,
array  $config,
array  $translatable,
  $langcode,
array  $reference_config = array() 
)
protected

Process the translatable data array with a given language.

Parameters
string$nameThe configuration name.
array$configThe active configuration data or override data.
array|\Drupal\Core\StringTranslation\TranslatableMarkup[]$translatable The translatable array structure.
See Also
::getTranslatableData()
Parameters
string$langcodeThe language code to process the array with.
array$reference_config(Optional) Reference configuration to check against if $config was an override. This allows us to update locale keys for data not in the override but still in the active configuration.

References LocaleConfigSubscriber\resetExistingTranslations(), and LocaleConfigSubscriber\saveCustomizedTranslation().

Referenced by LocaleConfigSubscriber\updateLocaleStorage().

Here is the call graph for this function:

Here is the caller graph for this function:

resetExistingTranslations (   $name,
  $translatable,
  $reference_config,
  $langcode 
)
protected

Reset existing locale translations to their source values.

Goes through $translatable to reset any existing translations to the source string, so prior translations would not reappear in the configuration.

Parameters
string$nameThe configuration name.
array | \Drupal\Core\StringTranslation\TranslatableMarkup$translatableEither a possibly nested array with TranslatableMarkup objects at the leaf items or a TranslatableMarkup object directly.
array | string$reference_configEither a possibly nested array with strings at the leaf items or a string directly. Only those $translatable items that are also present in $reference_config will get translations reset.
string$langcodeThe language code of the translation being processed.

References LocaleConfigSubscriber\saveCustomizedTranslation().

Referenced by LocaleConfigSubscriber\processTranslatableData().

Here is the call graph for this function:

Here is the caller graph for this function:

saveCustomizedTranslation (   $name,
  $source,
  $context,
  $new_translation,
  $langcode 
)
protected

Saves a translation string and marks it as customized.

Parameters
string$nameThe configuration name.
string$sourceThe source string value.
string$contextThe source string context.
string$new_translationThe translation string.
string$langcodeThe language code of the translation.

Referenced by LocaleConfigSubscriber\processTranslatableData(), and LocaleConfigSubscriber\resetExistingTranslations().

Here is the caller graph for this function:

updateLocaleStorage ( StorableConfigBase  $config,
  $langcode,
array  $reference_config = array() 
)
protected

Update locale storage based on configuration translations.

Parameters
\Drupal\Core\Config\StorableConfigBase$configActive configuration or configuration translation override.
string$langcodeThe language code of $config.
array$reference_config(Optional) Reference configuration to check against if $config was an override. This allows us to update locale keys for data not in the override but still in the active configuration.

References ConfigBase\get(), ConfigBase\getName(), and LocaleConfigSubscriber\processTranslatableData().

Referenced by LocaleConfigSubscriber\onConfigSave(), and LocaleConfigSubscriber\onOverrideChange().

Here is the call graph for this function:

Here is the caller graph for this function:


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