Track language selection with Plausible Language Changed event.
Centralize UI language switches in cycleAppLanguage and document the event in plausible-events.md. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import type { i18n as I18nInstance } from 'i18next'
|
||||
import { PlausibleEvents, trackPlausibleEvent } from '../services/analytics.js'
|
||||
|
||||
/** Supported UI languages (ISO 639-1, language-only). */
|
||||
export const SUPPORTED_LANGUAGES = ['de', 'en', 'da', 'sv', 'nb'] as const
|
||||
|
||||
@@ -20,3 +23,17 @@ export function getNextLanguage(current?: string): AppLanguage {
|
||||
export function isGermanLocale(language?: string): boolean {
|
||||
return normalizeAppLanguage(language) === 'de'
|
||||
}
|
||||
|
||||
/** Switch UI language and track explicit user choice (not auto-detection). */
|
||||
export function changeAppLanguage(i18n: I18nInstance, language: AppLanguage): void {
|
||||
const from = normalizeAppLanguage(i18n.language)
|
||||
const to = normalizeAppLanguage(language)
|
||||
if (from === to) return
|
||||
|
||||
void i18n.changeLanguage(to)
|
||||
trackPlausibleEvent(PlausibleEvents.LANGUAGE_CHANGED, { from, to })
|
||||
}
|
||||
|
||||
export function cycleAppLanguage(i18n: I18nInstance): void {
|
||||
changeAppLanguage(i18n, getNextLanguage(i18n.language))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user