Skip to content

Commit

Permalink
Merge pull request #311 from oandregal/add/global-style-variations
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy authored Mar 31, 2022
2 parents 85c9abe + 0314289 commit 6c0fcdb
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
32 changes: 32 additions & 0 deletions features/makepot.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3626,3 +3626,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"
"""
15 changes: 14 additions & 1 deletion src/MakePotCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -668,18 +668,31 @@ 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,
'extensions' => [ 'json' ],
]
);
}

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() );
}
Expand Down

0 comments on commit 6c0fcdb

Please sign in to comment.