Extract translations form the source code

2.0.4 2022-01-26 13:39 UTC


Latest Version Build Status Code Coverage Quality Score SensioLabsInsight Total Downloads

Extract translation messages from source code


Via Composer

$ composer require php-translation/extractor


$extractor = new Extractor();

// Create 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

// Define where the source code is
$finder = new Finder();

//Start extracting files
$sourceCollection = $extractor->extract($finder);

Found an issue?

Is it something we do not extract? Please add it as a tests. 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');