Skip to content

Commit

Permalink
Include PHP inside the /assets/lang path
Browse files Browse the repository at this point in the history
  • Loading branch information
amostajo committed Sep 30, 2024
1 parent f64dcba commit 2239768
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
12 changes: 11 additions & 1 deletion src/Traits/GeneratePotTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @copyright 10Quality <http://www.10quality.com>
* @license MIT
* @package WPMVC\Commands
* @version 1.1.18
* @version 1.1.19
*/
trait GeneratePotTrait
{
Expand Down Expand Up @@ -72,6 +72,16 @@ protected function generatePot($lang = 'en')
continue;
$scanner->scanFile($file);
}
foreach (glob($this->getAssetsPath().'lang/*.php') as $file) {
if ($this->isFileToLocalizeExcluded($file))
continue;
$scanner->scanFile($file);
}
foreach (glob($this->getAssetsPath().'lang/**/*.php') as $file) {
if ($this->isFileToLocalizeExcluded($file))
continue;
$scanner->scanFile($file);
}
$scannedTranslations = $scanner->getTranslations();
if (array_key_exists($domain, $scannedTranslations))
$translations = $translations->mergeWith($scannedTranslations[$domain]);
Expand Down
13 changes: 10 additions & 3 deletions tests/cases/GeneratePotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
* @copyright 10Quality <http://www.10quality.com>
* @license MIT
* @package WPMVC\Commands
* @version 1.1.17
* @version 1.1.19
*/
class GeneratePotTest extends WpmvcAyucoTestCase
{
/**
* Tests path.
*/
protected $path = [
FRAMEWORK_PATH.'/environment/assets/lang/test',
FRAMEWORK_PATH.'/environment/assets/lang/',
FRAMEWORK_PATH.'/environment/assets/views/',
FRAMEWORK_PATH.'/environment/assets/',
Expand All @@ -31,6 +32,10 @@ public function setUp(): void
mkdir(TESTING_PATH.'/assets/views/', 0777, true);
if (!is_dir(TESTING_PATH.'/app/Localize/'))
mkdir(TESTING_PATH.'/app/Localize/', 0777, true);
if (!is_dir(TESTING_PATH.'/assets/lang/'))
mkdir(TESTING_PATH.'/assets/lang/', 0777, true);
if (!is_dir(TESTING_PATH.'/assets/lang/test/'))
mkdir(TESTING_PATH.'/assets/lang/test/', 0777, true);
if (!is_file(TESTING_PATH.'/assets/views/localize.php'))
file_put_contents(TESTING_PATH.'/assets/views/localize.php', '<?php echo _e( \'View text 1\', \'my-app\' ) ?>');
if (!is_file(TESTING_PATH.'/app/Localize/Test.php'))
Expand All @@ -40,6 +45,8 @@ public function setUp(): void
. ' _e( \'Test echoed string "Yolo"\', \'my-app\' ); $numeric = _n( \'One string\', \'%d strings\', 3, \'my-app\' );'
. ' _e( \'Other domain\', \'other-domain\' );}}'
);
if (!is_file(TESTING_PATH.'/assets/lang/test/test.php'))
file_put_contents(TESTING_PATH.'/assets/lang/test/test.php', '<?php return array( __( \'Lang text 1\', \'my-app\' ) );');
}
/**
* Test resulting message.
Expand All @@ -57,7 +64,7 @@ public function testGeneration()
// Assert
$this->assertEquals('POT file generated!', $execution);
$this->assertFileExists($filename);
$this->assertCount(5, $translations);
$this->assertCount(6, $translations);
$this->assertEquals('en', $translations->getHeaders()->get('Language'));
$this->assertEquals('my-app', $translations->getHeaders()->get('X-Domain'));
$this->assertEquals('1.0.0', $translations->getHeaders()->get('MIME-Version'));
Expand All @@ -83,7 +90,7 @@ public function testExistingGeneration()
// Assert
$this->assertEquals('POT file updated!', $execution);
$this->assertFileExists($filename);
$this->assertCount(6, $translations);
$this->assertCount(7, $translations);
$this->assertEquals('en', $translations->getHeaders()->get('Language'));
$this->assertEquals('my-app', $translations->getHeaders()->get('X-Domain'));
$this->assertEquals('1.0.0', $translations->getHeaders()->get('MIME-Version'));
Expand Down

0 comments on commit 2239768

Please sign in to comment.