Skip to content

Commit

Permalink
extract commments from code #6
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Nov 20, 2019
1 parent 46f051c commit cde9672
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.1.1] - Unreleased
### Fixed
- Extract comments of functions prepended with echo, print or return [#6]
- Tested extracted comments from code

## [1.1.0] - 2019-11-19
### Added
- In v1.0, non-scalar arguments (others than string, int and float) were discarded. Now the arrays are included too [#5]
Expand All @@ -18,6 +23,8 @@ First version

[#1]: https://github.com/php-gettext/PHP-Scanner/issues/1
[#5]: https://github.com/php-gettext/PHP-Scanner/issues/5
[#6]: https://github.com/php-gettext/PHP-Scanner/issues/6

[1.1.1]: https://github.com/php-gettext/PHP-Scanner/compare/v1.1.0...HEAD
[1.1.0]: https://github.com/php-gettext/PHP-Scanner/compare/v1.0.1...v1.1.0
[1.0.1]: https://github.com/php-gettext/PHP-Scanner/compare/v1.0.0...v1.0.1
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ $phpScanner = new PhpScanner(
Translations::create('domain3')
);

//Set a default domain, so any translations with no domain specified, will be added to that domain
$phpScanner->setDefaultDomain('domain1');

//Extract all comments starting with 'i18n:' and 'Translators:'
$phpScanner->extractCommentsStartingWith('i18n:', 'Translators:');

//Scan files
foreach (glob('*.php') as $file) {
$phpScanner->scanFile($file);
Expand All @@ -38,8 +44,7 @@ foreach (glob('*.php') as $file) {
//Save the translations in .po files
$generator = new PoGenerator();

foreach ($phpScanner->getTranslations() as $translations) {
$domain = $translations->getDomain();
foreach ($phpScanner->getTranslations() as $domain => $translations) {
$generator->generateFile($translations, "locales/{$domain}.po");
}
```
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"require": {
"php": "^7.2",
"nikic/php-parser": "^4.2",
"gettext/gettext": "^5.1"
"gettext/gettext": "dev-master"
},
"require-dev": {
"phpunit/phpunit": "^8.0",
Expand Down
7 changes: 7 additions & 0 deletions tests/PhpScannerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,18 @@ public function testPhpCodeScanner()
$this->assertCount(1, $domain3);

$scanner->setDefaultDomain('domain1');
$scanner->extractCommentsStartingWith('');
$scanner->scanFile($file);

$this->assertCount(39, $domain1);
$this->assertCount(4, $domain2);
$this->assertCount(1, $domain3);

//Extract comments
$translation = $domain1->find('CONTEXT', 'All comments');
$this->assertNotNull($translation);
$this->assertSame([$file => [66]], $translation->getReferences()->toArray());
$this->assertCount(1, $translation->getExtractedComments());
}

public function testInvalidFunction()
Expand Down

0 comments on commit cde9672

Please sign in to comment.