diff --git a/features/makepot.feature b/features/makepot.feature index db0f9303..1c1913fc 100644 --- a/features/makepot.feature +++ b/features/makepot.feature @@ -3658,3 +3658,40 @@ Feature: Generate a POT file of a WordPress project msgctxt "Color name" msgid "Black" """ + + Scenario: Extract strings from the patterns directory + Given an empty foo-theme/patterns directory + And a foo-theme/patterns/my-pattern.php file: + """ + 'Title', + 'Description' => 'Description', + ] + ); + + if ( ! empty( $headers['Title'] ) ) { + $translation = new Translation( 'Pattern title', $headers['Title'] ); + $translation->addReference( $options['file'] ); + + $translations[] = $translation; + } + + if ( ! empty( $headers['Description'] ) ) { + $translation = new Translation( 'Pattern description', $headers['Description'] ); + $translation->addReference( $options['file'] ); + + $translations[] = $translation; + } + } + static::fromString( $string, $translations, $options ); } } diff --git a/src/MakePotCommand.php b/src/MakePotCommand.php index e0dac0ad..bfe37c61 100644 --- a/src/MakePotCommand.php +++ b/src/MakePotCommand.php @@ -618,6 +618,17 @@ protected function extract_strings() { PhpCodeExtractor::fromDirectory( $this->source, $translations, $options ); } + if ( ! $this->skip_php ) { + $options = [ + // Extract 'Title' and 'Description' headers from pattern files. + 'wpExtractPatterns' => isset( $this->main_file_data['Theme Name'] ), + 'include' => array_merge( $this->include, array( 'patterns' ) ), + 'exclude' => $this->exclude, + 'extensions' => [ 'php' ], + ]; + PhpCodeExtractor::fromDirectory( $this->source, $translations, $options ); + } + if ( ! $this->skip_blade ) { $options = [ 'include' => $this->include,