php-translation / extractor
Extract translations form the source code
Installs: 3 738 635
Dependents: 7
Suggesters: 0
Security: 0
Stars: 126
Watchers: 8
Forks: 33
Open Issues: 16
Requires
- php: ^8.1
- doctrine/annotations: ^1.7 || ^2.0
- nikic/php-parser: ^4.0 || ^5.0
- symfony/finder: ^5.4 || ^6.4 || ^7.0
- twig/twig: ^2.0 || ^3.0
Requires (Dev)
- knplabs/knp-menu: ^3.1
- symfony/phpunit-bridge: ^5.4 || ^6.4 || ^7.0
- symfony/translation: ^5.4 || ^6.4 || ^7.0
- symfony/twig-bridge: ^5.4 || ^6.4 || ^7.0
- symfony/validator: ^5.4 || ^6.4 || ^7.0
README
Extract translation messages from source code
Install
Via Composer:
$ composer require php-translation/extractor
Usage
$extractor = new Extractor(); // Create an extractor for PHP files $fileExtractor = new PHPFileExtractor(); // Add visitors $fileExtractor->addVisitor(new ContainerAwareTrans()); $fileExtractor->addVisitor(new ContainerAwareTransChoice()); $fileExtractor->addVisitor(new FlashMessage()); $fileExtractor->addVisitor(new FormTypeChoices()); // Add the file extractor to Extactor $extractor->addFileExtractor($fileExtractor); // Define where the source code is $finder = new Finder(); $finder->in('/foo/bar'); //Start extracting files $sourceCollection = $extractor->extract($finder);
Found an issue?
Is it something we do not extract? Please add it as a test. Add a new file with your example code in
tests/Resources/Github/Issue_XX.php
, then edit the AllExtractorsTest
to make sure the translation
key is found:
// ... $this->translationExists($sc, 'trans.issue_xx');