Skip to content

Commit e12d2e8

Browse files
committed
Merge branch 'main' into copilot/add-format-flag-to-update-commands
2 parents bf304ba + 07c72a3 commit e12d2e8

4 files changed

Lines changed: 105 additions & 2 deletions

File tree

.typos.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[default]
2+
extend-ignore-re = [
3+
"(?Rm)^.*(#|//)\\s*spellchecker:disable-line$",
4+
"(?s)(#|//)\\s*spellchecker:off.*?\\n\\s*(#|//)\\s*spellchecker:on",
5+
"(#|//)\\s*spellchecker:ignore-next-line\\n.*"
6+
]

features/language-plugin.feature

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,3 +558,40 @@ Feature: Manage plugin translation files for a WordPress install
558558
When I run `wp language plugin update akismet --dry-run --format=summary`
559559
Then STDOUT should be empty
560560
And STDERR should be empty
561+
562+
Scenario: Handle plugins with text domain different from slug
563+
Given a WP install
564+
And an empty cache
565+
566+
# Create a test plugin with a different text domain
567+
And a wp-content/plugins/test-plugin/test-plugin.php file:
568+
"""
569+
<?php
570+
/**
571+
* Plugin Name: Test Plugin
572+
* Text Domain: different-text-domain
573+
* Domain Path: /languages
574+
*/
575+
"""
576+
577+
# Manually create a translation file using the text domain (not the plugin slug)
578+
And a wp-content/languages/plugins/different-text-domain-de_DE.l10n.php file:
579+
"""
580+
"""
581+
And a wp-content/languages/plugins/different-text-domain-de_DE.mo file:
582+
"""
583+
"""
584+
And a wp-content/languages/plugins/different-text-domain-de_DE.po file:
585+
"""
586+
"""
587+
588+
When I run `wp language plugin list test-plugin --fields=language,status --format=csv`
589+
Then STDOUT should contain:
590+
"""
591+
en_US,active
592+
"""
593+
And STDERR should be empty
594+
595+
# If the fix is working, installed languages should be detected via text domain
596+
When I run `wp language plugin is-installed test-plugin de_DE`
597+
Then the return code should be 0

features/language-theme.feature

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,3 +442,38 @@ Feature: Manage theme translation files for a WordPress install
442442
When I run `wp language theme update twentyfifteen --dry-run --format=summary`
443443
Then STDOUT should be empty
444444
And STDERR should be empty
445+
446+
Scenario: Handle themes with text domain different from slug
447+
Given a WP install
448+
And an empty cache
449+
450+
# Create a test theme with a different text domain
451+
And a wp-content/themes/test-theme/style.css file:
452+
"""
453+
/*
454+
Theme Name: Test Theme
455+
Text Domain: different-text-domain
456+
*/
457+
"""
458+
459+
# Manually create a translation file using the text domain (not the theme slug)
460+
And a wp-content/languages/themes/different-text-domain-de_DE.l10n.php file:
461+
"""
462+
"""
463+
And a wp-content/languages/themes/different-text-domain-de_DE.mo file:
464+
"""
465+
"""
466+
And a wp-content/languages/themes/different-text-domain-de_DE.po file:
467+
"""
468+
"""
469+
470+
When I run `wp language theme list test-theme --fields=language,status --format=csv`
471+
Then STDOUT should contain:
472+
"""
473+
en_US,active
474+
"""
475+
And STDERR should be empty
476+
477+
# If the fix is working, installed languages should be detected via text domain
478+
When I run `wp language theme is-installed test-theme de_DE`
479+
Then the return code should be 0

src/WP_CLI/CommandWithTranslation.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,33 @@ protected function get_installed_languages( $slug = 'default' ) {
320320
/**
321321
* @var array<string, array<string, array<string, mixed>>> $available
322322
*/
323-
$available = wp_get_installed_translations( $this->obj_type );
324-
$available = ! empty( $available[ $slug ] ) ? array_keys( $available[ $slug ] ) : array();
323+
$available = wp_get_installed_translations( $this->obj_type );
324+
325+
// For plugins and themes, check if the text domain differs from the slug.
326+
$text_domain = $slug;
327+
if ( 'default' !== $slug ) {
328+
if ( 'plugins' === $this->obj_type ) {
329+
$plugins = get_plugins( '/' . $slug );
330+
if ( ! empty( $plugins ) ) {
331+
$plugin_data = array_shift( $plugins );
332+
// Use the TextDomain header if available, otherwise fall back to slug.
333+
if ( ! empty( $plugin_data['TextDomain'] ) ) {
334+
$text_domain = $plugin_data['TextDomain'];
335+
}
336+
}
337+
} elseif ( 'themes' === $this->obj_type ) {
338+
$theme_data = wp_get_theme( $slug );
339+
if ( $theme_data->exists() ) {
340+
// Use the TextDomain property if available, otherwise fall back to slug.
341+
$theme_text_domain = $theme_data->get( 'TextDomain' );
342+
if ( ! empty( $theme_text_domain ) ) {
343+
$text_domain = $theme_text_domain;
344+
}
345+
}
346+
}
347+
}
348+
349+
$available = ! empty( $available[ $text_domain ] ) ? array_keys( $available[ $text_domain ] ) : array();
325350
$available[] = 'en_US';
326351

327352
return $available;

0 commit comments

Comments
 (0)