You are here

protected function ConfigTranslationUiTest::getTranslation in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php \Drupal\Tests\config_translation\Functional\ConfigTranslationUiTest::getTranslation()

Gets translation from locale storage.

Parameters

$config_name: Configuration object.

$key: Translation configuration field key.

$langcode: String language code to load translation.

Return value

bool|mixed Returns translation if exists, FALSE otherwise.

1 call to ConfigTranslationUiTest::getTranslation()
ConfigTranslationUiTest::testLocaleDBStorage in core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php
Tests translation storage in locale storage.

File

core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php, line 1125

Class

ConfigTranslationUiTest
Translate settings and entities to various languages.

Namespace

Drupal\Tests\config_translation\Functional

Code

protected function getTranslation($config_name, $key, $langcode) {
  $settings_locations = $this->localeStorage
    ->getLocations([
    'type' => 'configuration',
    'name' => $config_name,
  ]);
  $this
    ->assertTrue(!empty($settings_locations), new FormattableMarkup('Configuration locations found for %config_name.', [
    '%config_name' => $config_name,
  ]));
  if (!empty($settings_locations)) {
    $source = $this->container
      ->get('config.factory')
      ->get($config_name)
      ->get($key);
    $source_string = $this->localeStorage
      ->findString([
      'source' => $source,
      'type' => 'configuration',
    ]);
    $this
      ->assertTrue(!empty($source_string), new FormattableMarkup('Found string for %config_name.%key.', [
      '%config_name' => $config_name,
      '%key' => $key,
    ]));
    if (!empty($source_string)) {
      $conditions = [
        'lid' => $source_string->lid,
        'language' => $langcode,
      ];
      $translations = $this->localeStorage
        ->getTranslations($conditions + [
        'translated' => TRUE,
      ]);
      return reset($translations);
    }
  }
  return FALSE;
}