You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have an iOS and Android app that integrates the respective PostHog SDK.
Our app is available in English and German. In our Mobile Analytics dashboard on PostHog (created using the PostHog template) I see a breakdown of the languages. This breakdown contains many more languages (including country specifier such as ru-RU) than just the two the app runs in.
Digging deeper, I realized that the additional languages only come from Android. On iOS it indeed only reports just the language the app runs in, as can be seen in its source:
On Android it should collect just the language that is also used for resource lookup. If my phone is set to de-CH and the app only supports English, I want to see en as the value for the $locale property.
Thanks for reporting this. You’re right that Android and iOS behave differently here in two ways:
Android reads the default locale, which can differ from the language your app displays. iOS uses Locale.current, which accounts for the app’s supported languages and per-app language settings.
Android includes the country (de-CH), while iOS only sends the language (de). Our property definition describes $locale as the device locale, with examples like en-US and de-DE, so iOS dropping the country is also an inconsistency. That is separate from which language the app actually displays.
We tested an English-only app with a resource context configured for de-CH on Android. Even Android’s app-context locale reports de-CH while the app displays English fallback strings, so it doesn’t look like switching to that API alone will fix this.
For now, you can override $locale with the language your app uses through beforeSend. We tested this with Android SDK 3.71.2 and confirmed that the outgoing events contained the supplied en or de value instead of de-CH. Add it before setting up PostHog:
Thanks, that's what I'm doing. I rely on a trick to get the locale: I define a string resource language that gets the respective language code as the value in each values-$LANG/strings.xml file.
I think this snippet should work as well:
fun Context.currentLanguageCode(): String {
val locale:Locale=if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.N) {
resources.configuration.locales[0]
} else {
@Suppress("DEPRECATION")
resources.configuration.locale
}
return locale.language // e.g. "en", "de", "fr"
}
The proposed approach matches the user’s language preferences against the app’s declared supported locales. It uses Android’s LocaleConfig API on Android 13+, and reads the same packaged XML directly on Android 6–12. If nothing matches, it uses an explicitly declared default; if that information is unavailable, it keeps today’s behavior.
This is just a proposal. It selects the best supported app language, but won’t necessarily match every displayed string because individual resources can fall back differently.
Does your app declare a localeConfig, manually or through AGP? That would help us check whether this approach covers your setup.
$locale: the primary device locale as a full tag (de-CH) on every platform.
Why: the taxonomy defines $locale as "the locale of the device" (en-US, de-DE), and every SDK can read it exactly.
Android: read the system locale instead of Locale.getDefault(), which can be a secondary language, a per-app choice or a value the app set itself. That's LocaleManager.systemLocales[0] on 13+, Resources.getSystem().configuration.locales[0] on 7–12, and configuration.locale on 6. Use toLanguageTag(), since the hand-built string drops the script (zh-Hans) and can produce en-.
Flutter gets it from the native SDKs. React Native already sends it through expo-localization / react-native-localize.
$app_language: a new property for the language the app actually shows.
For a bilingual user (phone set to es, en, English-only app), the device locale says es while they read English happily. It's also what this issue asks for.
Detection:
SDK
How
Accuracy
iOS
Bundle.main.preferredLocalizations.first
High, including the per-app language choice
Android 13+, per-app language picked
LocaleManager.getApplicationLocales()
High
Android 13+, localeConfig declared
LocaleConfig + LocaleList.getFirstMatch()
Close guess; per-string fallback can differ
Android 6–12 / no localeConfig
Nothing reliable
The app sets it
Flutter
Localizations.maybeLocaleOf(navigator.context) in PosthogObserver
High, for apps using the observer (untested)
React Native
No standard i18n library
The app sets it
Every SDK needs a way for the app to set it. Flutter and React Native apps usually translate in Dart/JS, so the native value would often be wrong there.
What we keep: iOS's current value moves to $app_language, and Android's becomes an exact device locale. Nothing is lost.
Both platforms' $locale would mean the same thing. The reporter declares localeConfig, so $language is filled automatically on iOS and Android 13+, and they set it on Android 6–12. Their chart (and maybe the Mobile Analytics template) would break down by $app_language.
Breaking change: iOS $locale values change from de to de-CH, and iOS charts by $locale change meaning, so I'd ship it in v4 with a migration note. We can put both iOS and Android changes in the major release branches.
Activity
dustinbyrne commentedon Sep 29, 2026
Thanks for reporting this. You’re right that Android and iOS behave differently here in two ways:
Locale.current, which accounts for the app’s supported languages and per-app language settings.de-CH), while iOS only sends the language (de). Our property definition describes$localeas the device locale, with examples likeen-USandde-DE, so iOS dropping the country is also an inconsistency. That is separate from which language the app actually displays.We tested an English-only app with a resource context configured for
de-CHon Android. Even Android’s app-context locale reportsde-CHwhile the app displays English fallback strings, so it doesn’t look like switching to that API alone will fix this.For now, you can override
$localewith the language your app uses throughbeforeSend. We tested this with Android SDK 3.71.2 and confirmed that the outgoing events contained the suppliedenordevalue instead ofde-CH. Add it before setting up PostHog:config.addBeforeSend { event -> event.properties?.set("\$locale", currentAppLanguage()) event }Replace
currentAppLanguage()with your app’s language getter, returning"en"or"de"for the breakdown you described.fphilipe commentedon Sep 30, 2026
Thanks, that's what I'm doing. I rely on a trick to get the locale: I define a string resource
languagethat gets the respective language code as the value in eachvalues-$LANG/strings.xmlfile.I think this snippet should work as well:
dustinbyrne commentedon Oct 2, 2026
I’ve opened a draft PR to explore this: #832.
The proposed approach matches the user’s language preferences against the app’s declared supported locales. It uses Android’s
LocaleConfigAPI on Android 13+, and reads the same packaged XML directly on Android 6–12. If nothing matches, it uses an explicitly declared default; if that information is unavailable, it keeps today’s behavior.This is just a proposal. It selects the best supported app language, but won’t necessarily match every displayed string because individual resources can fall back differently.
Does your app declare a
localeConfig, manually or through AGP? That would help us check whether this approach covers your setup.fphilipe commentedon Oct 2, 2026
We declare it manually:
android:localeConfig="@xml/locales_config"in the manifest. We don't use AGPgenerateLocaleConfig.marandaneto commentedon Oct 5, 2026
left a few comments in #832
turnipdabeets commentedon Oct 22, 2026
@dustinbyrne @marandaneto I wonder if we should go with two properties:
$locale: the primary device locale as a full tag (de-CH) on every platform.$app_language: a new property for the language the app actually shows.What we keep: iOS's current value moves to $app_language, and Android's becomes an exact device locale. Nothing is lost.
Both platforms' $locale would mean the same thing. The reporter declares localeConfig, so $language is filled automatically on iOS and Android 13+, and they set it on Android 6–12. Their chart (and maybe the Mobile Analytics template) would break down by $app_language.
Breaking change: iOS $locale values change from de to de-CH, and iOS charts by $locale change meaning, so I'd ship it in v4 with a migration note. We can put both iOS and Android changes in the major release branches.
posthog commentedon Oct 23, 2026
PostHog self-driving picked up this issue and researched it. Somebody may already be working on it, so ask before you start a fix.
Report (team access only): https://us.posthog.com/project/2/inbox/reports/01a169ef-9ba3-7c2a-a426-2e2a9414f51a?link_source=github_comment