From 752a4d4dd14a2d6c93dba5ae4410677c0b5d3c34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Thu, 31 Mar 2022 17:35:03 +0200 Subject: [PATCH 1/3] Look for theme.json files in the styles directory --- src/MakePotCommand.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/MakePotCommand.php b/src/MakePotCommand.php index 0c156402..f9e4fb36 100644 --- a/src/MakePotCommand.php +++ b/src/MakePotCommand.php @@ -668,11 +668,11 @@ protected function extract_strings() { } if ( ! $this->skip_theme_json ) { + // Look for the top-level theme.json file, nothing else. ThemeJsonExtractor::fromDirectory( $this->source, $translations, [ - // Only look for theme.json files, nothing else. 'restrictFileNames' => [ 'theme.json' ], 'include' => $this->include, 'exclude' => $this->exclude, @@ -680,6 +680,19 @@ protected function extract_strings() { ] ); } + + if ( ! $this->skip_theme_json ) { + // Look for any JSON file within the 'styles' directory. + ThemeJsonExtractor::fromDirectory( + $this->source, + $translations, + [ + 'include' => array_merge( $this->include, array( 'styles' ) ), + 'exclude' => $this->exclude, + 'extensions' => [ 'json' ], + ] + ); + } } catch ( \Exception $e ) { WP_CLI::error( $e->getMessage() ); } From 0b30b82b6b458beb2daf463f9dc58f8017aa2289 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Thu, 31 Mar 2022 18:04:12 +0200 Subject: [PATCH 2/3] Add behat test --- features/makepot.feature | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/features/makepot.feature b/features/makepot.feature index 53bcfd4f..91f671f0 100644 --- a/features/makepot.feature +++ b/features/makepot.feature @@ -3621,3 +3621,35 @@ Feature: Generate a POT file of a WordPress project msgctxt "Color name" msgid "Black" """ + + Scenario: Extract strings from style variations + Given an empty foo-theme/styles directory + And a foo-theme/styles/my-style.json file: + """ + { + "version": "1", + "settings": { + "blocks": { + "core/paragraph": { + "color": { + "palette": [ + { "slug": "black", "color": "#000000", "name": "Black" } + ] + } + } + } + } + } + """ + + When I try `wp i18n make-pot foo-theme` + Then STDOUT should be: + """ + Success: POT file successfully generated! + """ + And the foo-theme/foo-theme.pot file should exist + And the foo-theme/foo-theme.pot file should contain: + """ + msgctxt "Color name" + msgid "Black" + """ From 3149428a17b891af67668740765e77eaf2787ea9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Thu, 31 Mar 2022 18:20:33 +0200 Subject: [PATCH 3/3] Make linter happy --- src/MakePotCommand.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/MakePotCommand.php b/src/MakePotCommand.php index f9e4fb36..e0dac0ad 100644 --- a/src/MakePotCommand.php +++ b/src/MakePotCommand.php @@ -687,9 +687,9 @@ protected function extract_strings() { $this->source, $translations, [ - 'include' => array_merge( $this->include, array( 'styles' ) ), - 'exclude' => $this->exclude, - 'extensions' => [ 'json' ], + 'include' => array_merge( $this->include, array( 'styles' ) ), + 'exclude' => $this->exclude, + 'extensions' => [ 'json' ], ] ); }