function ConfigTranslationUiTestBase::getTranslation

Same name and namespace in other branches
  1. 11.x core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTestBase.php \Drupal\Tests\config_translation\Functional\ConfigTranslationUiTestBase::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 ConfigTranslationUiTestBase::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/ConfigTranslationUiTestBase.php, line 136

Class

ConfigTranslationUiTestBase
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->assertNotEmpty($settings_locations, "{$config_name} should have configuration locations.");
  if ($settings_locations) {
    $source = $this->container
      ->get('config.factory')
      ->get($config_name)
      ->get($key);
    $source_string = $this->localeStorage
      ->findString([
      'source' => $source,
      'type' => 'configuration',
    ]);
    $this->assertNotEmpty($source_string, "{$config_name}.{$key} should have a source string.");
    if ($source_string) {
      $conditions = [
        'lid' => $source_string->lid,
        'language' => $langcode,
      ];
      $translations = $this->localeStorage
        ->getTranslations($conditions + [
        'translated' => TRUE,
      ]);
      return reset($translations);
    }
  }
  return FALSE;
}

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