Skip to content

Commit

Permalink
Merge pull request #377 from wp-cli/fix/376-main-file-reference
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy authored Jan 16, 2024
2 parents 9cf9b40 + 5ffc3b2 commit b8548b9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
34 changes: 34 additions & 0 deletions features/makepot.feature
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,40 @@ Feature: Generate a POT file of a WordPress project
Description of the plugin
"""

Scenario: Adds file references for file headers.
Given an empty foo-plugin directory
And a foo-plugin/foo-plugin.php file:
"""
<?php
/**
* Plugin Name: Foo Plugin
* Plugin URI: https://example.com
* Description: Plugin Description
* Version: 0.1.0
* Author:
* Author URI:
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: foo-plugin
* Domain Path: /languages
*/
"""

When I try `wp i18n make-pot foo-plugin foo-plugin.pot`
Then the foo-plugin.pot file should exist
And the foo-plugin.pot file should contain:
"""
Description of the plugin
"""
And the foo-plugin.pot file should contain:
"""
#: foo-plugin.php
"""
And the foo-plugin.pot file should contain:
"""
Plugin Description
"""

Scenario: Adds copyright comments
When I run `wp scaffold plugin hello-world`

Expand Down
20 changes: 17 additions & 3 deletions src/MakePotCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ class MakePotCommand extends WP_CLI_Command {
*/
protected $main_file_data = [];

/**
* @var string
*/
protected $main_file_path;

/**
* @var bool
*/
Expand Down Expand Up @@ -481,7 +486,8 @@ protected function get_main_file_data() {
WP_CLI::log( 'Theme stylesheet detected.' );
WP_CLI::debug( sprintf( 'Theme stylesheet: %s', $file->getRealPath() ), 'make-pot' );

$this->project_type = 'theme';
$this->project_type = 'theme';
$this->main_file_path = $file->getRealPath();

return $theme_data;
}
Expand All @@ -502,7 +508,8 @@ protected function get_main_file_data() {
WP_CLI::log( 'Theme stylesheet detected.' );
WP_CLI::debug( sprintf( 'Theme stylesheet: %s', $file->getRealPath() . '/style.css' ), 'make-pot' );

$this->project_type = 'theme';
$this->project_type = 'theme';
$this->main_file_path = $file->getRealPath();

return $theme_data;
}
Expand All @@ -523,7 +530,8 @@ protected function get_main_file_data() {
WP_CLI::log( 'Plugin file detected.' );
WP_CLI::debug( sprintf( 'Plugin file: %s', $file->getRealPath() ), 'make-pot' );

$this->project_type = 'plugin';
$this->project_type = 'plugin';
$this->main_file_path = $file->getRealPath();

return $plugin_data;
}
Expand Down Expand Up @@ -622,6 +630,12 @@ protected function extract_strings() {
$translation->addExtractedComment( sprintf( '%s of the plugin', $header ) );
}

if ( $this->main_file_path && $this->location ) {
$translation->addReference(
str_replace( "$this->source/", '', $this->main_file_path )
);
}

$translations[] = $translation;
}

Expand Down

0 comments on commit b8548b9

Please sign in to comment.