Skip to content

Send a locale query parameter on WordPress.com requests - #1590

Merged
oguzkocer merged 2 commits into
trunkfrom
add/wpcom-locale-parameter
Aug 26, 2026
Merged

Send a locale query parameter on WordPress.com requests#1590
oguzkocer merged 2 commits into
trunkfrom
add/wpcom-locale-parameter

Conversation

@oguzkocer

@oguzkocer oguzkocer commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

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 locale in 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

  • AsNamespace gained locale_param_name, defaulting to None. WpComNamespace overrides it: locale for /rest/v1.1, /rest/v1.2 and /rest/v1.3, _locale for /wpcom/v2, none for /oauth2. Every other namespace inherits the default, so WordPress.org and Jetpack are unaffected without opting out.
  • New WpComLanguageProvider trait (#[uniffi::export(with_foreign)]), carried on WpApiClientDelegate.language_provider and 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.
  • WpDerivedRequest codegen appends the pair after resolving the URL and before the request's own params, so an endpoint declaring locale still takes precedence.
  • The generated endpoint type gained a with_language_provider constructor; new continues 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

  • I've added an entry to CHANGELOG.md under ## [Unreleased], using the Keep a Changelog categories (Added, Changed, Deprecated, Removed, Fixed, Security). Prefix breaking changes with **BREAKING:**.

@wpmobilebot

wpmobilebot commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

XCFramework Build

This PR's XCFramework is available for testing. Add to your Package.swift:

.package(url: "https://github.com/automattic/wordpress-rs", branch: "pr-build/1590")

Built from 70762b4

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
oguzkocer force-pushed the add/wpcom-locale-parameter branch from af9a28e to 70762b4 Compare August 26, 2026 00:38
@oguzkocer
oguzkocer marked this pull request as ready for review August 26, 2026 00:41
@oguzkocer
oguzkocer merged commit 6332d21 into trunk Aug 26, 2026
36 checks passed
@oguzkocer
oguzkocer deleted the add/wpcom-locale-parameter branch August 26, 2026 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants