diff --git a/features/language-plugin.feature b/features/language-plugin.feature index a94e9636..b4bc38d8 100644 --- a/features/language-plugin.feature +++ b/features/language-plugin.feature @@ -444,3 +444,35 @@ 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 + And a wp-content/plugins/test-plugin/test-plugin.php file: + """ + >> $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 ); + 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; + } + } + } + } + + $available = ! empty( $available[ $text_domain ] ) ? array_keys( $available[ $text_domain ] ) : array(); $available[] = 'en_US'; return $available;