Send a locale query parameter on WordPress.com requests - #1590
Merged
Conversation
Collaborator
XCFramework BuildThis PR's XCFramework is available for testing. Add to your .package(url: "https://github.com/automattic/wordpress-rs", branch: "pr-build/1590")Built from 70762b4 |
3 tasks
WordPress.com localizes a response when the request carries a locale query parameter, but nothing in the generated request builders sent one. The parameter name depends on the API version, and the value is only known at runtime, so neither half fits in an endpoint's params type. `AsNamespace` now declares the parameter name, defaulting to `None` so namespaces that don't read one — including every WordPress.org namespace — are unaffected without opting out. The value comes from a `WpComLanguageProvider` on the client delegate, asked once per request. Changes: - Add `AsNamespace::locale_param_name`, overridden by `WpComNamespace`: `locale` for `/rest/v1.x`, `_locale` for `/wpcom/v2`, none for `/oauth2` - Add the `WpComLanguageProvider` trait and wire it through `WpApiClientDelegate.language_provider` - Append the pair in `WpDerivedRequest` codegen, ahead of the request's own params so an endpoint declaring `locale` still takes precedence - Give the generated endpoint type a `with_language_provider` constructor - Cover v1.1/v1.2/v1.3, `/wpcom/v2`, an absent language, and a WordPress.org endpoint handed a provider
Changes: - Add an optional `languageProvider` to both `WpComApiClient` constructors, defaulting to `null`, and pass it into the `WpApiClientDelegate` - Suppress `LongParameterList` on the interceptor convenience constructor, matching `WpApiClient` and `JetpackApiClient`
oguzkocer
force-pushed
the
add/wpcom-locale-parameter
branch
from
August 26, 2026 00:38
af9a28e to
70762b4
Compare
oguzkocer
marked this pull request as ready for review
August 26, 2026 00:41
1 task
crazytonyli
approved these changes
Aug 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
WordPress.com localizes a response when the request carries a locale query parameter. Nothing in the generated request builders sent one, so a handful of endpoints picked it up only because they happened to declare
localein their own params type, and the rest sent nothing.If you'd like to see this in action, please see wordpress-mobile/WordPress-Android#23265 to see how it's being integrated. Feel free to follow the testing instructions in that PR to validate that the locale is being sent as expected.
Changes
AsNamespacegainedlocale_param_name, defaulting toNone.WpComNamespaceoverrides it:localefor/rest/v1.1,/rest/v1.2and/rest/v1.3,_localefor/wpcom/v2, none for/oauth2. Every other namespace inherits the default, so WordPress.org and Jetpack are unaffected without opting out.WpComLanguageProvidertrait (#[uniffi::export(with_foreign)]), carried onWpApiClientDelegate.language_providerand threaded through the generated request executor and builder. It's asked once per request, so a client returning a live value needs no invalidation when the language changes.WpDerivedRequestcodegen appends the pair after resolving the URL and before the request's own params, so an endpoint declaringlocalestill takes precedence.with_language_providerconstructor;newcontinues to build URLs without a locale.Tests cover v1.1/v1.2/v1.3 and
/wpcom/v2, a provider returning no language, precedence over an endpoint's own parameter, and a WordPress.org endpoint handed a provider sending no locale.Changelog
CHANGELOG.mdunder## [Unreleased], using the Keep a Changelog categories (Added,Changed,Deprecated,Removed,Fixed,Security). Prefix breaking changes with**BREAKING:**.