Skip to content

Commit 069b988

Browse files
Copilotswissspidy
andcommitted
Fix language status for plugins/themes with different text domain than slug
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent cf8304a commit 069b988

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

‎src/WP_CLI/CommandWithTranslation.php‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,30 @@ protected function get_installed_languages( $slug = 'default' ) {
283283
/**
284284
* @var array<string, array<string, array<string, mixed>>> $available
285285
*/
286-
$available = wp_get_installed_translations( $this->obj_type );
287-
$available = ! empty( $available[ $slug ] ) ? array_keys( $available[ $slug ] ) : array();
286+
$available = wp_get_installed_translations( $this->obj_type );
287+
288+
// For plugins and themes, check if the text domain differs from the slug.
289+
$text_domain = $slug;
290+
if ( 'default' !== $slug ) {
291+
if ( 'plugins' === $this->obj_type ) {
292+
$plugins = get_plugins( '/' . $slug );
293+
if ( ! empty( $plugins ) ) {
294+
$plugin_data = array_shift( $plugins );
295+
// Use the TextDomain header if available, otherwise fall back to slug.
296+
if ( ! empty( $plugin_data['TextDomain'] ) ) {
297+
$text_domain = $plugin_data['TextDomain'];
298+
}
299+
}
300+
} elseif ( 'themes' === $this->obj_type ) {
301+
$theme_data = wp_get_theme( $slug );
302+
// Use the TextDomain property if available, otherwise fall back to slug.
303+
if ( ! empty( $theme_data->get( 'TextDomain' ) ) ) {
304+
$text_domain = $theme_data->get( 'TextDomain' );
305+
}
306+
}
307+
}
308+
309+
$available = ! empty( $available[ $text_domain ] ) ? array_keys( $available[ $text_domain ] ) : array();
288310
$available[] = 'en_US';
289311

290312
return $available;

0 commit comments

Comments
 (0)