Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

TranslationNodeVisitor.php

Zuletzt modifiziert: 09.10.2024, 12:56 - Dateigröße: 3.48 KiB


 001  <?php
 002   
 003  /*
 004   * This file is part of the Symfony package.
 005   *
 006   * (c) Fabien Potencier <fabien@symfony.com>
 007   *
 008   * For the full copyright and license information, please view the LICENSE
 009   * file that was distributed with this source code.
 010   */
 011   
 012  namespace Symfony\Bridge\Twig\NodeVisitor;
 013   
 014  use Symfony\Bridge\Twig\Node\TransNode;
 015   
 016  /**
 017   * TranslationNodeVisitor extracts translation messages.
 018   *
 019   * @author Fabien Potencier <fabien@symfony.com>
 020   */
 021  class TranslationNodeVisitor extends \Twig_BaseNodeVisitor
 022  {
 023      const UNDEFINED_DOMAIN = '_undefined';
 024   
 025      private $enabled = false;
 026      private $messages = array();
 027   
 028      public function enable()
 029      {
 030          $this->enabled = true;
 031          $this->messages = array();
 032      }
 033   
 034      public function disable()
 035      {
 036          $this->enabled = false;
 037          $this->messages = array();
 038      }
 039   
 040      public function getMessages()
 041      {
 042          return $this->messages;
 043      }
 044   
 045      /**
 046       * {@inheritdoc}
 047       */
 048      protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env)
 049      {
 050          if (!$this->enabled) {
 051              return $node;
 052          }
 053   
 054          if (
 055              $node instanceof \Twig_Node_Expression_Filter &&
 056              'trans' === $node->getNode('filter')->getAttribute('value') &&
 057              $node->getNode('node') instanceof \Twig_Node_Expression_Constant
 058          ) {
 059              // extract constant nodes with a trans filter
 060              $this->messages[] = array(
 061                  $node->getNode('node')->getAttribute('value'),
 062                  $this->getReadDomainFromArguments($node->getNode('arguments'), 1),
 063              );
 064          } elseif (
 065              $node instanceof \Twig_Node_Expression_Filter &&
 066              'transchoice' === $node->getNode('filter')->getAttribute('value') &&
 067              $node->getNode('node') instanceof \Twig_Node_Expression_Constant
 068          ) {
 069              // extract constant nodes with a trans filter
 070              $this->messages[] = array(
 071                  $node->getNode('node')->getAttribute('value'),
 072                  $this->getReadDomainFromArguments($node->getNode('arguments'), 2),
 073              );
 074          } elseif ($node instanceof TransNode) {
 075              // extract trans nodes
 076              $this->messages[] = array(
 077                  $node->getNode('body')->getAttribute('data'),
 078                  $this->getReadDomainFromNode($node->getNode('domain')),
 079              );
 080          }
 081   
 082          return $node;
 083      }
 084   
 085      /**
 086       * {@inheritdoc}
 087       */
 088      protected function doLeaveNode(\Twig_Node $node, \Twig_Environment $env)
 089      {
 090          return $node;
 091      }
 092   
 093      /**
 094       * {@inheritdoc}
 095       */
 096      public function getPriority()
 097      {
 098          return 0;
 099      }
 100   
 101      /**
 102       * @param \Twig_Node $arguments
 103       * @param int        $index
 104       *
 105       * @return string|null
 106       */
 107      private function getReadDomainFromArguments(\Twig_Node $arguments, $index)
 108      {
 109          if ($arguments->hasNode('domain')) {
 110              $argument = $arguments->getNode('domain');
 111          } elseif ($arguments->hasNode($index)) {
 112              $argument = $arguments->getNode($index);
 113          } else {
 114              return;
 115          }
 116   
 117          return $this->getReadDomainFromNode($argument);
 118      }
 119   
 120      /**
 121       * @param \Twig_Node $node
 122       *
 123       * @return string|null
 124       */
 125      private function getReadDomainFromNode(\Twig_Node $node = null)
 126      {
 127          if (null === $node) {
 128              return;
 129          }
 130   
 131          if ($node instanceof \Twig_Node_Expression_Constant) {
 132              return $node->getAttribute('value');
 133          }
 134   
 135          return self::UNDEFINED_DOMAIN;
 136      }
 137  }
 138