Skip to content

Commit

Permalink
make-pot: scan any theme.json file in any level
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy committed Dec 19, 2024
1 parent 0133eb1 commit b7d53ee
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 39 deletions.
97 changes: 97 additions & 0 deletions features/makepot.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3651,6 +3651,35 @@ Feature: Generate a POT file of a WordPress project
msgid "Black"
"""

Scenario: Skips theme.json file if excluding it
Given an empty foo-theme directory
And a foo-theme/theme.json file:
"""
{
"version": "1",
"settings": {
"color": {
"palette": [
{ "slug": "black", "color": "#000000", "name": "Black" }
]
}
}
}
"""

When I try `wp i18n make-pot foo-theme --exclude=theme.json`
Then STDOUT should be:
"""
Success: POT file successfully generated.
"""
And the foo-theme/foo-theme.pot file should exist
But the foo-theme/foo-theme.pot file should not contain:
"""
msgctxt "Color name"
msgid "Black"
"""


Scenario: Extract strings from the top-level section of theme.json files
Given an empty foo-theme directory
And a foo-theme/theme.json file:
Expand Down Expand Up @@ -3972,3 +4001,71 @@ Feature: Generate a POT file of a WordPress project
"""
msgid "foo-plugin/longertests/foo-plugin.php"
"""

Scenario: Extract strings from theme.json files in any level
Given an empty foo-project directory
And a foo-project/theme.json file:
"""
{
"version": "1",
"title": "My style variation",
"description": "My style variation description"
}
"""

And a foo-project/nested/theme.json file:
"""
{
"version": "1",
"title": "Nested style variation",
"description": "Nested style variation description"
}
"""

And a foo-project/nested/notatheme.json file:
"""
{
"version": "1",
"title": "Not extracted style variation",
"description": "Not extracted style variation description"
}
"""

When I try `wp i18n make-pot foo-project`
Then STDOUT should be:
"""
Success: POT file successfully generated.
"""
And the foo-project/foo-project.pot file should exist
And the foo-project/foo-project.pot file should contain:
"""
#: theme.json
msgctxt "Style variation name"
msgid "My style variation"
"""
And the foo-project/foo-project.pot file should contain:
"""
#: theme.json
msgctxt "Style variation description"
msgid "My style variation description"
"""
And the foo-project/foo-project.pot file should contain:
"""
#: nested/theme.json
msgctxt "Style variation name"
msgid "Nested style variation"
"""
And the foo-project/foo-project.pot file should contain:
"""
#: nested/theme.json
msgctxt "Style variation description"
msgid "Nested style variation description"
"""
And the foo-project/foo-project.pot file should not contain:
"""
msgid "Not extract style variation"
"""
And the foo-project/foo-project.pot file should not contain:
"""
msgid "Not extracted style variation description"
"""
20 changes: 10 additions & 10 deletions src/MakePotCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ protected function extract_strings() {
[
'schema' => JsonSchemaExtractor::BLOCK_JSON_SOURCE,
'schemaFallback' => JsonSchemaExtractor::BLOCK_JSON_FALLBACK,
// Only look for block.json files, nothing else.
// Only look for block.json files in any folder, nothing else.
'restrictFileNames' => [ 'block.json' ],
'include' => $this->include,
'exclude' => $this->exclude,
Expand All @@ -704,18 +704,18 @@ protected function extract_strings() {
}

if ( ! $this->skip_theme_json ) {
// This will look for the top-level theme.json file, as well as
// any JSON file within the top-level styles/ directory.
ThemeJsonExtractor::fromDirectory(
JsonSchemaExtractor::fromDirectory(
$this->source,
$translations,
[
'schema' => JsonSchemaExtractor::THEME_JSON_SOURCE,
'schemaFallback' => JsonSchemaExtractor::THEME_JSON_FALLBACK,
'include' => $this->include,
'exclude' => $this->exclude,
'extensions' => [ 'json' ],
'addReferences' => $this->location,
// Only look for theme.json files in any folder, nothing else.
'restrictFileNames' => [ 'theme.json' ],
'schema' => JsonSchemaExtractor::THEME_JSON_SOURCE,
'schemaFallback' => JsonSchemaExtractor::THEME_JSON_FALLBACK,
'include' => $this->include,
'exclude' => $this->exclude,
'extensions' => [ 'json' ],
'addReferences' => $this->location,
]
);
}
Expand Down
29 changes: 0 additions & 29 deletions src/ThemeJsonExtractor.php

This file was deleted.

0 comments on commit b7d53ee

Please sign in to comment.