diff --git a/features/language-core.feature b/features/language-core.feature index 250b6166..f4bcf251 100644 --- a/features/language-core.feature +++ b/features/language-core.feature @@ -165,6 +165,7 @@ Feature: Manage translation files for a WordPress install When I run `wp language core uninstall en_GB` Then the wp-content/languages/admin-en_GB.po file should not exist And the wp-content/languages/en_GB.po file should not exist + And the wp-content/languages/en_GB.l10n.php file should not exist And STDOUT should be: """ Success: Language uninstalled. @@ -173,8 +174,10 @@ Feature: Manage translation files for a WordPress install When I run `wp language core uninstall en_CA ja` Then the wp-content/languages/admin-en_CA.po file should not exist And the wp-content/languages/en_CA.po file should not exist + And the wp-content/languages/en_CA.l10n.php file should not exist And the wp-content/languages/admin-ja.po file should not exist And the wp-content/languages/ja.po file should not exist + And the wp-content/languages/ja.l10n.php file should not exist And STDOUT should be: """ Success: Language uninstalled. diff --git a/features/language-plugin.feature b/features/language-plugin.feature index 841edf83..ab2e8693 100644 --- a/features/language-plugin.feature +++ b/features/language-plugin.feature @@ -125,8 +125,10 @@ Feature: Manage translation files for a WordPress install When I run `wp language plugin uninstall hello-dolly cs_CZ de_DE` Then the wp-content/languages/plugins/hello-dolly-cs_CZ.po file should not exist And the wp-content/languages/plugins/hello-dolly-cs_CZ.mo file should not exist + And the wp-content/languages/plugins/hello-dolly-cs_CZ.l10n.php file should not exist And the wp-content/languages/plugins/hello-dolly-de_DE.po file should not exist And the wp-content/languages/plugins/hello-dolly-de_DE.mo file should not exist + And the wp-content/languages/plugins/hello-dolly-de_DE.l10n.php file should not exist And STDOUT should contain: """ Language 'cs_CZ' for 'hello-dolly' uninstalled. diff --git a/features/language-theme.feature b/features/language-theme.feature index dff36c91..c3b16618 100644 --- a/features/language-theme.feature +++ b/features/language-theme.feature @@ -119,8 +119,10 @@ Feature: Manage translation files for a WordPress install When I run `wp language theme uninstall twentyten cs_CZ de_DE` Then the wp-content/languages/themes/twentyten-cs_CZ.po file should not exist And the wp-content/languages/themes/twentyten-cs_CZ.mo file should not exist + And the wp-content/languages/themes/twentyten-cs_CZ.l10n.php file should not exist And the wp-content/languages/themes/twentyten-de_DE.po file should not exist And the wp-content/languages/themes/twentyten-de_DE.mo file should not exist + And the wp-content/languages/themes/twentyten-de_DE.l10n.php file should not exist """ Success: Language 'cs_CZ' for 'twentyten' uninstalled. Success: Language 'de_DE' for 'twentyten' uninstalled. diff --git a/src/Core_Language_Command.php b/src/Core_Language_Command.php index 8430bc53..ebdee964 100644 --- a/src/Core_Language_Command.php +++ b/src/Core_Language_Command.php @@ -246,28 +246,43 @@ public function install( $args, $assoc_args ) { public function uninstall( $args, $assoc_args ) { global $wp_filesystem; + $dir = 'core' === $this->obj_type ? '' : "/$this->obj_type"; + $files = scandir( WP_LANG_DIR . $dir ); + if ( ! $files ) { + WP_CLI::error( 'No files found in language directory.' ); + } + $language_codes = (array) $args; $available = $this->get_installed_languages(); - foreach ( $language_codes as $language_code ) { + $current_locale = get_locale(); + foreach ( $language_codes as $language_code ) { if ( ! in_array( $language_code, $available, true ) ) { WP_CLI::error( 'Language not installed.' ); } - $dir = 'core' === $this->obj_type ? '' : "/$this->obj_type"; - $files = scandir( WP_LANG_DIR . $dir ); - if ( ! $files ) { - WP_CLI::error( 'No files found in language directory.' ); - } - - $current_locale = get_locale(); if ( $language_code === $current_locale ) { WP_CLI::warning( "The '{$language_code}' language is active." ); exit; } + $files_to_remove = array( + "$language_code.po", + "$language_code.mo", + "$language_code.l10n.php", + "admin-$language_code.po", + "admin-$language_code.mo", + "admin-$language_code.l10n.php", + "admin-network-$language_code.po", + "admin-network-$language_code.mo", + "admin-network-$language_code.l10n.php", + "continents-cities-$language_code.po", + "continents-cities-$language_code.mo", + "continents-cities-$language_code.l10n.php", + ); + // As of WP 4.0, no API for deleting a language pack WP_Filesystem(); $deleted = false; @@ -275,9 +290,11 @@ public function uninstall( $args, $assoc_args ) { if ( '.' === $file[0] || is_dir( $file ) ) { continue; } - $extension_length = strlen( $language_code ) + 4; - $ending = substr( $file, -$extension_length ); - if ( ! in_array( $file, array( $language_code . '.po', $language_code . '.mo' ), true ) && ! in_array( $ending, array( '-' . $language_code . '.po', '-' . $language_code . '.mo' ), true ) ) { + + if ( + ! in_array( $file, $files_to_remove, true ) && + ! preg_match( "/$language_code-\w{32}\.json/", $file ) + ) { continue; } diff --git a/src/Plugin_Language_Command.php b/src/Plugin_Language_Command.php index 31f82887..4327bc32 100644 --- a/src/Plugin_Language_Command.php +++ b/src/Plugin_Language_Command.php @@ -475,25 +475,40 @@ public function uninstall( $args, $assoc_args ) { exit; } - $po_file = "{$dir}/{$plugin}-{$language_code}.po"; - $mo_file = "{$dir}/{$plugin}-{$language_code}.mo"; - - $files_to_remove = array( $po_file, $mo_file ); - - $count_files_removed = 0; - $had_one_file = 0; - foreach ( $files_to_remove as $file ) { - if ( $wp_filesystem->exists( $file ) ) { - $had_one_file = 1; - if ( $wp_filesystem->delete( $file ) ) { - ++$count_files_removed; - } else { - \WP_CLI::error( "Couldn't uninstall language: $language_code from plugin $plugin." ); - } + $files_to_remove = array( + "$plugin-$language_code.po", + "$plugin-$language_code.mo", + "$plugin-$language_code.l10n.php", + ); + + $count_files_to_remove = 0; + $count_files_removed = 0; + $had_one_file = false; + + foreach ( $files as $file ) { + if ( '.' === $file[0] || is_dir( $file ) ) { + continue; + } + + if ( + ! in_array( $file, $files_to_remove, true ) && + ! preg_match( "/$plugin-$language_code-\w{32}\.json/", $file ) + ) { + continue; + } + + $had_one_file = true; + + ++$count_files_to_remove; + + if ( $wp_filesystem->delete( $dir . '/' . $file ) ) { + ++$count_files_removed; + } else { + \WP_CLI::error( "Couldn't uninstall language: $language_code from plugin $plugin." ); } } - if ( count( $files_to_remove ) === $count_files_removed ) { + if ( $count_files_to_remove === $count_files_removed ) { $result['status'] = 'uninstalled'; ++$successes; \WP_CLI::log( "Language '{$language_code}' for '{$plugin}' uninstalled." ); diff --git a/src/Theme_Language_Command.php b/src/Theme_Language_Command.php index 65c5e605..9be32903 100644 --- a/src/Theme_Language_Command.php +++ b/src/Theme_Language_Command.php @@ -486,25 +486,40 @@ public function uninstall( $args, $assoc_args ) { exit; } - $po_file = "{$dir}/{$theme}-{$language_code}.po"; - $mo_file = "{$dir}/{$theme}-{$language_code}.mo"; - - $files_to_remove = array( $po_file, $mo_file ); - - $count_files_removed = 0; - $had_one_file = 0; - foreach ( $files_to_remove as $file ) { - if ( $wp_filesystem->exists( $file ) ) { - $had_one_file = 1; - if ( $wp_filesystem->delete( $file ) ) { - ++$count_files_removed; - } else { - \WP_CLI::error( "Couldn't uninstall language: $language_code from theme $theme." ); - } + $files_to_remove = array( + "$theme-$language_code.po", + "$theme-$language_code.mo", + "$theme-$language_code.l10n.php", + ); + + $count_files_to_remove = 0; + $count_files_removed = 0; + $had_one_file = false; + + foreach ( $files as $file ) { + if ( '.' === $file[0] || is_dir( $file ) ) { + continue; + } + + if ( + ! in_array( $file, $files_to_remove, true ) && + ! preg_match( "/$theme-$language_code-\w{32}\.json/", $file ) + ) { + continue; + } + + $had_one_file = true; + + ++$count_files_to_remove; + + if ( $wp_filesystem->delete( $dir . '/' . $file ) ) { + ++$count_files_removed; + } else { + \WP_CLI::error( "Couldn't uninstall language: $language_code from theme $theme." ); } } - if ( count( $files_to_remove ) === $count_files_removed ) { + if ( $count_files_to_remove === $count_files_removed ) { $result['status'] = 'uninstalled'; ++$successes; \WP_CLI::log( "Language '{$language_code}' for '{$theme}' uninstalled." );