Skip to content
2 changes: 1 addition & 1 deletion features/cli.feature
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Feature: `wp cli` tasks
When I run `wp cli param-dump --with-values | grep -o '"current":' | uniq -c | tr -d ' '`
Then STDOUT should be:
"""
22"current":
23"current":
"""
And STDERR should be empty
And the return code should be 0
Expand Down
12 changes: 12 additions & 0 deletions features/config.feature
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,18 @@ Feature: Have a config file
WP_CLI_AUTOCORRECT: 1
"""

Scenario: Set locale via config file
Given a WP installation
And a wp-cli.yml file:
"""
locale: de_DE
"""

When I run `wp eval 'echo get_locale();'`
Then STDOUT should be:
"""
de_DE

Scenario: Custom system config path via WP_CLI_SYSTEM_SETTINGS_PATH
Given an empty directory
And a system-config.yml file:
Expand Down
11 changes: 11 additions & 0 deletions php/WP_CLI/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,17 @@ private function setup_bootstrap_hooks(): void {
WP_CLI::add_wp_hook( 'setup_theme', [ $this, 'action_setup_theme_wp_cli_skip_themes' ], 999 );
}

// Set the locale if configured
if ( ! empty( $this->config['locale'] ) ) {
$locale = $this->config['locale'];
WP_CLI::add_wp_hook(
'locale',
static function () use ( $locale ) {
return $locale;
}
);
}

// Log WordPress HTTP API requests
WP_CLI::add_wp_hook(
'pre_http_request',
Expand Down
6 changes: 6 additions & 0 deletions php/config-spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@
'desc' => 'Load WordPress in a given context.',
],

'locale' => [
'file' => '<locale>',
'desc' => 'Set the locale for WP-CLI and WordPress (e.g., en_US, de_DE).',
'default' => '',
],

'disabled_commands' => [
'file' => '<list>',
'default' => [],
Expand Down
Loading