function LocaleConfigManager::getStringTranslation
Same name in other branches
- 9 core/modules/locale/src/LocaleConfigManager.php \Drupal\locale\LocaleConfigManager::getStringTranslation()
- 8.9.x core/modules/locale/src/LocaleConfigManager.php \Drupal\locale\LocaleConfigManager::getStringTranslation()
- 10 core/modules/locale/src/LocaleConfigManager.php \Drupal\locale\LocaleConfigManager::getStringTranslation()
Get the translation object for the given source/context and language.
Parameters
string $name: Name of the configuration location.
string $langcode: Language code to translate to.
string $source: The source string, should be English.
string $context: The string context.
Return value
\Drupal\locale\TranslationString|false The translation object if the string was not empty or FALSE otherwise.
File
-
core/
modules/ locale/ src/ LocaleConfigManager.php, line 438
Class
- LocaleConfigManager
- Manages configuration supported in part by interface translation.
Namespace
Drupal\localeCode
public function getStringTranslation($name, $langcode, $source, $context) {
if ($source) {
$this->translateString($name, $langcode, $source, $context);
if ($string = $this->translations[$name][$langcode][$context][$source]) {
if (!$string->isTranslation()) {
$conditions = [
'lid' => $string->lid,
'language' => $langcode,
];
$translation = $this->localeStorage
->createTranslation($conditions);
$this->translations[$name][$langcode][$context][$source] = $translation;
return $translation;
}
else {
return $string;
}
}
}
return FALSE;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.