function LocaleConfigSubscriberTest::saveLocaleTranslationData

Same name in other branches
  1. 8.9.x core/modules/locale/tests/src/Kernel/LocaleConfigSubscriberTest.php \Drupal\Tests\locale\Kernel\LocaleConfigSubscriberTest::saveLocaleTranslationData()
  2. 10 core/modules/locale/tests/src/Kernel/LocaleConfigSubscriberTest.php \Drupal\Tests\locale\Kernel\LocaleConfigSubscriberTest::saveLocaleTranslationData()
  3. 11.x core/modules/locale/tests/src/Kernel/LocaleConfigSubscriberTest.php \Drupal\Tests\locale\Kernel\LocaleConfigSubscriberTest::saveLocaleTranslationData()

Saves translation data from locale module.

This will invoke LocaleConfigSubscriber through the event dispatcher. To make sure the configuration was persisted correctly, the configuration value is checked. Because LocaleConfigSubscriber temporarily disables the override state of the configuration factory we check that the correct value is restored afterwards.

Parameters

string $config_name: The configuration name.

string $key: The configuration key.

string $source: The source string.

string $translation: The translation string to save.

string $langcode: The language code.

bool $is_active: Whether the update will affect the active configuration.

5 calls to LocaleConfigSubscriberTest::saveLocaleTranslationData()
LocaleConfigSubscriberForeignTest::testEnglish in core/modules/locale/tests/src/Kernel/LocaleConfigSubscriberForeignTest.php
Tests that adding English creates a translation override.
LocaleConfigSubscriberForeignTest::testLocaleCreateActiveTranslation in core/modules/locale/tests/src/Kernel/LocaleConfigSubscriberForeignTest.php
Tests importing community translations of shipped configuration.
LocaleConfigSubscriberForeignTest::testLocaleUpdateActiveTranslation in core/modules/locale/tests/src/Kernel/LocaleConfigSubscriberForeignTest.php
Tests updating community translations of shipped configuration.
LocaleConfigSubscriberTest::testLocaleCreateTranslation in core/modules/locale/tests/src/Kernel/LocaleConfigSubscriberTest.php
Tests importing community translations of shipped configuration.
LocaleConfigSubscriberTest::testLocaleUpdateTranslation in core/modules/locale/tests/src/Kernel/LocaleConfigSubscriberTest.php
Tests updating community translations of shipped configuration.

File

core/modules/locale/tests/src/Kernel/LocaleConfigSubscriberTest.php, line 304

Class

LocaleConfigSubscriberTest
Tests that shipped configuration translations are updated correctly.

Namespace

Drupal\Tests\locale\Kernel

Code

protected function saveLocaleTranslationData($config_name, $key, $source, $translation, $langcode, $is_active = FALSE) {
    $this->localeConfigManager
        ->reset();
    $this->localeConfigManager
        ->getStringTranslation($config_name, $langcode, $source, '')
        ->setString($translation)
        ->save();
    $this->localeConfigManager
        ->reset();
    $this->localeConfigManager
        ->updateConfigTranslations([
        $config_name,
    ], [
        $langcode,
    ]);
    $this->configFactory
        ->reset($config_name);
    if ($is_active) {
        $this->assertActiveConfig($config_name, $key, $translation, $langcode);
    }
    else {
        $this->assertConfigOverride($config_name, $key, $translation, $langcode);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.