Skip to content

Commit 2239768

Browse files
committed
Include PHP inside the /assets/lang path
1 parent f64dcba commit 2239768

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/Traits/GeneratePotTrait.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* @copyright 10Quality <http://www.10quality.com>
2020
* @license MIT
2121
* @package WPMVC\Commands
22-
* @version 1.1.18
22+
* @version 1.1.19
2323
*/
2424
trait GeneratePotTrait
2525
{
@@ -72,6 +72,16 @@ protected function generatePot($lang = 'en')
7272
continue;
7373
$scanner->scanFile($file);
7474
}
75+
foreach (glob($this->getAssetsPath().'lang/*.php') as $file) {
76+
if ($this->isFileToLocalizeExcluded($file))
77+
continue;
78+
$scanner->scanFile($file);
79+
}
80+
foreach (glob($this->getAssetsPath().'lang/**/*.php') as $file) {
81+
if ($this->isFileToLocalizeExcluded($file))
82+
continue;
83+
$scanner->scanFile($file);
84+
}
7585
$scannedTranslations = $scanner->getTranslations();
7686
if (array_key_exists($domain, $scannedTranslations))
7787
$translations = $translations->mergeWith($scannedTranslations[$domain]);

tests/cases/GeneratePotTest.php

+10-3
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
* @copyright 10Quality <http://www.10quality.com>
1010
* @license MIT
1111
* @package WPMVC\Commands
12-
* @version 1.1.17
12+
* @version 1.1.19
1313
*/
1414
class GeneratePotTest extends WpmvcAyucoTestCase
1515
{
1616
/**
1717
* Tests path.
1818
*/
1919
protected $path = [
20+
FRAMEWORK_PATH.'/environment/assets/lang/test',
2021
FRAMEWORK_PATH.'/environment/assets/lang/',
2122
FRAMEWORK_PATH.'/environment/assets/views/',
2223
FRAMEWORK_PATH.'/environment/assets/',
@@ -31,6 +32,10 @@ public function setUp(): void
3132
mkdir(TESTING_PATH.'/assets/views/', 0777, true);
3233
if (!is_dir(TESTING_PATH.'/app/Localize/'))
3334
mkdir(TESTING_PATH.'/app/Localize/', 0777, true);
35+
if (!is_dir(TESTING_PATH.'/assets/lang/'))
36+
mkdir(TESTING_PATH.'/assets/lang/', 0777, true);
37+
if (!is_dir(TESTING_PATH.'/assets/lang/test/'))
38+
mkdir(TESTING_PATH.'/assets/lang/test/', 0777, true);
3439
if (!is_file(TESTING_PATH.'/assets/views/localize.php'))
3540
file_put_contents(TESTING_PATH.'/assets/views/localize.php', '<?php echo _e( \'View text 1\', \'my-app\' ) ?>');
3641
if (!is_file(TESTING_PATH.'/app/Localize/Test.php'))
@@ -40,6 +45,8 @@ public function setUp(): void
4045
. ' _e( \'Test echoed string "Yolo"\', \'my-app\' ); $numeric = _n( \'One string\', \'%d strings\', 3, \'my-app\' );'
4146
. ' _e( \'Other domain\', \'other-domain\' );}}'
4247
);
48+
if (!is_file(TESTING_PATH.'/assets/lang/test/test.php'))
49+
file_put_contents(TESTING_PATH.'/assets/lang/test/test.php', '<?php return array( __( \'Lang text 1\', \'my-app\' ) );');
4350
}
4451
/**
4552
* Test resulting message.
@@ -57,7 +64,7 @@ public function testGeneration()
5764
// Assert
5865
$this->assertEquals('POT file generated!', $execution);
5966
$this->assertFileExists($filename);
60-
$this->assertCount(5, $translations);
67+
$this->assertCount(6, $translations);
6168
$this->assertEquals('en', $translations->getHeaders()->get('Language'));
6269
$this->assertEquals('my-app', $translations->getHeaders()->get('X-Domain'));
6370
$this->assertEquals('1.0.0', $translations->getHeaders()->get('MIME-Version'));
@@ -83,7 +90,7 @@ public function testExistingGeneration()
8390
// Assert
8491
$this->assertEquals('POT file updated!', $execution);
8592
$this->assertFileExists($filename);
86-
$this->assertCount(6, $translations);
93+
$this->assertCount(7, $translations);
8794
$this->assertEquals('en', $translations->getHeaders()->get('Language'));
8895
$this->assertEquals('my-app', $translations->getHeaders()->get('X-Domain'));
8996
$this->assertEquals('1.0.0', $translations->getHeaders()->get('MIME-Version'));

0 commit comments

Comments
 (0)