Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
TwigExtractor.php
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\Translation;
013
014 use Symfony\Component\Finder\Finder;
015 use Symfony\Component\Translation\Extractor\AbstractFileExtractor;
016 use Symfony\Component\Translation\Extractor\ExtractorInterface;
017 use Symfony\Component\Translation\MessageCatalogue;
018 use Twig\Environment;
019 use Twig\Error\Error;
020 use Twig\Source;
021
022 /**
023 * TwigExtractor extracts translation messages from a twig template.
024 *
025 * @author Michel Salib <michelsalib@hotmail.com>
026 * @author Fabien Potencier <fabien@symfony.com>
027 */
028 class TwigExtractor extends AbstractFileExtractor implements ExtractorInterface
029 {
030 /**
031 * Default domain for found messages.
032 *
033 * @var string
034 */
035 private $defaultDomain = 'messages';
036
037 /**
038 * Prefix for found message.
039 *
040 * @var string
041 */
042 private $prefix = '';
043
044 private $twig;
045
046 public function __construct(Environment $twig)
047 {
048 $this->twig = $twig;
049 }
050
051 /**
052 * {@inheritdoc}
053 */
054 public function extract($resource, MessageCatalogue $catalogue)
055 {
056 foreach ($this->extractFiles($resource) as $file) {
057 try {
058 $this->extractTemplate(file_get_contents($file->getPathname()), $catalogue);
059 } catch (Error $e) {
060 // ignore errors, these should be fixed by using the linter
061 }
062 }
063 }
064
065 /**
066 * {@inheritdoc}
067 */
068 public function setPrefix($prefix)
069 {
070 $this->prefix = $prefix;
071 }
072
073 protected function extractTemplate($template, MessageCatalogue $catalogue)
074 {
075 $visitor = $this->twig->getExtension('Symfony\Bridge\Twig\Extension\TranslationExtension')->getTranslationNodeVisitor();
076 $visitor->enable();
077
078 $this->twig->parse($this->twig->tokenize(new Source($template, '')));
079
080 foreach ($visitor->getMessages() as $message) {
081 $catalogue->set(trim($message[0]), $this->prefix.trim($message[0]), $message[1] ?: $this->defaultDomain);
082 }
083
084 $visitor->disable();
085 }
086
087 /**
088 * @param string $file
089 *
090 * @return bool
091 */
092 protected function canBeExtracted($file)
093 {
094 return $this->isFile($file) && 'twig' === pathinfo($file, \PATHINFO_EXTENSION);
095 }
096
097 /**
098 * {@inheritdoc}
099 */
100 protected function extractFromDirectory($directory)
101 {
102 $finder = new Finder();
103
104 return $finder->files()->name('*.twig')->in($directory);
105 }
106 }
107