## Bug Report
- [x] Yes, I reviewed the [contribution guidelines](https://make.…wordpress.org/cli/handbook/contributing/).
- [x] Yes, more specifically, I reviewed the guidelines on [how to write clear bug reports](https://make.wordpress.org/cli/handbook/bug-reports/).
**Describe the current, buggy behavior**
The (valid) `theme.json` is not processed by `wp i18n`, no translation strings are extracted from it.
A PHP warning occurs:
````
Theme stylesheet detected.
PHP Warning: Invalid argument supplied for foreach() in phar:///usr/local/bin/wp/vendor/wp-cli/i18n-command/src/ThemeJsonExtractor.php on line 209
PHP Stack trace:
PHP 1. {main}() /usr/local/bin/wp:0
PHP 2. include() /usr/local/bin/wp:4
PHP 3. include() phar:///usr/local/bin/wp/php/boot-phar.php:11
PHP 4. WP_CLI\bootstrap() phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php:27
PHP 5. WP_CLI\Bootstrap\LaunchRunner->process($state = class WP_CLI\Bootstrap\BootstrapState { private $state = ['context_manager' => class WP_CLI\ContextManager { ... }] }) phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/bootstrap.php:78
PHP 6. WP_CLI\Runner->start() phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php:28
PHP 7. WP_CLI\Runner->do_early_invoke($when = 'before_wp_load') phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php:1170
PHP 8. WP_CLI\Runner->run_command_and_exit($help_exit_warning = *uninitialized*) phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php:125
PHP 9. WP_CLI\Runner->run_command($args = [0 => 'i18n', 1 => 'make-pot', 2 => '.', 3 => './resources/lang/theme.pot'], $assoc_args = [], $options = *uninitialized*) phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php:440
PHP 10. WP_CLI\Dispatcher\Subcommand->invoke($args = [0 => '.', 1 => './resources/lang/theme.pot'], $assoc_args = [], $extra_args = []) phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php:417
PHP 11. call_user_func:{phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/Subcommand.php:491}($function_name = class Closure { virtual $closure = "$this->WP_CLI\Dispatcher\{closure}", public $static = ['callable' => [...]]; public $parameter = ['$args' => '<required>', '$assoc_args' => '<required>'] }, ...$parameters = variadic([])) phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/Subcommand.php:491
PHP 12. WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure:phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php:97-104}($args = [0 => '.', 1 => './resources/lang/theme.pot'], $assoc_args = []) phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/Subcommand.php:491
PHP 13. call_user_func:{phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php:100}($function_name = [0 => class WP_CLI\I18n\MakePotCommand { protected $source = '/home/build/src/example.com/site/web/app/themes/theme'; protected $destination = './resources/lang/theme.pot'; protected $merge = [...]; protected $exceptions = [...]; protected $subtract_and_merge = NULL; protected $include = [...]; protected $exclude = [...]; protected $slug = 'theme'; protected $main_file_data = [...]; protected $skip_js = FALSE; protected $skip_php = FALSE; protected $skip_blade = FALSE; protected $skip_block_json = FALSE; protected $skip_theme_json = FALSE; protected $skip_audit = FALSE; protected $location = TRUE; protected $headers = [...]; protected $domain = 'theme'; protected $package_name = NULL; protected $file_comment = NULL; protected $project_type = 'theme' }, 1 => '__invoke'], ...$parameters = variadic([])) phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php:100
PHP 14. WP_CLI\I18n\MakePotCommand->__invoke($args = [0 => '.', 1 => './resources/lang/theme.pot'], $assoc_args = []) phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php:100
PHP 15. WP_CLI\I18n\MakePotCommand->extract_strings() /home/build/.wp-cli/packages/vendor/wp-cli/i18n-command/src/MakePotCommand.php:285
PHP 16. WP_CLI\I18n\ThemeJsonExtractor::fromDirectory($dir = '/home/build/src/example.com/site/web/app/themes/theme', $translations = class Gettext\Translations { protected $headers = ['Project-Id-Version' => 'Theme 1.0.0', 'Report-Msgid-Bugs-To' => 'https://wordpress.org/support/theme/theme', 'Last-Translator' => 'FULL NAME <EMAIL@ADDRESS>', 'Language-Team' => 'LANGUAGE <LL@li.org>', 'MIME-Version' => '1.0', 'Content-Type' => 'text/plain; charset=UTF-8', 'Content-Transfer-Encoding' => '8bit', 'POT-Creation-Date' => '2022-05-10T21:12:15+02:00', 'PO-Revision-Date' => 'YEAR-MO-DA HO:MI+ZONE', 'X-Generator' => 'WP-CLI 2.6.0', 'X-Domain' => 'theme']; protected $translationClass = 'Gettext\\Translation'; private ${ArrayObject}storage = ['Theme' => class Gettext\Translation { ... }, 'https://www.example.com' => class Gettext\Translation { ... }, 'Test theme.' => class Gettext\Translation { ... }, 'Author' => class Gettext\Translation { ... }, 'https://www.web-design-hosting.eu' => class Gettext\Translation { ... }] }, $options = ['restrictFileNames' => [0 => 'theme.json'], 'include' => [], 'exclude' => [0 => 'node_modules', 1 => '.git', 2 => '.svn', 3 => '.CVS', 4 => '.hg', 5 => 'vendor', 6 => 'Gruntfile.js', 7 => 'webpack.config.js', 8 => '*.min.js'], 'extensions' => [0 => 'json']]) /home/build/.wp-cli/packages/vendor/wp-cli/i18n-command/src/MakePotCommand.php:676
PHP 17. WP_CLI\I18n\ThemeJsonExtractor::fromFile($file_or_files = [0 => '/home/build/src/example.com/site/web/app/themes/theme/.budfiles/bud/modules.json', 1 => '/home/build/src/example.com/site/web/app/themes/theme/.budfiles/bud/profile.json', 2 => '/home/build/src/example.com/site/web/app/themes/theme/composer.json', 3 => '/home/build/src/example.com/site/web/app/themes/theme/jsconfig.json', 4 => '/home/build/src/example.com/site/web/app/themes/theme/package.json', 5 => '/home/build/src/example.com/site/web/app/themes/theme/public/app.3be68fa733011d85f572.hot-update.json', 6 => '/home/build/src/example.com/site/web/app/themes/theme/public/app.daf54ef2be6639ef729e.hot-update.json', 7 => '/home/build/src/example.com/site/web/app/themes/theme/public/editor.3be68fa733011d85f572.hot-update.json', 8 => '/home/build/src/example.com/site/web/app/themes/theme/public/editor.daf54ef2be6639ef729e.hot-update.json', 9 => '/home/build/src/example.com/site/web/app/themes/theme/public/entrypoints.json', 10 => '/home/build/src/example.com/site/web/app/themes/theme/public/hmr.json', 11 => '/home/build/src/example.com/site/web/app/themes/theme/public/manifest.json', 12 => '/home/build/src/example.com/site/web/app/themes/theme/theme.json'], $translations = class Gettext\Translations { protected $headers = ['Project-Id-Version' => 'Theme 1.0.0', 'Report-Msgid-Bugs-To' => 'https://wordpress.org/support/theme/theme', 'Last-Translator' => 'FULL NAME <EMAIL@ADDRESS>', 'Language-Team' => 'LANGUAGE <LL@li.org>', 'MIME-Version' => '1.0', 'Content-Type' => 'text/plain; charset=UTF-8', 'Content-Transfer-Encoding' => '8bit', 'POT-Creation-Date' => '2022-05-10T21:12:15+02:00', 'PO-Revision-Date' => 'YEAR-MO-DA HO:MI+ZONE', 'X-Generator' => 'WP-CLI 2.6.0', 'X-Domain' => 'theme']; protected $translationClass = 'Gettext\\Translation'; private ${ArrayObject}storage = ['Theme' => class Gettext\Translation { ... }, 'https://www.example.com' => class Gettext\Translation { ... }, 'Test theme.' => class Gettext\Translation { ... }, 'Author' => class Gettext\Translation { ... }, 'https://www.web-design-hosting.eu' => class Gettext\Translation { ... }] }, $options = ['restrictFileNames' => [0 => 'theme.json'], 'include' => [], 'exclude' => [0 => 'node_modules', 1 => '.git', 2 => '.svn', 3 => '.CVS', 4 => '.hg', 5 => 'vendor', 6 => 'Gruntfile.js', 7 => 'webpack.config.js', 8 => '*.min.js'], 'extensions' => [0 => 'json']]) phar:///usr/local/bin/wp/vendor/wp-cli/i18n-command/src/IterableCodeExtractor.php:97
PHP 18. WP_CLI\I18n\ThemeJsonExtractor::fromString($string = '\n{\n "$schema": "https://schemas.wp.org/trunk/theme.json",\n "version": 2,\n "settings": {\n "color": {\n "palette": [\n {\n "slug": "primary",\n "color": "#525ddc",\n "name": "Primary"\n }\n ],\n "custom": false,\n "customGradient": false,\n "defaultPalette": false,\n "defaultGradients": false\n },\n "custom": {\n "spacing": {},\n "typography": {\n "font-size": {},\n "line-height": {}\n }\n }', $translations = class Gettext\Translations { protected $headers = ['Project-Id-Version' => 'Theme 1.0.0', 'Report-Msgid-Bugs-To' => 'https://wordpress.org/support/theme/theme', 'Last-Translator' => 'FULL NAME <EMAIL@ADDRESS>', 'Language-Team' => 'LANGUAGE <LL@li.org>', 'MIME-Version' => '1.0', 'Content-Type' => 'text/plain; charset=UTF-8', 'Content-Transfer-Encoding' => '8bit', 'POT-Creation-Date' => '2022-05-10T21:12:15+02:00', 'PO-Revision-Date' => 'YEAR-MO-DA HO:MI+ZONE', 'X-Generator' => 'WP-CLI 2.6.0', 'X-Domain' => 'theme']; protected $translationClass = 'Gettext\\Translation'; private ${ArrayObject}storage = ['Theme' => class Gettext\Translation { ... }, 'https://www.example.com' => class Gettext\Translation { ... }, 'Test theme.' => class Gettext\Translation { ... }, 'Author' => class Gettext\Translation { ... }, 'https://www.web-design-hosting.eu' => class Gettext\Translation { ... }] }, $options = ['restrictFileNames' => [0 => 'theme.json'], 'include' => [], 'exclude' => [0 => 'node_modules', 1 => '.git', 2 => '.svn', 3 => '.CVS', 4 => '.hg', 5 => 'vendor', 6 => 'Gruntfile.js', 7 => 'webpack.config.js', 8 => '*.min.js'], 'extensions' => [0 => 'json'], 'file' => 'theme.json']) phar:///usr/local/bin/wp/vendor/wp-cli/i18n-command/src/IterableCodeExtractor.php:68
PHP 19. WP_CLI\I18n\ThemeJsonExtractor::get_fields_to_translate() phar:///usr/local/bin/wp/vendor/wp-cli/i18n-command/src/ThemeJsonExtractor.php:43
PHP 20. WP_CLI\I18n\ThemeJsonExtractor::extract_paths_to_translate($i18n_partial = ['title' => 'Style variation name', 'settings' => ['typography' => [...], 'color' => [...], 'blocks' => [...]], 'customTemplates' => [0 => [...]], 'templateParts' => [0 => [...]]], $current_path = *uninitialized*) phar:///usr/local/bin/wp/vendor/wp-cli/i18n-command/src/ThemeJsonExtractor.php:166
PHP 21. WP_CLI\I18n\ThemeJsonExtractor::extract_paths_to_translate($i18n_partial = 'Style variation name', $current_path = [0 => 'title']) phar:///usr/local/bin/wp/vendor/wp-cli/i18n-command/src/ThemeJsonExtractor.php:222
Success: POT file successfully generated!
````
(Valid )`theme.json` that causes the issue:
```json
{
"$schema": "https://schemas.wp.org/trunk/theme.json",
"version": 2,
"settings": {
"color": {
"palette": [
{
"slug": "primary",
"color": "#525ddc",
"name": "Primary"
}
],
"custom": false,
"customGradient": false,
"defaultPalette": false,
"defaultGradients": false
},
"custom": {
"spacing": {},
"typography": {
"font-size": {},
"line-height": {}
}
},
"spacing": {
"padding": true,
"units": ["px", "%", "em", "rem", "vw", "vh"]
},
"typography": {
"customFontSize": false
}
}
}
````
**Describe how other contributors can replicate this bug**
- Use a theme that contains this (valid )`theme.json`:
```json
{
"$schema": "https://schemas.wp.org/trunk/theme.json",
"version": 2,
"settings": {
"color": {
"palette": [
{
"slug": "primary",
"color": "#525ddc",
"name": "Primary"
}
],
"custom": false,
"customGradient": false,
"defaultPalette": false,
"defaultGradients": false
},
"custom": {
"spacing": {},
"typography": {
"font-size": {},
"line-height": {}
}
},
"spacing": {
"padding": true,
"units": ["px", "%", "em", "rem", "vw", "vh"]
},
"typography": {
"customFontSize": false
}
}
}
````
- Invoke `wp i18n` inside the theme directory:
`wp i18n make-pot . ./resources/lang/theme.pot`
Notice the PHP warning and that translation strings in `theme.json` are not extracted.
**Describe what you would expect as the correct outcome**
No PHP warning and translation strings extracted from `theme.json`.
**Let us know what environment you are running this on**
```
OS: Linux 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022 x86_64
Shell: /bin/bash
PHP binary: /usr/bin/php7.4
PHP version: 7.4.29
php.ini used: /etc/php/7.4/cli/php.ini
MySQL binary: /usr/bin/mysql
MySQL version: mysql Ver 8.0.29-0ubuntu0.20.04.3 for Linux on x86_64 ((Ubuntu))
SQL modes:
WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir: phar://wp-cli.phar/vendor
WP_CLI phar path: /home/build/src/[...]/[...]/test-theme
WP-CLI packages dir: /home/build/.wp-cli/packages/
WP-CLI global config:
WP-CLI project config: /home/build/src/[...]/site/wp-cli.yml
WP-CLI version: 2.6.0
```
**Provide a possible solution**
Probably some mismatch of expected `theme.json` data structure and extractor logic that needs to be fixed.