Skip to content

fix(surveys): re-translate displayed surveys when user language changes#4195

Open
nandinitiw wants to merge 3 commits into
PostHog:mainfrom
nandinitiw:fix/survey-retranslate-on-language-change
Open

fix(surveys): re-translate displayed surveys when user language changes#4195
nandinitiw wants to merge 3 commits into
PostHog:mainfrom
nandinitiw:fix/survey-retranslate-on-language-change

Conversation

@nandinitiw

Copy link
Copy Markdown

What

When a survey popover is on screen, it was never re-translated if the user's language changed mid-session. This happened in two scenarios:

  1. posthog.identify() / setPersonPropertiesForFlags() sets a new language person property
  2. The browser fires a languagechange event (OS/browser language switch)

The TODO comment in survey-translations.ts already called this out as a known gap.

How

In SurveyManager:

  • Register a window.languagechange listener in the constructor
  • Subscribe to posthog.onFeatureFlags() (which fires after identify() reloads flags)
  • Both call _onLanguageChange(), which:
    • No-ops if no survey is in focus
    • Re-detects the resolved language
    • No-ops if the language is unchanged (idempotent, safe to call on every flag reload)
    • Otherwise updates _currentLanguage and re-renders the popover via renderPopover()
  • Listeners are cleaned up on destroy()
  • _currentLanguage is cleared when a survey is dismissed

The iOS reference implementation in posthog-ios #686 follows the same pattern.

Tests

5 new unit tests covering:

  • Re-renders when language differs
  • Does not re-render when language is unchanged
  • No-ops when no survey is in focus
  • Clears _currentLanguage on dismiss
  • Removes languagechange listener on destroy()

Closes #4174

nandinitiw and others added 3 commits July 6, 2026 13:40
…cking

Include service_tier in the getModelParams extraction so that flex/priority
tier requests are reflected in $ai_model_parameters and the backend can apply
the correct pricing multiplier when calculating $ai_total_cost_usd.

Closes #2323
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
When identify() sets a new 'language' person property, or the browser fires a
languagechange event, any popover survey currently on screen stays in the old
language until dismissed. This wires up both triggers to re-detect the resolved
language and re-render in place when it differs from what was originally shown.

Closes PostHog#4174
@nandinitiw
nandinitiw requested a review from a team as a code owner July 18, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Re-translate displayed survey on language change

1 participant