Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add is-installed command to check if a given language is installed #36

Merged
merged 3 commits into from Jul 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 24 additions & 2 deletions README.md
Expand Up @@ -63,8 +63,6 @@ wp language core





### wp language core activate

Activates a given language.
Expand All @@ -85,6 +83,30 @@ wp language core activate <language>



### wp language core is-installed

Checks if a given language is installed.

~~~
wp language core is-installed <language>
~~~

Returns exit code 0 when installed, 1 when uninstalled.

**OPTIONS**

<language>
The language code to check.

**EXAMPLES**

# Check whether the German language is installed; exit status 0 if installed, otherwise 1.
$ wp language core is-installed de_DE
$ echo $?
1



### wp language core install

Installs a given language.
Expand Down
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -37,6 +37,7 @@
"language",
"language core",
"language core activate",
"language core is-installed",
"language core install",
"language core list",
"language core uninstall",
Expand Down
14 changes: 14 additions & 0 deletions features/language-core.feature
Expand Up @@ -13,6 +13,14 @@ Feature: Manage translation files for a WordPress install
| en_US | English (United States) | active |
| en_GB | English (UK) | uninstalled |

When I try `wp language core is-installed en_GB`
Then the return code should be 1
And STDERR should be empty

When I try `wp language core is-installed en_AU`
Then the return code should be 1
And STDERR should be empty

When I run `wp language core install en_GB`
And I run `wp language core install en_AU`
Then the wp-content/languages/admin-en_GB.po file should exist
Expand All @@ -23,6 +31,12 @@ Feature: Manage translation files for a WordPress install
"""
And STDERR should be empty

When I try `wp language core is-installed en_GB`
Then the return code should be 0

When I try `wp language core is-installed en_AU`
Then the return code should be 0

When I run `wp language core install en_CA en_NZ`
Then the wp-content/languages/admin-en_CA.po file should exist
And the wp-content/languages/en_CA.po file should exist
Expand Down
32 changes: 32 additions & 0 deletions src/WP_CLI/CommandWithTranslation.php
Expand Up @@ -121,6 +121,38 @@ protected function sort_translations_callback( $a, $b ) {
return strnatcasecmp( $a['language'], $b['language'] );
}

/**
* Checks if a given language is installed.
*
* Returns exit code 0 when installed, 1 when uninstalled.
*
* ## OPTIONS
*
* <language>
* : The language code to check.
*
* ## EXAMPLES
*
* # Check whether the German language is installed; exit status 0 if installed, otherwise 1.
* $ wp language core is-installed de_DE
* $ echo $?
* 1
*
* @subcommand is-installed
*/
public function is_installed( $args, $assoc_args = array() ) {

list( $language_code ) = $args;

$available = $this->get_installed_languages();

if ( in_array( $language_code, $available, true ) ) {
\WP_CLI::halt( 0 );
} else {
\WP_CLI::halt( 1 );
}
}

/**
* Installs a given language.
*
Expand Down