class ConfigImportLocaleSubscriber in Locale: Config import 8
This class extends the LocaleConfigSubscriber in Drupal\locale.
The only function that is overwritten is updateLocaleStorage, to make sure it respects the overwrite_interface_translation setting of this module.
Hierarchy
- class \Drupal\locale\LocaleConfigSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\config_import_locale\ConfigImportLocaleSubscriber
Expanded class hierarchy of ConfigImportLocaleSubscriber
See also
\Drupal\locale\LocaleConfigSubscriber
File
- src/
ConfigImportLocaleSubscriber.php, line 15
Namespace
Drupal\config_import_localeView source
class ConfigImportLocaleSubscriber extends LocaleConfigSubscriber {
/**
* Saves a translation string and marks it as customized.
*
* We overwrite this function to make sure it checks the
* overwrite_interface_translation setting of this module.
*/
protected function saveCustomizedTranslation($name, $source, $context, $new_translation, $langcode) {
// Load our config.
$config_import_locale_config = \Drupal::config('config_import_locale.settings');
$overwrite = $config_import_locale_config
->get('overwrite_interface_translation');
// Call the correct function, based on our config.
switch ($overwrite) {
case 'no_overwrite':
$this
->saveCustomizedTranslationNoOverwrite($name, $source, $context, $new_translation, $langcode);
break;
case 'nothing':
// Do nothing.
break;
default:
parent::saveCustomizedTranslation($name, $source, $context, $new_translation, $langcode);
}
}
/**
* Updates an interface translation if no previous translation is set.
*
* Code is basically the same as
* LocaleConfigSubscriber::saveCustomizedTranslation, but with a more
* restrictive if-structure.
*/
protected function saveCustomizedTranslationNoOverwrite($name, $source, $context, $new_translation, $langcode) {
$locale_translation = $this->localeConfigManager
->getStringTranslation($name, $langcode, $source, $context);
if (!empty($locale_translation)) {
$existing_translation = $locale_translation
->getString();
if ($locale_translation
->isNew() && $source != $new_translation || !$locale_translation
->isNew() && empty($existing_translation) && $source != $new_translation) {
$locale_translation
->setString($new_translation)
->setCustomized(TRUE)
->save();
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigImportLocaleSubscriber:: |
protected | function |
Saves a translation string and marks it as customized. Overrides LocaleConfigSubscriber:: |
|
ConfigImportLocaleSubscriber:: |
protected | function | Updates an interface translation if no previous translation is set. | |
LocaleConfigSubscriber:: |
protected | property | The configuration factory. | |
LocaleConfigSubscriber:: |
protected | property | The typed configuration manager. | |
LocaleConfigSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
LocaleConfigSubscriber:: |
public | function | Updates the locale strings when a translated active configuration is saved. | |
LocaleConfigSubscriber:: |
public | function | Updates the locale strings when a configuration override is saved/deleted. | |
LocaleConfigSubscriber:: |
protected | function | Process the translatable data array with a given language. | |
LocaleConfigSubscriber:: |
protected | function | Reset existing locale translations to their source values. | |
LocaleConfigSubscriber:: |
protected | function | Update locale storage based on configuration translations. | |
LocaleConfigSubscriber:: |
public | function | Constructs a LocaleConfigSubscriber. |