From cf8304a5b18deaeddeacb9e158853de83e2628b3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 8 Nov 2025 16:13:05 +0000 Subject: [PATCH 1/8] Initial plan From 069b9886cb461440618c69772c7635ff20510fb8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 8 Nov 2025 16:23:07 +0000 Subject: [PATCH 2/8] Fix language status for plugins/themes with different text domain than slug Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/WP_CLI/CommandWithTranslation.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/WP_CLI/CommandWithTranslation.php b/src/WP_CLI/CommandWithTranslation.php index c273dc8e..4c9b142a 100644 --- a/src/WP_CLI/CommandWithTranslation.php +++ b/src/WP_CLI/CommandWithTranslation.php @@ -283,8 +283,30 @@ protected function get_installed_languages( $slug = 'default' ) { /** * @var array>> $available */ - $available = wp_get_installed_translations( $this->obj_type ); - $available = ! empty( $available[ $slug ] ) ? array_keys( $available[ $slug ] ) : array(); + $available = wp_get_installed_translations( $this->obj_type ); + + // For plugins and themes, check if the text domain differs from the slug. + $text_domain = $slug; + if ( 'default' !== $slug ) { + if ( 'plugins' === $this->obj_type ) { + $plugins = get_plugins( '/' . $slug ); + if ( ! empty( $plugins ) ) { + $plugin_data = array_shift( $plugins ); + // Use the TextDomain header if available, otherwise fall back to slug. + if ( ! empty( $plugin_data['TextDomain'] ) ) { + $text_domain = $plugin_data['TextDomain']; + } + } + } elseif ( 'themes' === $this->obj_type ) { + $theme_data = wp_get_theme( $slug ); + // Use the TextDomain property if available, otherwise fall back to slug. + if ( ! empty( $theme_data->get( 'TextDomain' ) ) ) { + $text_domain = $theme_data->get( 'TextDomain' ); + } + } + } + + $available = ! empty( $available[ $text_domain ] ) ? array_keys( $available[ $text_domain ] ) : array(); $available[] = 'en_US'; return $available; From c8f987d84a6031e42382ff8348e2f836b9d32239 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 8 Nov 2025 16:29:14 +0000 Subject: [PATCH 3/8] Add theme exists check for better error handling Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/WP_CLI/CommandWithTranslation.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/WP_CLI/CommandWithTranslation.php b/src/WP_CLI/CommandWithTranslation.php index 4c9b142a..9f66e9c2 100644 --- a/src/WP_CLI/CommandWithTranslation.php +++ b/src/WP_CLI/CommandWithTranslation.php @@ -299,9 +299,12 @@ protected function get_installed_languages( $slug = 'default' ) { } } elseif ( 'themes' === $this->obj_type ) { $theme_data = wp_get_theme( $slug ); - // Use the TextDomain property if available, otherwise fall back to slug. - if ( ! empty( $theme_data->get( 'TextDomain' ) ) ) { - $text_domain = $theme_data->get( 'TextDomain' ); + if ( $theme_data->exists() ) { + // Use the TextDomain property if available, otherwise fall back to slug. + $theme_text_domain = $theme_data->get( 'TextDomain' ); + if ( ! empty( $theme_text_domain ) ) { + $text_domain = $theme_text_domain; + } } } } From 0fbb3d5332cbe793c37efa4019f3ef42216af9c3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 8 Nov 2025 16:30:11 +0000 Subject: [PATCH 4/8] Add test for plugins with different text domain than slug Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/language-plugin.feature | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/features/language-plugin.feature b/features/language-plugin.feature index a94e9636..24c8b445 100644 --- a/features/language-plugin.feature +++ b/features/language-plugin.feature @@ -444,3 +444,37 @@ Feature: Manage plugin translation files for a WordPress install | akismet | en_US | active | | akismet | nl_NL | installed | And STDERR should be empty + + @require-wp-4.0 + Scenario: Handle plugins with text domain different from slug + Given a WP install + And an empty cache + + # Create a test plugin with a different text domain + Given a wp-content/plugins/test-plugin/test-plugin.php file: + """ + Date: Mon, 10 Nov 2025 16:40:20 +0100 Subject: [PATCH 5/8] Lint fix --- src/WP_CLI/CommandWithTranslation.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/WP_CLI/CommandWithTranslation.php b/src/WP_CLI/CommandWithTranslation.php index 9f66e9c2..8d9a763d 100644 --- a/src/WP_CLI/CommandWithTranslation.php +++ b/src/WP_CLI/CommandWithTranslation.php @@ -284,7 +284,7 @@ protected function get_installed_languages( $slug = 'default' ) { * @var array>> $available */ $available = wp_get_installed_translations( $this->obj_type ); - + // For plugins and themes, check if the text domain differs from the slug. $text_domain = $slug; if ( 'default' !== $slug ) { @@ -308,7 +308,7 @@ protected function get_installed_languages( $slug = 'default' ) { } } } - + $available = ! empty( $available[ $text_domain ] ) ? array_keys( $available[ $text_domain ] ) : array(); $available[] = 'en_US'; From 6e2d8b72c9f6d998397e54668e58315fd1827091 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 10 Nov 2025 16:52:45 +0100 Subject: [PATCH 6/8] Fix test --- features/language-plugin.feature | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/features/language-plugin.feature b/features/language-plugin.feature index 24c8b445..030246d7 100644 --- a/features/language-plugin.feature +++ b/features/language-plugin.feature @@ -462,10 +462,8 @@ Feature: Manage plugin translation files for a WordPress install """ # Manually create a translation file using the text domain (not the plugin slug) - And a wp-content/languages/plugins/different-text-domain-de_DE.po file: + And a wp-content/languages/plugins/different-text-domain-de_DE.l10n.php file: """ - msgid "" - msgstr "" """ When I run `wp language plugin list test-plugin --fields=language,status --format=csv` From a770faf428c93ed15fd4bb4c6753ce38d81e2427 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 10 Nov 2025 15:56:09 +0000 Subject: [PATCH 7/8] Add test for themes with text domain different from slug Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/language-theme.feature | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/features/language-theme.feature b/features/language-theme.feature index 6bbfc725..37fdd873 100644 --- a/features/language-theme.feature +++ b/features/language-theme.feature @@ -328,3 +328,33 @@ Feature: Manage theme translation files for a WordPress install | en_US | active | | nl_NL | installed | And STDERR should be empty + + @require-wp-4.0 + Scenario: Handle themes with text domain different from slug + Given a WP install + And an empty cache + + # Create a test theme with a different text domain + Given a wp-content/themes/test-theme/style.css file: + """ + /* + Theme Name: Test Theme + Text Domain: different-text-domain + */ + """ + + # Manually create a translation file using the text domain (not the theme slug) + And a wp-content/languages/themes/different-text-domain-de_DE.l10n.php file: + """ + """ + + When I run `wp language theme list test-theme --fields=language,status --format=csv` + Then STDOUT should contain: + """ + en_US,active + """ + And STDERR should be empty + + # If the fix is working, installed languages should be detected via text domain + When I run `wp language theme is-installed test-theme de_DE` + Then the return code should be 0 From fb6368f0429bc6afb1cffb69f51f9b6436934f05 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 10 Nov 2025 17:10:47 +0100 Subject: [PATCH 8/8] Lint fix --- features/language-plugin.feature | 2 +- features/language-theme.feature | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/features/language-plugin.feature b/features/language-plugin.feature index 030246d7..b4bc38d8 100644 --- a/features/language-plugin.feature +++ b/features/language-plugin.feature @@ -451,7 +451,7 @@ Feature: Manage plugin translation files for a WordPress install And an empty cache # Create a test plugin with a different text domain - Given a wp-content/plugins/test-plugin/test-plugin.php file: + And a wp-content/plugins/test-plugin/test-plugin.php file: """