Repository navigation
Always set the Language property on translation updates - #187
Conversation
`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.
|
Hello! 👋 Thanks for opening this pull request! Please check out our contributing guidelines. We appreciate you taking the initiative to contribute to this project. Contributing isn't limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation. Here are some useful Composer commands to get you started:
To run a single Behat test, you can use the following command: # Run all tests in a single file
composer behat features/some-feature.feature
# Run only a specific scenario (where 123 is the line number of the "Scenario:" title)
composer behat features/some-feature.feature:123You can find a list of all available Behat steps in our handbook. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Is it? I would appreciate some clear reproduction steps. Sounds like the translation API is returning some fields but not all? 🤔 |
|
Turns out my description was off. I dug into the two sites that log this, and the packs that trigger it never come from wordpress.org in the first place. Plugins that host their own language packs append entries to the So it's not a partial response, there's simply no entry for the locale. Reproduction (no premium plugin needed, any WP install with
<?php
add_filter( 'site_transient_update_plugins', function ( $value ) {
if ( ! is_object( $value ) ) {
$value = new stdClass();
}
$value->translations[] = array(
'type' => 'plugin',
'slug' => 'my-private-plugin',
'language' => 'de_DE',
'version' => '0.1.0',
'updated' => '2026-01-01 00:00:00',
'package' => 'https://example.invalid/my-private-plugin-de_DE.zip',
'autoupdate' => true,
);
return $value;
} );Without You could argue this is on the plugins to return the right shape from |
|
Thanks for digging into this, that's a much clearer picture. Those plugins are wrong: if you inject packs into That said, I'm fine with landing the fallback. Reading One ask before merging: please update the PR description to match the actual cause (a pack in the transient whose slug the translations API doesn't know), since the current text still tells the multi-locale / version-pinning story. |
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
No unresolved blocking issues were identified.
Review effort: Lite
Findings: None
What changed in this PR
Fixes translation update logging by falling back to the raw locale when translation metadata is unavailable.
Changes:
- Always assigns the translation
Languageproperty. - Adds Behat coverage for missing translation metadata.
| File | Description |
|---|---|
src/WP_CLI/CommandWithTranslation.php |
Adds locale fallback handling. |
features/language-plugin.feature |
Tests updates when the API returns no translations. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
I get this warning too when updating wordpress-seo-premium:
|
Summary
CommandWithTranslation::update()logs every pack it is about to install with"Updating '{$update->Language}' translation for {$update->Name} {$update->Version}...",but
Languageis only assigned inside anisset( $translation->english_name )guard. Whenthat lookup misses, the property is never set, so PHP 8 raises
Warning: Undefined property: stdClass::$Languageand the locale prints as an empty string.The lookup misses when a language pack in the
update_plugins/update_themestransientbelongs to a slug that the wordpress.org translations API doesn't know:
pre_set_site_transient_update_plugins/site_transient_update_plugins(e.g. the TranslationsPress library used by Yoast SEO Premium and Gravity Forms, or
WC_Helper_Updaterfor WooCommerce.com extensions).get_translation_updates()picks them up.get_all_languages()then askstranslations_api()about that slug. Unless the plugin alsofilters
translations_apiand returns data in the wordpress.org shape(
{"translations": [...]}), the response is{"translations":[]},wp_list_filter()returns[],reset()yieldsfalse, and(object) falsehas noenglish_name.Strictly speaking, such plugins should answer
translations_apifor their own slug.But reading
$update->Languagewhen it is only set conditionally is a bug on WP-CLI's sideregardless of what the API returns. The packs still install (the warning happens before
$upgrader->upgrade()), so falling back to the raw locale code is the right behaviour:Updating 'de_DE' translation for My Private Plugin 0.1.0...instead ofUpdating '' translation for My Private Plugin 0.1.0...plus a PHP warning.Reproduction
Any WP install with
WP_DEBUGenabled:wp-content/mu-plugins/private-language-packs.php:Testing
Adds a Behat scenario that mocks the translations API to return
{"translations":[]}while theupdate check still offers a
de_DEpack, then asserts the locale code is printed andSTDERRis empty. It fails on
mainand passes with this change.Summary by CodeRabbit
Generated by Claude Code