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

TranslationExtension.php

Zuletzt modifiziert: 09.10.2024, 12:56 - Dateigröße: 3.03 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\Extension;
013   
014  use Symfony\Bridge\Twig\TokenParser\TransTokenParser;
015  use Symfony\Bridge\Twig\TokenParser\TransChoiceTokenParser;
016  use Symfony\Bridge\Twig\TokenParser\TransDefaultDomainTokenParser;
017  use Symfony\Component\Translation\TranslatorInterface;
018  use Symfony\Bridge\Twig\NodeVisitor\TranslationNodeVisitor;
019  use Symfony\Bridge\Twig\NodeVisitor\TranslationDefaultDomainNodeVisitor;
020   
021  /**
022   * Provides integration of the Translation component with Twig.
023   *
024   * @author Fabien Potencier <fabien@symfony.com>
025   */
026  class TranslationExtension extends \Twig_Extension
027  {
028      private $translator;
029      private $translationNodeVisitor;
030   
031      public function __construct(TranslatorInterface $translator, \Twig_NodeVisitorInterface $translationNodeVisitor = null)
032      {
033          if (!$translationNodeVisitor) {
034              $translationNodeVisitor = new TranslationNodeVisitor();
035          }
036   
037          $this->translator = $translator;
038          $this->translationNodeVisitor = $translationNodeVisitor;
039      }
040   
041      public function getTranslator()
042      {
043          return $this->translator;
044      }
045   
046      /**
047       * {@inheritdoc}
048       */
049      public function getFilters()
050      {
051          return array(
052              new \Twig_SimpleFilter('trans', array($this, 'trans')),
053              new \Twig_SimpleFilter('transchoice', array($this, 'transchoice')),
054          );
055      }
056   
057      /**
058       * Returns the token parser instance to add to the existing list.
059       *
060       * @return array An array of Twig_TokenParser instances
061       */
062      public function getTokenParsers()
063      {
064          return array(
065              // {% trans %}Symfony is great!{% endtrans %}
066              new TransTokenParser(),
067   
068              // {% transchoice count %}
069              //     {0} There is no apples|{1} There is one apple|]1,Inf] There is {{ count }} apples
070              // {% endtranschoice %}
071              new TransChoiceTokenParser(),
072   
073              // {% trans_default_domain "foobar" %}
074              new TransDefaultDomainTokenParser(),
075          );
076      }
077   
078      /**
079       * {@inheritdoc}
080       */
081      public function getNodeVisitors()
082      {
083          return array($this->translationNodeVisitor, new TranslationDefaultDomainNodeVisitor());
084      }
085   
086      public function getTranslationNodeVisitor()
087      {
088          return $this->translationNodeVisitor;
089      }
090   
091      public function trans($message, array $arguments = array(), $domain = null, $locale = null)
092      {
093          return $this->translator->trans($message, $arguments, $domain, $locale);
094      }
095   
096      public function transchoice($message, $count, array $arguments = array(), $domain = null, $locale = null)
097      {
098          return $this->translator->transChoice($message, $count, array_merge(array('%count%' => $count), $arguments), $domain, $locale);
099      }
100   
101      /**
102       * {@inheritdoc}
103       */
104      public function getName()
105      {
106          return 'translator';
107      }
108  }
109