You are here

class TranslationManagerWrapper in Devel 8

Same name and namespace in other branches
  1. 8.3 webprofiler/src/StringTranslation/TranslationManagerWrapper.php \Drupal\webprofiler\StringTranslation\TranslationManagerWrapper
  2. 8.2 webprofiler/src/StringTranslation/TranslationManagerWrapper.php \Drupal\webprofiler\StringTranslation\TranslationManagerWrapper
  3. 4.x webprofiler/src/StringTranslation/TranslationManagerWrapper.php \Drupal\webprofiler\StringTranslation\TranslationManagerWrapper

Class TranslationManagerWrapper

Hierarchy

Expanded class hierarchy of TranslationManagerWrapper

1 file declares its use of TranslationManagerWrapper
TranslationsDataCollector.php in webprofiler/src/DataCollector/TranslationsDataCollector.php

File

webprofiler/src/StringTranslation/TranslationManagerWrapper.php, line 10

Namespace

Drupal\webprofiler\StringTranslation
View source
class TranslationManagerWrapper extends TranslationManager {

  /**
   * @var \Drupal\webprofiler\StringTranslation\TranslationManagerWrapper
   */
  private $translationManager;

  /**
   * @var array
   */
  private $translated;

  /**
   * @var array
   */
  private $untranslated;

  /**
   * @param \Drupal\webprofiler\StringTranslation\TranslationManagerWrapper $translationManager
   */
  public function setDataCollector(TranslationManagerWrapper $translationManager) {
    $this->translationManager = $translationManager;
  }

  /**
   * {@inheritdoc}
   */
  protected function doTranslate($string, array $options = array()) {

    // Merge in defaults.
    if (empty($options['langcode'])) {
      $options['langcode'] = $this->defaultLangcode;
    }
    if (empty($options['context'])) {
      $options['context'] = '';
    }
    $translation = $this
      ->getStringTranslation($options['langcode'], $string, $options['context']);
    if ($translation) {
      $this->translated[$string] = $translation;
    }
    else {
      $this->untranslated[$string] = $string;
    }
    return $translation === FALSE ? $string : $translation;
  }

  /**
   * @return array
   */
  public function getTranslated() {
    return $this->translated;
  }

  /**
   * @return array
   */
  public function getUntranslated() {
    return $this->untranslated;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TranslationManager::$defaultLangcode protected property The default langcode used in translations.
TranslationManager::$sortedTranslators protected property An array of translators, sorted by priority.
TranslationManager::$translators protected property An unsorted array of arrays of active translators.
TranslationManager::addTranslator public function Appends a translation system to the translation chain.
TranslationManager::formatPlural public function Formats a string containing a count of items. Overrides TranslationInterface::formatPlural
TranslationManager::getStringTranslation public function Retrieves English string to given language. Overrides TranslatorInterface::getStringTranslation
TranslationManager::reset public function Resets translation cache. Overrides TranslatorInterface::reset
TranslationManager::setDefaultLangcode public function Sets the default langcode.
TranslationManager::sortTranslators protected function Sorts translators according to priority.
TranslationManager::translate public function Translates a string to the current language or to a given language. Overrides TranslationInterface::translate
TranslationManager::translateString public function Translates a TranslatableMarkup object to a string. Overrides TranslationInterface::translateString
TranslationManager::__construct public function Constructs a TranslationManager object. 1
TranslationManagerWrapper::$translated private property
TranslationManagerWrapper::$translationManager private property
TranslationManagerWrapper::$untranslated private property
TranslationManagerWrapper::doTranslate protected function Translates a string to the current language or to a given language. Overrides TranslationManager::doTranslate
TranslationManagerWrapper::getTranslated public function
TranslationManagerWrapper::getUntranslated public function
TranslationManagerWrapper::setDataCollector public function