Send the device language on WordPress.com requests - #23265
Draft
oguzkocer wants to merge 2 commits into
Draft
Conversation
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`
Collaborator
Generated by 🚫 Danger |
Contributor
Project dependencies changeslist! 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 (*) |
Contributor
|
|
Contributor
|
|
1 task
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
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-rsto 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
DeviceWpComLanguageProviderimplementsWpComLanguageProvider, mapping the device locale to aWpComLanguagewith the existingfromLocaleextension. 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 returnsnull, which sends no parameter and leaves the choice to the server.WpComApiClientProviderpasses the provider toWpComApiClient. Every wordpress-rs WordPress.com call in the app goes through this provider, so this one change covers all of them.TrackNetworkRequestsInterceptoris added to that client'sOkHttpClient. 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-rspinned to the1590-af9a28ecCI 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:
wordpressdebug variant, and log in to a WordPress.com account./rest/v1.2/all-domains) or a domain search (/rest/v1.1/domains/suggestions) both work.public-api.wordpress.comcarrieslocale=en(or whatever your device language is) in its query string.The value follows the device language:
locale=es.WordPress.org requests are unaffected:
localeor_localeparameter.