Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions features/language-core.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions features/language-plugin.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions features/language-theme.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
39 changes: 28 additions & 11 deletions src/Core_Language_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,38 +246,55 @@ 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;
foreach ( $files as $file ) {
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;
}

Expand Down
47 changes: 31 additions & 16 deletions src/Plugin_Language_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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." );
Expand Down
47 changes: 31 additions & 16 deletions src/Theme_Language_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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." );
Expand Down