You are here

public function LocaleTranslation::getStringTranslation in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/locale/src/LocaleTranslation.php \Drupal\locale\LocaleTranslation::getStringTranslation()

Retrieves English string to given language.

Parameters

string $langcode: Language code to translate to.

string $string: The source string.

string $context: The string context.

Return value

string|FALSE Translated string if there is a translation, FALSE if not.

Overrides TranslatorInterface::getStringTranslation

File

core/modules/locale/src/LocaleTranslation.php, line 113
Contains \Drupal\locale\LocaleTranslation.

Class

LocaleTranslation
String translator using the locale module.

Namespace

Drupal\locale

Code

public function getStringTranslation($langcode, $string, $context) {

  // If the language is not suitable for locale module, just return.
  if ($langcode == LanguageInterface::LANGCODE_SYSTEM || $langcode == 'en' && !$this
    ->canTranslateEnglish()) {
    return FALSE;
  }

  // Strings are cached by langcode, context and roles, using instances of the
  // LocaleLookup class to handle string lookup and caching.
  if (!isset($this->translations[$langcode][$context])) {
    $this->translations[$langcode][$context] = new LocaleLookup($langcode, $context, $this->storage, $this->cache, $this->lock, $this->configFactory, $this->languageManager, $this->requestStack);
  }
  $translation = $this->translations[$langcode][$context]
    ->get($string);
  return $translation === TRUE ? FALSE : $translation;
}