Skip to content

Send the device language on WordPress.com requests - #23265

Draft
oguzkocer wants to merge 2 commits into
trunkfrom
global-locale-for-wordpress-rs
Draft

Send the device language on WordPress.com requests#23265
oguzkocer wants to merge 2 commits into
trunkfrom
global-locale-for-wordpress-rs

Conversation

@oguzkocer

Copy link
Copy Markdown
Contributor

Description

Not for merge yet. This branch exists to exercise wordpress-rs#1590 in a real app and confirm the locale query parameter reaches the wire. It pins wordpress-rs to a CI build (1590-af9a28ec…) rather than a release, so it can't ship as-is. Once #1590 lands and a version is published, this can be repointed and converted into a proper PR.

Changes

  • DeviceWpComLanguageProvider implements WpComLanguageProvider, mapping the device locale to a WpComLanguage with the existing fromLocale extension. It's asked on every request rather than captured once, so changing the device language mid-session takes effect without rebuilding the client. An unmappable locale returns null, which sends no parameter and leaves the choice to the server.
  • WpComApiClientProvider passes the provider to WpComApiClient. Every wordpress-rs WordPress.com call in the app goes through this provider, so this one change covers all of them.
  • TrackNetworkRequestsInterceptor is added to that client's OkHttpClient. This client was built with no interceptors, so its requests never reached Chucker — without this there's no way to observe the parameter. The interceptor is gated on the existing network-tracking preference and passes through when it's off. This change doesn't belong to this PR and should be removed before it's marked ready for review. See Decide whether wordpress-rs clients should receive the app's OkHttp interceptors #23241 which should be tackled on its own.
  • wordpress-rs pinned to the 1590-af9a28ec CI build.

Testing instructions

The locale parameter is sent on every WordPress.com request, so any screen backed by the wordpress-rs client will show it.

Locale reaches the wire:

  1. Build and install the wordpress debug variant, and log in to a WordPress.com account.
  2. Go to Me → Experimental Features and enable network debugging.
  3. Go to Me → Help & Support and enable network request tracking.
  4. Open a screen that fetches from WordPress.com through wordpress-rs — the domains dashboard for a site (/rest/v1.2/all-domains) or a domain search (/rest/v1.1/domains/suggestions) both work.
  5. Return to Me → Help & Support and open the network request viewer.
  • A request to public-api.wordpress.com carries locale=en (or whatever your device language is) in its query string.

The value follows the device language:

  1. Change the device language to Spanish in Android settings.
  2. Repeat steps 3–4 above.
  • The same request now carries locale=es.

WordPress.org requests are unaffected:

  1. Add or open a self-hosted site and load its posts or media.
  • Requests to that site's REST API carry no locale or _locale parameter.

Changes:
- Add `DeviceWpComLanguageProvider`, mapping the device locale to a
  `WpComLanguage` via `fromLocale` on every request
- Pass it to `WpComApiClient` in `WpComApiClientProvider`
- Add `TrackNetworkRequestsInterceptor` to that client's `OkHttpClient`, so
  its requests appear in Chucker when network tracking is enabled
- Point `wordpress-rs` at the `1590-af9a28ec` CI build
`AppCompatDelegate.getApplicationLocales()` holds the language the user
picked inside the app. `Locale.getDefault()` only reflects it once the
framework has propagated the change to the process, so a request made
before that lands, or from a background service, reads the OS language.

Changes:
- Read the locale from `PerAppLocaleManager.getCurrentLocale()`, which
  falls back to `Locale.getDefault()` when no app language is set
- Rename `DeviceWpComLanguageProvider` to `AppWpComLanguageProvider`
@oguzkocer oguzkocer added Localization Do Not Merge PR shouldn't be merged, failing the build labels Aug 26, 2026
@dangermattic

Copy link
Copy Markdown
Collaborator
2 Errors
🚫 Please add tests for class AppWpComLanguageProvider (or add unit-tests-exemption label to ignore this).
🚫 This PR includes a PR version of wordpress-rs (1590-af9a28ec86d13203855db032d85e608b00b645c0). Please merge the corresponding wordpress-rs PR and update to a trunk version before merging.
1 Message
📖 This PR is still a Draft: some checks will be skipped.

Generated by 🚫 Danger

@wpmobilebot

Copy link
Copy Markdown
Contributor

Project dependencies changes

list
! Upgraded Dependencies
rs.wordpress.api:android:1590-af9a28ec86d13203855db032d85e608b00b645c0, (changed from 0.7.0)
rs.wordpress.api:kotlin:1590-af9a28ec86d13203855db032d85e608b00b645c0, (changed from 0.7.0)
tree
 +--- project :libs:fluxc
-|    \--- rs.wordpress.api:android:0.7.0
-|         +--- com.squareup.okhttp3:okhttp:5.4.0 (*)
-|         +--- com.squareup.okhttp3:okhttp-tls:5.4.0
-|         |    +--- org.jetbrains.kotlin:kotlin-stdlib:2.1.21 -> 2.4.10 (*)
-|         |    +--- com.squareup.okio:okio:3.17.0 (*)
-|         |    \--- com.squareup.okhttp3:okhttp:5.4.0 (*)
-|         +--- net.java.dev.jna:jna:5.19.1
-|         +--- rs.wordpress.api:kotlin:0.7.0
-|         |    +--- com.squareup.okhttp3:okhttp:5.4.0 (*)
-|         |    +--- com.squareup.okhttp3:okhttp-tls:5.4.0 (*)
-|         |    +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2 -> 1.11.0 (*)
-|         |    \--- org.jetbrains.kotlin:kotlin-stdlib:2.3.21 -> 2.4.10 (*)
-|         \--- org.jetbrains.kotlin:kotlin-stdlib:2.3.21 -> 2.4.10 (*)
+|    \--- rs.wordpress.api:android:1590-af9a28ec86d13203855db032d85e608b00b645c0
+|         +--- com.squareup.okhttp3:okhttp:5.4.0 (*)
+|         +--- com.squareup.okhttp3:okhttp-tls:5.4.0
+|         |    +--- org.jetbrains.kotlin:kotlin-stdlib:2.1.21 -> 2.4.10 (*)
+|         |    +--- com.squareup.okio:okio:3.17.0 (*)
+|         |    \--- com.squareup.okhttp3:okhttp:5.4.0 (*)
+|         +--- net.java.dev.jna:jna:5.19.1
+|         +--- rs.wordpress.api:kotlin:1590-af9a28ec86d13203855db032d85e608b00b645c0
+|         |    +--- com.squareup.okhttp3:okhttp:5.4.0 (*)
+|         |    +--- com.squareup.okhttp3:okhttp-tls:5.4.0 (*)
+|         |    +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2 -> 1.11.0 (*)
+|         |    \--- org.jetbrains.kotlin:kotlin-stdlib:2.3.21 -> 2.4.10 (*)
+|         \--- org.jetbrains.kotlin:kotlin-stdlib:2.3.21 -> 2.4.10 (*)
-\--- rs.wordpress.api:android:0.7.0 (*)
+\--- rs.wordpress.api:android:1590-af9a28ec86d13203855db032d85e608b00b645c0 (*)

@wpmobilebot

Copy link
Copy Markdown
Contributor

App Icon📲 You can test the changes from this Pull Request in Jetpack Android by scanning the QR code below to install the corresponding build.

App NameJetpack Android
Build TypeDebug
Versionpr23265-6fb9ae5
Build Number1498
Application IDcom.jetpack.android.prealpha
Commit6fb9ae5
Installation URL530er9vhh1v80
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

Copy link
Copy Markdown
Contributor

App Icon📲 You can test the changes from this Pull Request in WordPress Android by scanning the QR code below to install the corresponding build.

App NameWordPress Android
Build TypeDebug
Versionpr23265-6fb9ae5
Build Number1498
Application IDorg.wordpress.android.prealpha
Commit6fb9ae5
Installation URL61d255tep8bko
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Do Not Merge PR shouldn't be merged, failing the build Localization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants