Skip to content
Merged
41 changes: 24 additions & 17 deletions features/language-core.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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`
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
21 changes: 13 additions & 8 deletions features/language-plugin.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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`
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
21 changes: 13 additions & 8 deletions features/language-theme.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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`
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
23 changes: 18 additions & 5 deletions src/Core_Language_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,37 +168,50 @@ 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++;
}
}

if ( WP_CLI\Utils\get_flag_value( $assoc_args, 'activate' ) ) {
$this->activate_language( $language_code );
}
}

\WP_CLI\Utils\report_batch_operation_results( 'language', 'install', $count, $successes, $errors, $skips );
}

/**
Expand Down
21 changes: 17 additions & 4 deletions src/Plugin_Language_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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." );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a skip or a success? Looks like media would treat it as a success.

https://github.com/wp-cli/media-command/blob/337459d/src/Media_Command.php#L590-L600

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the success message, I think we can leave it as is.

Success: Installed 0 of 1 languages (1 skipped).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, makes sense to me.

$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 );
}

/**
Expand Down
21 changes: 17 additions & 4 deletions src/Theme_Language_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down