Skip to content

Always set the Language property on translation updates - #187

Merged
swissspidy merged 3 commits into
wp-cli:mainfrom
victorcamnerin:fix/undefined-language-property
Dec 1, 2026
Merged

swissspidy merged 3 commits into
wp-cli:mainfrom
victorcamnerin:fix/undefined-language-property

Conversation

@victorcamnerin

@victorcamnerin victorcamnerin commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

CommandWithTranslation::update() logs every pack it is about to install with
"Updating '{$update->Language}' translation for {$update->Name} {$update->Version}...",
but Language is only assigned inside an isset( $translation->english_name ) guard. When
that lookup misses, the property is never set, so PHP 8 raises
Warning: Undefined property: stdClass::$Language and the locale prints as an empty string.

The lookup misses when a language pack in the update_plugins / update_themes transient
belongs to a slug that the wordpress.org translations API doesn't know:

  • Plugins that host their own language packs add entries to the transient via
    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_Updater for WooCommerce.com extensions). get_translation_updates() picks them up.
  • get_all_languages() then asks translations_api() about that slug. Unless the plugin also
    filters translations_api and returns data in the wordpress.org shape
    ({"translations": [...]}), the response is {"translations":[]}, wp_list_filter() returns
    [], reset() yields false, and (object) false has no english_name.

Strictly speaking, such plugins should answer translations_api for their own slug.
But reading $update->Language when it is only set conditionally is a bug on WP-CLI's side
regardless 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 of
Updating '' translation for My Private Plugin 0.1.0... plus a PHP warning.

Reproduction

Any WP install with WP_DEBUG enabled:

wp scaffold plugin my-private-plugin --skip-tests

wp-content/mu-plugins/private-language-packs.php:

<?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;
} );
$ wp language plugin update my-private-plugin
Warning: Undefined property: stdClass::$Language in .../src/WP_CLI/CommandWithTranslation.php
Updating '' translation for My Private Plugin 0.1.0...

Testing

Adds a Behat scenario that mocks the translations API to return {"translations":[]} while the
update check still offers a de_DE pack, then asserts the locale code is printed and STDERR
is empty. It fails on main and passes with this change.

Summary by CodeRabbit

  • Bug Fixes
    • Plugin translation updates now retain language information when the translation service omits a translated display name. Updates can also proceed when the service returns no available plugin translations but an installed translation remains eligible for updating. This improves the reliability of translation updates across plugin versions and helps ensure the correct language is reflected in update output.

Generated by Claude Code

`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.
@victorcamnerin
victorcamnerin requested a review from a team as a code owner August 31, 2026 07:54
@github-actions

Copy link
Copy Markdown
Contributor

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:

  • composer install: Install dependencies.
  • composer test: Run the full test suite.
  • composer phpcs: Check for code style violations.
  • composer phpcbf: Automatically fix code style violations.
  • composer phpunit: Run unit tests.
  • composer behat: Run behavior-driven tests.

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:123

You can find a list of all available Behat steps in our handbook.

@coderabbitai

coderabbitai Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The translation update path now falls back to the existing language value when english_name is not set. A scenario checks that the Akismet de_DE translation is reported for update when the translations API returns an empty list.

Changes: Translation update fallback

Layer / File(s) Summary
Language fallback and regression scenario
src/WP_CLI/CommandWithTranslation.php, features/language-plugin.feature
The update object assigns english_name or falls back to language. The scenario checks the update message and confirms that stderr is empty when the translations API returns an empty list.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: swissspidy, ernilambar

Merge Risk: Minimal · up to b8531

This change makes translation updates print the locale code when the WordPress.org translations API does not recognize a pack's slug. That removes a PHP warning and an empty locale in update logs. The change is small and covered by a new scenario, and no merge-blocking risk is evident.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Always set the Language property on translation updates" matches the main change. The diff in CommandWithTranslation.php replaces a conditional assignment of the Language property with a te…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Always set the Language property on translation updates" matches the main change. The diff in CommandWithTranslation.php replaces a conditional assignment of the Language property with a ternary that always assigns it, falling back to the raw locale code when english_name is missing. The PR objectives describe the same goal, which is to avoid a PHP warning and an empty locale in update logs for packs from slugs the translations API does not recognize.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 968a361d-9203-4375-81d8-b63f2860200b
Commits

Reviewing files that changed from the base of the PR and between f1c8c3e and b853127.

Files selected for processing: 1

  • features/language-plugin.feature
Files skipped from review as they are similar to previous changes: 1

  • features/language-plugin.feature

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@github-actions github-actions Bot added bug command:language Related to 'language' command command:language-plugin Related to 'language plugin' command scope:testing Related to testing labels Aug 31, 2026
@codecov

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@swissspidy

Copy link
Copy Markdown
Member

This is easy to hit on a multi-locale site with a mixed set of extensions

Is it? I would appreciate some clear reproduction steps. Sounds like the translation API is returning some fields but not all? 🤔

@victorcamnerin

Copy link
Copy Markdown
Contributor Author

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 update_plugins transient via site_transient_update_plugins / pre_set_site_transient_update_plugins. The TranslationsPress library does this (Yoast SEO Premium, Gravity Forms and its add-ons), and WC_Helper_Updater does the same for WooCommerce.com extensions. get_translation_updates() picks those entries up, but get_all_languages() then asks the wordpress.org translations API for that slug, and wordpress.org has never heard of it:

$ curl 'https://api.wordpress.org/translations/plugins/1.0/?slug=wordpress-seo-premium&version=27.5'
{"translations":[]}

So it's not a partial response, there's simply no entry for the locale. wp_list_filter() returns [] and Language never gets set. Gravity Forms also filters translations_api to fill that gap, so its packs print fine. Yoast SEO Premium filters it too, but returns the data keyed by slug instead of under translations, so the lookup still misses. Locale count doesn't matter, a single-locale site hits it just as easily, so the "multi-locale" angle in the description was a red herring.

Reproduction (no premium plugin needed, any WP install with WP_DEBUG on):

wp scaffold plugin my-private-plugin --skip-tests

wp-content/mu-plugins/private-language-packs.php:

<?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;
} );
$ wp language plugin update my-private-plugin
Warning: Undefined property: stdClass::$Language in .../language-command/src/WP_CLI/CommandWithTranslation.php on line 134
Updating '' translation for My Private Plugin 0.1.0...

Without WP_DEBUG the warning is swallowed and you're left with the empty quotes.

You could argue this is on the plugins to return the right shape from translations_api, so whether WP-CLI should guard against it too is your call. Happy to adjust the PR either way, or close it if you'd rather leave the current behaviour.

@swissspidy

Copy link
Copy Markdown
Member

Thanks for digging into this, that's a much clearer picture.

Those plugins are wrong: if you inject packs into update_plugins, you should also answer translations_api for your slug, and in the same shape wordpress.org uses ({"translations": [...]}). Gravity Forms and e.g. Traduttore Registry do exactly that and are unaffected. Yoast's slug-keyed response is a bug on their side and worth reporting to them.

That said, I'm fine with landing the fallback. Reading $update->Language when we only set it conditionally is our bug, regardless of what the API returned, and core's own upgrader skin only shows the locale code anyway. The packs install fine either way, so degrading to de_DE is the right behaviour.

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Language property.
  • 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.

@HoffmannTom

Copy link
Copy Markdown

I get this warning too when updating wordpress-seo-premium:

wp language plugin update wordpress-seo-premium
PHP Warning: Undefined property: stdClass::$Language in phar:///usr/local/bin/wp/vendor/wp-cli/language-command/src/WP_CLI/CommandWithTranslation.php on line 98
Warning: Undefined property: stdClass::$Language in phar:///usr/local/bin/wp/vendor/wp-cli/language-command/src/WP_CLI/CommandWithTranslation.php on line 98
Updating '' translation for Yoast SEO Premium 29.0-RC2...
Downloading translation from https://packages.translationspress.com/yoast/wordpress-seo-premium/wordpress-seo-premium-de_DE_formal.zip...
Unpacking the update...
Installing the latest version...
Removing the old version of the translation...
Translation updated successfully.
Success: Updated 1/1 translation.

Comment thread features/language-plugin.feature Resolved
@swissspidy swissspidy added this to the 3.0.3 milestone Nov 30, 2026
@swissspidy
swissspidy merged commit 4f47985 into wp-cli:main Dec 1, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug command:language Related to 'language' command command:language-plugin Related to 'language plugin' command scope:testing Related to testing state:unconfirmed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants