Skip to content

Commit 8864ccd

Browse files
committed
[BUGFIX] Ignore localization folders
resolves #348
1 parent 268a2a7 commit 8864ccd

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

packages/typo3-docs-theme/resources/config/typo3-docs-theme.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
declare(strict_types=1);
44

55
use Brotkrueml\TwigCodeHighlight\Extension as CodeHighlight;
6+
use phpDocumentor\Guides\Event\PostCollectFilesForParsingEvent;
67
use phpDocumentor\Guides\Event\PostProjectNodeCreated;
78
use phpDocumentor\Guides\Event\PostRenderProcess;
89
use phpDocumentor\Guides\Event\PreParseProcess;
@@ -20,6 +21,7 @@
2021

2122
use T3Docs\Typo3DocsTheme\Directives\T3FieldListTableDirective;
2223
use T3Docs\Typo3DocsTheme\Directives\YoutubeDirective;
24+
use T3Docs\Typo3DocsTheme\EventListeners\IgnoreLocalizationsFolders;
2325
use T3Docs\Typo3DocsTheme\EventListeners\TestingModeActivator;
2426
use T3Docs\Typo3DocsTheme\Inventory\Typo3InventoryRepository;
2527
use T3Docs\Typo3DocsTheme\Parser\ExtendedInterlinkParser;
@@ -72,12 +74,16 @@
7274
->tag('twig.extension')
7375
->autowire()
7476

77+
// Register Event Listeners
7578
->set(AddThemeSettingsToProjectNode::class)
7679
->tag('event_listener', ['event' => PostProjectNodeCreated::class])
7780

7881
->set(CopyResources::class)
7982
->tag('event_listener', ['event' => PostRenderProcess::class])
8083

84+
->set(IgnoreLocalizationsFolders::class)
85+
->tag('event_listener', ['event' => PostCollectFilesForParsingEvent::class])
86+
8187
->set(TestingModeActivator::class)
8288
->tag('event_listener', ['event' => PreParseProcess::class]);
8389
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace T3Docs\Typo3DocsTheme\EventListeners;
4+
5+
use phpDocumentor\Guides\Event\PostCollectFilesForParsingEvent;
6+
use phpDocumentor\Guides\Files;
7+
8+
final class IgnoreLocalizationsFolder
9+
{
10+
/**
11+
* @see https://regex101.com/r/zUNAFQ/1
12+
*/
13+
private const LOCALIZATION_FOLDER_REGEX = '/^Localization\\.[a-z]+_[A-Z]+/s';
14+
public function __invoke(PostCollectFilesForParsingEvent $event): void
15+
{
16+
$files = $event->getFiles();
17+
$newFiles = new Files();
18+
foreach ($files as $filePath) {
19+
if (!preg_match(self::LOCALIZATION_FOLDER_REGEX, $filePath)) {
20+
$newFiles->add($filePath);
21+
}
22+
}
23+
$event->setFiles($newFiles);
24+
}
25+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace T3Docs\Typo3DocsTheme\EventListeners;
4+
5+
use phpDocumentor\Guides\Event\PostCollectFilesForParsingEvent;
6+
use phpDocumentor\Guides\Files;
7+
8+
final class IgnoreLocalizationsFolders
9+
{
10+
/**
11+
* Format as described here: https://docs.typo3.org/m/typo3/docs-how-to-document/main/en-us/HowToAddTranslation/Index.html
12+
* Currently only simplified tags of form xx_YY are supported.
13+
* todo: change this to BCP 47 in the future? deployment actions and language/version switch have to be changed accordingly
14+
* @see https://regex101.com/r/zUNAFQ/1
15+
*/
16+
private const LOCALIZATION_FOLDER_REGEX = '/^Localization\\.[a-z]{2}_[A-Z]{2}/s';
17+
public function __invoke(PostCollectFilesForParsingEvent $event): void
18+
{
19+
$files = $event->getFiles();
20+
$newFiles = new Files();
21+
foreach ($files as $filePath) {
22+
if (!preg_match(self::LOCALIZATION_FOLDER_REGEX, $filePath)) {
23+
$newFiles->add($filePath);
24+
}
25+
}
26+
$event->setFiles($newFiles);
27+
}
28+
}

0 commit comments

Comments
 (0)