From 0fcd3d85e13767d60480e66ec02f92cf16ad5938 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 18 Dec 2023 09:39:59 +0100 Subject: [PATCH 1/2] Add file references for plugin/theme headers --- features/makepot.feature | 34 ++++++++++++++++++++++++++++++++++ src/MakePotCommand.php | 20 +++++++++++++++++--- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/features/makepot.feature b/features/makepot.feature index 59479d3..5b7bcfc 100644 --- a/features/makepot.feature +++ b/features/makepot.feature @@ -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: + """ + getRealPath() ), 'make-pot' ); - $this->project_type = 'theme'; + $this->project_type = 'theme'; + $this->main_file_path = $file->getRealPath(); return $theme_data; } @@ -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; } @@ -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; } @@ -622,6 +630,12 @@ protected function extract_strings() { $translation->addExtractedComment( sprintf( '%s of the plugin', $header ) ); } + if ( $this->main_file_path ) { + $translation->addReference( + str_replace( "$this->source/", '', $this->main_file_path ) + ); + } + $translations[] = $translation; } From 5ffc3b2d7cfcad0a2f835f9c2cec8cbef83af109 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 18 Dec 2023 09:47:09 +0100 Subject: [PATCH 2/2] Honor location flag --- src/MakePotCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MakePotCommand.php b/src/MakePotCommand.php index d87a875..e022775 100644 --- a/src/MakePotCommand.php +++ b/src/MakePotCommand.php @@ -630,7 +630,7 @@ protected function extract_strings() { $translation->addExtractedComment( sprintf( '%s of the plugin', $header ) ); } - if ( $this->main_file_path ) { + if ( $this->main_file_path && $this->location ) { $translation->addReference( str_replace( "$this->source/", '', $this->main_file_path ) );