Skip to content

Commit cde9672

Browse files
committed
extract commments from code #6
1 parent 46f051c commit cde9672

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [1.1.1] - Unreleased
9+
### Fixed
10+
- Extract comments of functions prepended with echo, print or return [#6]
11+
- Tested extracted comments from code
12+
813
## [1.1.0] - 2019-11-19
914
### Added
1015
- In v1.0, non-scalar arguments (others than string, int and float) were discarded. Now the arrays are included too [#5]
@@ -18,6 +23,8 @@ First version
1823

1924
[#1]: https://github.com/php-gettext/PHP-Scanner/issues/1
2025
[#5]: https://github.com/php-gettext/PHP-Scanner/issues/5
26+
[#6]: https://github.com/php-gettext/PHP-Scanner/issues/6
2127

28+
[1.1.1]: https://github.com/php-gettext/PHP-Scanner/compare/v1.1.0...HEAD
2229
[1.1.0]: https://github.com/php-gettext/PHP-Scanner/compare/v1.0.1...v1.1.0
2330
[1.0.1]: https://github.com/php-gettext/PHP-Scanner/compare/v1.0.0...v1.0.1

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ $phpScanner = new PhpScanner(
3030
Translations::create('domain3')
3131
);
3232

33+
//Set a default domain, so any translations with no domain specified, will be added to that domain
34+
$phpScanner->setDefaultDomain('domain1');
35+
36+
//Extract all comments starting with 'i18n:' and 'Translators:'
37+
$phpScanner->extractCommentsStartingWith('i18n:', 'Translators:');
38+
3339
//Scan files
3440
foreach (glob('*.php') as $file) {
3541
$phpScanner->scanFile($file);
@@ -38,8 +44,7 @@ foreach (glob('*.php') as $file) {
3844
//Save the translations in .po files
3945
$generator = new PoGenerator();
4046

41-
foreach ($phpScanner->getTranslations() as $translations) {
42-
$domain = $translations->getDomain();
47+
foreach ($phpScanner->getTranslations() as $domain => $translations) {
4348
$generator->generateFile($translations, "locales/{$domain}.po");
4449
}
4550
```

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"require": {
2121
"php": "^7.2",
2222
"nikic/php-parser": "^4.2",
23-
"gettext/gettext": "^5.1"
23+
"gettext/gettext": "dev-master"
2424
},
2525
"require-dev": {
2626
"phpunit/phpunit": "^8.0",

tests/PhpScannerTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,18 @@ public function testPhpCodeScanner()
3030
$this->assertCount(1, $domain3);
3131

3232
$scanner->setDefaultDomain('domain1');
33+
$scanner->extractCommentsStartingWith('');
3334
$scanner->scanFile($file);
3435

3536
$this->assertCount(39, $domain1);
3637
$this->assertCount(4, $domain2);
3738
$this->assertCount(1, $domain3);
39+
40+
//Extract comments
41+
$translation = $domain1->find('CONTEXT', 'All comments');
42+
$this->assertNotNull($translation);
43+
$this->assertSame([$file => [66]], $translation->getReferences()->toArray());
44+
$this->assertCount(1, $translation->getExtractedComments());
3845
}
3946

4047
public function testInvalidFunction()

0 commit comments

Comments
 (0)