diff --git a/features/language-core.feature b/features/language-core.feature index ec23efdf7..bcf81f9c7 100644 --- a/features/language-core.feature +++ b/features/language-core.feature @@ -31,7 +31,7 @@ Feature: Manage translation files for a WordPress install And the wp-content/languages/en_AU.po file should exist And STDOUT should contain: """ - Success: Language installed. + Success: Installed 1 of 1 languages. """ And STDERR should be empty @@ -48,7 +48,7 @@ Feature: Manage translation files for a WordPress install And the wp-content/languages/ja.po file should exist And STDOUT should contain: """ - Success: Language installed. + Success: Installed 2 of 2 languages. """ And STDERR should be empty @@ -63,11 +63,12 @@ Feature: Manage translation files for a WordPress install """ When I try `wp language core install en_AU` - Then STDERR should be: + Then STDOUT should be: """ - Warning: Language 'en_AU' already installed. + Language 'en_AU' already installed. + Success: Installed 0 of 1 languages (1 skipped). """ - And STDOUT should be empty + And STDERR should be empty And the return code should be 0 When I run `wp language core list --fields=language,english_name,status` @@ -111,23 +112,25 @@ Feature: Manage translation files for a WordPress install | en_GB | English (UK) | active | When I try `wp language core install en_AU --activate` - Then STDERR should contain: - """ - Warning: Language 'en_AU' already installed. - """ + Then STDERR should be empty And STDOUT should be: """ + Language 'en_AU' already installed. Success: Language activated. + Success: Installed 0 of 1 languages (1 skipped). """ And the return code should be 0 When I try `wp language core install en_AU --activate` Then STDERR should contain: """ - Warning: Language 'en_AU' already installed. Warning: Language 'en_AU' already active. """ - And STDOUT should be empty + And STDOUT should contain: + """ + Language 'en_AU' already installed. + Success: Installed 0 of 1 languages (1 skipped). + """ And the return code should be 0 When I try `wp language core install en_CA ja --activate` @@ -191,17 +194,21 @@ Feature: Manage translation files for a WordPress install And the wp-content/languages/en_GB.po file should exist And STDOUT should contain: """ - Success: Language installed. Success: Language activated. + Success: Installed 1 of 1 languages. """ And STDERR should be empty When I try `wp language core install invalid_lang` Then STDERR should be: """ - Error: Language 'invalid_lang' not found. + Warning: Language 'invalid_lang' not found. + Error: No languages installed (1 failed). + """ + And STDOUT should be: + """ + Language 'invalid_lang' not installed. """ - And STDOUT should be empty And the return code should be 1 @require-wp-latest @require-php-5.6 @less-than-php-7.0 @@ -228,7 +235,7 @@ Feature: Manage translation files for a WordPress install And the wp-content/languages/ja.po file should exist And STDOUT should contain: """ - Success: Language installed. + Success: Installed 2 of 2 languages. """ And STDERR should be empty @@ -345,7 +352,7 @@ Feature: Manage translation files for a WordPress install And the wp-content/languages/de_DE.po file should exist And STDOUT should contain: """ - Success: Language installed. + Success: Installed 1 of 1 languages. """ And STDERR should be empty @@ -392,7 +399,7 @@ Feature: Manage translation files for a WordPress install And the wp-content/languages/de_DE_formal.po file should exist And STDOUT should contain: """ - Success: Language installed. + Success: Installed 1 of 1 languages. """ And STDERR should be empty diff --git a/features/language-plugin.feature b/features/language-plugin.feature index 804e86b1f..ca2662412 100644 --- a/features/language-plugin.feature +++ b/features/language-plugin.feature @@ -32,7 +32,7 @@ Feature: Manage translation files for a WordPress install Then the wp-content/languages/plugins/hello-dolly-en_GB.po file should exist And STDOUT should contain: """ - Success: Language installed. + Success: Installed 1 of 1 languages. """ And STDERR should be empty @@ -41,7 +41,7 @@ Feature: Manage translation files for a WordPress install And the wp-content/languages/plugins/hello-dolly-de_DE.po file should exist And STDOUT should contain: """ - Success: Language installed. + Success: Installed 2 of 2 languages. """ And STDERR should be empty @@ -62,11 +62,12 @@ Feature: Manage translation files for a WordPress install """ When I try `wp language plugin install hello-dolly en_GB` - Then STDERR should be: + Then STDERR should be empty + And STDOUT should be: """ - Warning: Language 'en_GB' already installed. + Language 'en_GB' already installed. + Success: Installed 0 of 1 languages (1 skipped). """ - And STDOUT should be empty And the return code should be 0 When I run `wp language plugin list hello-dolly --fields=language,english_name,status` @@ -141,9 +142,13 @@ Feature: Manage translation files for a WordPress install When I try `wp language plugin install hello-dolly invalid_lang` Then STDERR should be: """ - Error: Language 'invalid_lang' not found. + Warning: Language 'invalid_lang' not found. + Error: No languages installed (1 failed). + """ + And STDOUT should be: + """ + Language 'invalid_lang' not installed. """ - And STDOUT should be empty And the return code should be 1 @require-wp-4.0 @@ -157,7 +162,7 @@ Feature: Manage translation files for a WordPress install Then the wp-content/languages/plugins/hello-dolly-en_GB.po file should exist And STDOUT should contain: """ - Success: Language installed. + Success: Installed 1 of 1 languages. """ And STDERR should be empty diff --git a/features/language-theme.feature b/features/language-theme.feature index 85aeb9552..175221d37 100644 --- a/features/language-theme.feature +++ b/features/language-theme.feature @@ -31,7 +31,7 @@ Feature: Manage translation files for a WordPress install Then the wp-content/languages/themes/twentyten-en_GB.po file should exist And STDOUT should contain: """ - Success: Language installed. + Success: Installed 1 of 1 languages. """ And STDERR should be empty @@ -40,7 +40,7 @@ Feature: Manage translation files for a WordPress install And the wp-content/languages/themes/twentyten-de_DE.po file should exist And STDOUT should contain: """ - Success: Language installed. + Success: Installed 2 of 2 languages. """ And STDERR should be empty @@ -61,11 +61,12 @@ Feature: Manage translation files for a WordPress install """ When I try `wp language theme install twentyten en_GB` - Then STDERR should be: + Then STDERR should be empty + And STDOUT should be: """ - Warning: Language 'en_GB' already installed. + Language 'en_GB' already installed. + Success: Installed 0 of 1 languages (1 skipped). """ - And STDOUT should be empty And the return code should be 0 When I run `wp language theme list twentyten --fields=language,english_name,status` @@ -126,9 +127,13 @@ Feature: Manage translation files for a WordPress install When I try `wp language theme install twentyten invalid_lang` Then STDERR should be: """ - Error: Language 'invalid_lang' not found. + Warning: Language 'invalid_lang' not found. + Error: No languages installed (1 failed). + """ + And STDOUT should be: + """ + Language 'invalid_lang' not installed. """ - And STDOUT should be empty And the return code should be 1 @require-wp-4.0 @@ -142,7 +147,7 @@ Feature: Manage translation files for a WordPress install Then the wp-content/languages/themes/twentyten-en_GB.po file should exist And STDOUT should contain: """ - Success: Language installed. + Success: Installed 1 of 1 languages. """ And STDERR should be empty diff --git a/src/Core_Language_Command.php b/src/Core_Language_Command.php index 141289981..f5c5b1e14 100644 --- a/src/Core_Language_Command.php +++ b/src/Core_Language_Command.php @@ -168,30 +168,41 @@ public function is_installed( $args, $assoc_args = array() ) { * * # Install the Japanese language. * $ wp language core install ja - * Success: Language installed. + * Downloading translation from https://downloads.wordpress.org/translation/core/4.9.8/ja.zip... + * Unpacking the update... + * Installing the latest version... + * Translation updated successfully. + * Language 'ja' installed. + * Success: Installed 1 of 1 languages. * * @subcommand install */ public function install( $args, $assoc_args ) { $language_codes = (array) $args; + $count = count( $language_codes ); - if( 1 < count( $language_codes ) && in_array( true , $assoc_args , true ) ){ + if ( $count > 1 && in_array( true, $assoc_args, true ) ) { WP_CLI::error( 'Only a single language can be active.' ); } $available = $this->get_installed_languages(); + $successes = $errors = $skips = 0; foreach ( $language_codes as $language_code ) { if ( in_array( $language_code, $available, true ) ) { - WP_CLI::warning( "Language '{$language_code}' already installed." ); + \WP_CLI::log( "Language '{$language_code}' already installed." ); + $skips++; } else { $response = $this->download_language_pack( $language_code ); if ( is_wp_error( $response ) ) { - WP_CLI::error( $response ); + \WP_CLI::warning( $response ); + \WP_CLI::log( "Language '{$language_code}' not installed." ); + $errors++; } else { - WP_CLI::success( 'Language installed.' ); + \WP_CLI::log( "Language '{$language_code}' installed." ); + $successes++; } } @@ -199,6 +210,8 @@ public function install( $args, $assoc_args ) { $this->activate_language( $language_code ); } } + + \WP_CLI\Utils\report_batch_operation_results( 'language', 'install', $count, $successes, $errors, $skips ); } /** diff --git a/src/Plugin_Language_Command.php b/src/Plugin_Language_Command.php index 72996c4f3..e5038a7e9 100644 --- a/src/Plugin_Language_Command.php +++ b/src/Plugin_Language_Command.php @@ -199,30 +199,43 @@ public function is_installed( $args, $assoc_args = array() ) { * * # Install the Japanese language for Akismet. * $ wp language plugin install akismet ja - * Success: Language installed. + * Downloading translation from https://downloads.wordpress.org/translation/plugin/akismet/4.0.3/ja.zip... + * Unpacking the update... + * Installing the latest version... + * Translation updated successfully. + * Language 'ja' installed. + * Success: Installed 1 of 1 languages. * * @subcommand install */ public function install( $args, $assoc_args ) { $plugin = array_shift( $args ); $language_codes = (array) $args; + $count = count( $language_codes ); $available = $this->get_installed_languages( $plugin ); + $successes = $errors = $skips = 0; foreach ( $language_codes as $language_code ) { if ( in_array( $language_code, $available, true ) ) { - \WP_CLI::warning( "Language '{$language_code}' already installed." ); + \WP_CLI::log( "Language '{$language_code}' already installed." ); + $skips++; } else { $response = $this->download_language_pack( $language_code, $plugin ); if ( is_wp_error( $response ) ) { - \WP_CLI::error( $response ); + \WP_CLI::warning( $response ); + \WP_CLI::log( "Language '{$language_code}' not installed." ); + $errors++; } else { - \WP_CLI::success( 'Language installed.' ); + \WP_CLI::log( "Language '{$language_code}' installed." ); + $successes++; } } } + + \WP_CLI\Utils\report_batch_operation_results( 'language', 'install', $count, $successes, $errors, $skips ); } /** diff --git a/src/Theme_Language_Command.php b/src/Theme_Language_Command.php index 8a23c023b..5f4ce7a73 100644 --- a/src/Theme_Language_Command.php +++ b/src/Theme_Language_Command.php @@ -201,30 +201,43 @@ public function is_installed( $args, $assoc_args = array() ) { * * # Install the Japanese language for Twenty Seventeen. * $ wp language theme install twentyseventeen ja - * Success: Language installed. + * Downloading translation from https://downloads.wordpress.org/translation/theme/twentyseventeen/1.3/ja.zip... + * Unpacking the update... + * Installing the latest version... + * Translation updated successfully. + * Language 'ja' installed. + * Success: Installed 1 of 1 languages. * * @subcommand install */ public function install( $args, $assoc_args ) { $theme = array_shift( $args ); $language_codes = (array) $args; + $count = count( $language_codes ); $available = $this->get_installed_languages( $theme ); + $successes = $errors = $skips = 0; foreach ( $language_codes as $language_code ) { if ( in_array( $language_code, $available, true ) ) { - \WP_CLI::warning( "Language '{$language_code}' already installed." ); + \WP_CLI::log( "Language '{$language_code}' already installed." ); + $skips++; } else { $response = $this->download_language_pack( $language_code, $theme ); if ( is_wp_error( $response ) ) { - \WP_CLI::error( $response ); + \WP_CLI::warning( $response ); + \WP_CLI::log( "Language '{$language_code}' not installed." ); + $errors++; } else { - \WP_CLI::success( 'Language installed.' ); + \WP_CLI::log( "Language '{$language_code}' installed." ); + $successes++; } } } + + \WP_CLI\Utils\report_batch_operation_results( 'language', 'install', $count, $successes, $errors, $skips ); } /**