I have an android app and using remote config.
I have this usecase and I want to send the app language change in that request. My app supports both English and Vietnam and the user can select their preferred language. I am just testing with changing to vietnam language.
However, in the request its always using my system device language. And as that is always set to English it always sends en-US.
In my firebase remote config console I have a field that has an Language condition for English and Vietnam. So based on that condition I can do something in the app.
class FetchRemoteConfigUseCase @Inject constructor(
private val remoteConfigProvider: RemoteConfigProvider,
private val firebaseRemoteConfigSettings: FirebaseRemoteConfigSettings,
private val schedulersFacade: SchedulersFacade
) {
fun execute(): Completable {
return Completable.create { completable ->
remoteConfigProvider
.remoteConfig
.setConfigSettingsAsync(firebaseRemoteConfigSettings)
.continueWithTask {
remoteConfigProvider.remoteConfig.setDefaultsAsync(mapOf("languageCode" to "vi-VN"))
remoteConfigProvider.remoteConfig.fetchAndActivate()
}
.addOnCompleteListener {
completable.onComplete()
}
}.observeOn(schedulersFacade.io)
}
}
When I check the request in charles proxy I can see only en-US.
{
"appInstanceId": "app instance Id"",
"appVersion": "4.0.0",
"countryCode": "US",
"analyticsUserProperties": {
"current_cluster": "cluster"
},
"appId": "app Id"",
"platformVersion": "30",
"timeZone": "Asia/Vietnam",
"sdkVersion": "21.0.2",
"packageName": "package name",
"languageCode": "en-US",
"appBuild": "140"
}
I am wondering how can I send the languageCode in the above.
Just a side question how does firebase know where to extract these properties and send them in the request?
2
Answers
To send the languageCode based on user selection in your app to Firebase Remote Config:
like SharedPreferences.
Config request before fetching configurations.
E.G
Firebase automatically gathers standard details like app version and device info via the integrated SDK. When you manually set additional properties, like languageCode, Firebase includes these in the server requests, helping determine the appropriate configuration to return based on your Remote Config settings.
You can also check their doc
Another approach
You could prefix or suffix your Remote Config parameter keys with the language code:
In your app, you would construct the key dynamically based on the user’s selected language and fetch the corresponding value:
The remote config allows key-value data to be sent to the frontend, but it needs to be actually used by the networking library.
The way the networking library picks up the language is similar to web browsers, by using
Accept-Language Http Headers
. Firebase Hosting also says it uses this method. Note that the"languageCode"
of the device will automatically be sent to the backend, no additional work is needed to change it based on the devices settings. You would need to modify it if the user uses there phone in one language and wants to use the app in a different language.Instruction to "Configure internationalization (i18n) rewrites" for Firebase Hosting are here. Here is an example in Flutter for localization with Firebase remote config.
In other Android contexts, this post explains how Accept-Language Http Headers may be used with OkHttp network requests. And this one for DefaultHttpClient
An example of how to change it in general on Android: