posthog-js
Version:
Posthog-js allows you to automatically capture usage and send events to PostHog.
28 lines (27 loc) • 1.4 kB
TypeScript
import { PostHog } from '../posthog-core';
import { Survey } from '../posthog-surveys-types';
/**
* Detects the user's language using priority order:
* 1. config.override_display_language (explicit override)
* 2. person properties 'language' (allows programmatic control via posthog.identify())
* 3. navigator.language (browser language)
*
* TODO: Consider adding dynamic language change detection in the future:
* - Listen to 'languagechange' event on window (https://developer.mozilla.org/en-US/docs/Web/API/Window/languagechange_event)
* - Listen to config changes (once we add config change events to PostHog core)
* - Re-render survey when language changes mid-session
*
* @param instance - PostHog instance to retrieve config and person properties
* @returns The detected language code (e.g., 'fr', 'es', 'en-US') or null if not found
*/
export declare function detectUserLanguage(instance: PostHog): string | null;
/**
* Applies translations to a survey based on the user's language from person properties
* @param survey - The original survey object
* @param instance - PostHog instance to retrieve person properties
* @returns An object containing the translated survey and the language used (or null if no translation applied)
*/
export declare function applySurveyTranslationForUser(survey: Survey, instance: PostHog): {
survey: Survey;
language: string | null;
};