You are here

class TranslationsDataCollector in Devel 8.3

Same name and namespace in other branches
  1. 8 webprofiler/src/DataCollector/TranslationsDataCollector.php \Drupal\webprofiler\DataCollector\TranslationsDataCollector
  2. 8.2 webprofiler/src/DataCollector/TranslationsDataCollector.php \Drupal\webprofiler\DataCollector\TranslationsDataCollector
  3. 4.x webprofiler/src/DataCollector/TranslationsDataCollector.php \Drupal\webprofiler\DataCollector\TranslationsDataCollector

Class TranslationsDataCollector.

Hierarchy

Expanded class hierarchy of TranslationsDataCollector

File

webprofiler/src/DataCollector/TranslationsDataCollector.php, line 17

Namespace

Drupal\webprofiler\DataCollector
View source
class TranslationsDataCollector extends DataCollector implements DrupalDataCollectorInterface {
  use StringTranslationTrait, DrupalDataCollectorTrait;

  /**
   * @var \Drupal\Core\StringTranslation\TranslationInterface
   */
  private $translation;

  /**
   * @var \Drupal\Core\Routing\UrlGeneratorInterface
   */
  private $urlGenerator;

  /**
   * @param \Drupal\Core\StringTranslation\TranslationInterface $translation
   * @param \Drupal\Core\Routing\UrlGeneratorInterface $urlGenerator
   */
  public function __construct(TranslationInterface $translation, UrlGeneratorInterface $urlGenerator) {
    $this->translation = $translation;
    $this->urlGenerator = $urlGenerator;
    $this->data['translations']['translated'] = [];
    $this->data['translations']['untranslated'] = [];
  }

  /**
   * {@inheritdoc}
   */
  public function collect(Request $request, Response $response, \Exception $exception = NULL) {
    if ($this->translation instanceof TranslationManagerWrapper) {

      /** \Drupal\webprofiler\StringTranslation\TranslationManagerWrapper $this->translation */
      $this->data['translations']['translated'] = $this->translation
        ->getTranslated();
      $this->data['translations']['untranslated'] = $this->translation
        ->getUntranslated();
    }
    $this->data['user_interface_translations_path'] = $this->urlGenerator
      ->generateFromRoute('locale.translate_page');
  }

  /**
   * @return int
   */
  public function getTranslatedCount() {
    return count($this->data['translations']['translated']);
  }

  /**
   * @return int
   */
  public function getUntranslatedCount() {
    return count($this->data['translations']['untranslated']);
  }

  /**
   * {@inheritdoc}
   */
  public function getName() {
    return 'translations';
  }

  /**
   * {@inheritdoc}
   */
  public function getTitle() {
    return $this
      ->t('Translations');
  }

  /**
   * {@inheritdoc}
   */
  public function getPanelSummary() {
    return $this
      ->t('Translated: @translated, untranslated: @untranslated', [
      '@translated' => $this
        ->getTranslatedCount(),
      '@untranslated' => $this
        ->getUntranslatedCount(),
    ]);
  }

  /**
   * {@inheritdoc}
   */
  public function getIcon() {
    return 'iVBORw0KGgoAAAANSUhEUgAAABUAAAAcCAYAAACOGPReAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAgpJREFUeNrUVrFuwjAQPUcZiAQDQ6WEbgwwMCJVqhjgBxhYGSvEDzBkZYSBH+ADoFJHlg4MdIMKxiLBXKAbUmEm9bPiyAREEgRDTzqZ2Mfzu7tnJ8xxHLq1aXQHuwsos2078p9arVYg0yL3CXcnwCdubKDp3F+5myFin9xYK0xNzQiZm1c3KpVKUb1ep2QyebvuFwoFSqfTlM/nbweay+VoOBxeDar7JwC03W49UO5fs9nsZTwef8qYUqkUjSmAYrGYqKlhGFSpVH45oBFFdkdM0RjUst1uC7Z45ofjWdO0t8Ph8CDjyuUyZTIZ6na7tNvtTmSn+2s5n88FIMwdPzhgUWYBA2A2mxVjIpEQarEsiwaDAS2XSxPH9OI1xVNnbmo0Go28eTDkAOL3YrGg/X4v1tfr9WmjLplsULVaFawbjYbHkjfzqPsr7o9RwJE2HOkifbAGS1ljdL/G/ScsWK/XE+NmsxGMkW6/3xfgWMMIpu9hLgkEN5tNDwClgAoADjAYRszr8m7kD2gGU5uh1hEjmoGUUU/oGLVEXaVhA2yoKYAwRwFx/Ezj8bjHEIYaSgVgDptNp1NiePG5QCfS4qyZXANop9MR7JANWAFA6hWgWEcmqqTYOWBVl0jZf0ViU+hUNk0AyVf0ObYK0+8IslupF8qlkxVWdoipsaCPiaBr7uwr+t98ofwJMADuIP9IDjFbLwAAAABJRU5ErkJggg==';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalDataCollectorInterface::getData public function 8
DrupalDataCollectorInterface::getDrupalSettings public function 1
DrupalDataCollectorInterface::getLibraries public function Returns the libraries needed in detail panel. 2
DrupalDataCollectorInterface::hasPanel public function Returns true if this datacollector has a detail panel. 2
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
TranslationsDataCollector::$translation private property
TranslationsDataCollector::$urlGenerator private property
TranslationsDataCollector::collect public function Collects data for the given Request and Response.
TranslationsDataCollector::getIcon public function Returns the collector icon in base64 format. Overrides DrupalDataCollectorInterface::getIcon
TranslationsDataCollector::getName public function Returns the name of the collector. Overrides DrupalDataCollectorInterface::getName
TranslationsDataCollector::getPanelSummary public function Returns the string used in vertical tab summary. Overrides DrupalDataCollectorInterface::getPanelSummary
TranslationsDataCollector::getTitle public function Returns the datacollector title. Overrides DrupalDataCollectorInterface::getTitle
TranslationsDataCollector::getTranslatedCount public function
TranslationsDataCollector::getUntranslatedCount public function
TranslationsDataCollector::__construct public function