Skip to content

Commit 5b1b51f

Browse files
Always set the Language property on translation updates
`wp language <core|plugin|theme> update` reads `$update->Language` when logging each pack it is about to install, but only assigned it when the translations API returned an `english_name` for that locale. The two sides can disagree: the update check offers packs for every locale installed on the site, while `get_all_languages()` re-queries the translations API pinned to the *installed* extension version. When that lookup returns nothing, `reset()` yields false, the property is never set, and PHP 8 raises "Warning: Undefined property: stdClass::$Language" before printing the locale as an empty string. Fall back to the raw locale code so the line stays meaningful and the command stays warning-free.
1 parent 1929dfe commit 5b1b51f

2 files changed

Lines changed: 38 additions & 7 deletions

File tree

‎features/language-plugin.feature‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,3 +592,35 @@ Feature: Manage plugin translation files for a WordPress install
592592
# If the fix is working, installed languages should be detected via text domain
593593
When I run `wp language plugin is-installed test-plugin de_DE`
594594
Then the return code should be 0
595+
596+
@require-wp-4.0
597+
Scenario: Update a translation that the translations API does not list
598+
Given a WP install
599+
And an empty cache
600+
601+
When I run `wp plugin install akismet --version=3.2 --force`
602+
Then STDERR should be empty
603+
604+
When I run `wp language plugin install akismet de_DE`
605+
Then STDERR should be empty
606+
607+
When I run `wp plugin install akismet --version=4.0 --force`
608+
Then STDERR should be empty
609+
610+
# The update check still offers the de_DE language pack, but the translations
611+
# API no longer reports de_DE for the installed version, so there is no
612+
# english_name to fall back on.
613+
And that HTTP requests to api.wordpress.org/translations/plugins/1.0/ will respond with:
614+
"""
615+
HTTP/1.1 200
616+
Content-Type: application/json
617+
618+
{"translations":[]}
619+
"""
620+
621+
When I run `wp language plugin update akismet`
622+
Then STDOUT should contain:
623+
"""
624+
Updating 'de_DE' translation for Akismet
625+
"""
626+
And STDERR should be empty

‎src/WP_CLI/CommandWithTranslation.php‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,12 @@ public function update( $args, $assoc_args ) {
106106
$translation = wp_list_filter( $all_languages, array( 'language' => $update->language ) );
107107
$translation = (object) reset( $translation );
108108

109-
$update->Type = ucfirst( $update->type );
110-
$update->Name = $name;
111-
$update->Version = $update->version;
112-
113-
if ( isset( $translation->english_name ) ) {
114-
$update->Language = $translation->english_name;
115-
}
109+
$update->Type = ucfirst( $update->type );
110+
$update->Name = $name;
111+
$update->Version = $update->version;
112+
$update->Language = isset( $translation->english_name )
113+
? $translation->english_name
114+
: $update->language;
116115

117116
if ( ! isset( $updates_per_type[ $update->type ] ) ) {
118117
$updates_per_type[ $update->type ] = array();

0 commit comments

Comments
 (0)