You are here

public function LocaleConfigManager::getStringTranslation in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 433
Contains \Drupal\locale\LocaleConfigManager.

Class

LocaleConfigManager
Manages configuration supported in part by interface translation.

Namespace

Drupal\locale

Code

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 = array(
          'lid' => $string->lid,
          'language' => $langcode,
        );
        $translation = $this->localeStorage
          ->createTranslation($conditions);
        $this->translations[$name][$langcode][$context][$source] = $translation;
        return $translation;
      }
      else {
        return $string;
      }
    }
  }
  return FALSE;
}