File tree Expand file tree Collapse file tree 4 files changed +22
-3
lines changed Expand file tree Collapse file tree 4 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55The format is based on [ Keep a Changelog] ( http://keepachangelog.com/ )
66and 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
Original file line number Diff line number Diff 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
3440foreach (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```
Original file line number Diff line number Diff line change 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" ,
Original file line number Diff line number Diff 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 ()
You can’t perform that action at this time.
0 commit comments