function ConfigTranslationUiTest::getTranslation
Same name in other branches
- 9 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 - Test translation storage in locale storage.
File
-
core/
modules/ config_translation/ tests/ src/ Functional/ ConfigTranslationUiTest.php, line 1090
Class
- ConfigTranslationUiTest
- Translate settings and entities to various languages.
Namespace
Drupal\Tests\config_translation\FunctionalCode
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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.