https://github.com/php-translation/extractor
Extracts translation strings from source code
https://github.com/php-translation/extractor
Last synced: about 1 year ago
JSON representation
Extracts translation strings from source code
- Host: GitHub
- URL: https://github.com/php-translation/extractor
- Owner: php-translation
- License: mit
- Created: 2016-11-27T17:10:12.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-10-02T18:11:10.000Z (over 1 year ago)
- Last Synced: 2025-03-30T09:02:02.228Z (about 1 year ago)
- Language: PHP
- Homepage:
- Size: 295 KB
- Stars: 127
- Watchers: 7
- Forks: 33
- Open Issues: 17
-
Metadata Files:
- Readme: Readme.md
- Changelog: Changelog.md
- License: LICENSE
Awesome Lists containing this project
README
# Translation extractor
[](https://github.com/php-translation/extractor/releases)
[](https://packagist.org/packages/php-translation/extractor)
**Extract translation messages from source code**
## Install
Via Composer:
```bash
$ composer require php-translation/extractor
```
## Usage
```php
$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:
```php
// ...
$this->translationExists($sc, 'trans.issue_xx');
```