Always set the Language property on translation updates - #187
Always set the Language property on translation updates#187victorcamnerin wants to merge 1 commit into
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. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe translation update path now falls back to the existing language value when the API does not provide ChangesTranslation update fallback
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The update now shows the locale code instead of emitting an undefined-property warning when translation metadata is unavailable. No actionable merge-blocking risk remains beyond normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (1 skipped: 1 unsupported.) ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Some tools did not complete. Review the errors below. 🔧 PHPStan (2.2.8)Invalid configuration: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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? 🤔 |
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 two sides can legitimately disagree:
get_translation_updates()filters the update check throughplugins_update_check_locales,so the transient offers a pack for every locale installed on the site.
get_all_languages()then re-queriestranslations_api()pinned to the installedextension version.
When that response doesn't list the locale,
wp_list_filter()returns an empty array,reset()yieldsfalse, and(object) falsehas noenglish_name.This is easy to hit on a multi-locale site with a mixed set of extensions — we see it a few
times a day on a production site running five locales, from a nightly
wp language plugin update --all. It is cosmetic (it happens before$upgrader->upgrade(),and the packs still install), but it produces a steady stream of PHP warnings in cron output
and error trackers. The guard has been unchanged since v2.0.0.
Falling back to the raw locale code keeps the line meaningful:
Updating 'de_DE' translation for Akismet 4.0...rather thanUpdating '' translation for Akismet 4.0....Testing
Adds a Behat scenario that mocks the translations API to return
{"translations":[]}afterthe update check has already offered a
de_DEpack, then assertsSTDERRis empty. It failson
mainand passes with this change.I could not run
composer phpcsorcomposer behatlocally — my environment has no networkaccess to
codeload.github.com, so dev dependencies would not install. Onlyphp -lwasverified here; please let CI be the judge on the rest.
Summary by CodeRabbit