From 5de1b0a012e9d7811591a846d89daf1579fe85bd Mon Sep 17 00:00:00 2001 From: Oliver Sand Date: Wed, 22 Feb 2023 19:21:05 +0100 Subject: [PATCH] Pass current language into Jitsi (#24609 * Pass current language into Jitsi Jitsi itself now uses the current language of the user. However, this does not yet apply to the welcome page of the Jitsi widget that says "Join conference", which is only hard-coded to english for now. Signed-off-by: Oliver Sand * Map between Element and Jitsi language codes --------- Signed-off-by: Oliver Sand --- src/vector/jitsi/index.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/vector/jitsi/index.ts b/src/vector/jitsi/index.ts index e06073f1d2..4281b908f3 100644 --- a/src/vector/jitsi/index.ts +++ b/src/vector/jitsi/index.ts @@ -57,6 +57,7 @@ let roomName: string; let startAudioOnly: boolean; let isVideoChannel: boolean; let supportsScreensharing: boolean; +let language: string; let widgetApi: WidgetApi; let meetApi: any; // JitsiMeetExternalAPI @@ -86,6 +87,7 @@ const setupCompleted = (async (): Promise => { const parentUrl = qsParam("parentUrl", true); const widgetId = qsParam("widgetId", true); const theme = qsParam("theme", true); + language = qsParam("language", true) ?? "en"; if (theme) { document.body.classList.add(`theme-${theme.replace(" ", "_")}`); @@ -313,6 +315,31 @@ function closeConference(): void { } } +// Converts from IETF language tags used by Element (en-US) to the format used +// by Jitsi (enUS) +function normalizeLanguage(language: string): string { + const [lang, variant] = language.replace("_", "-").split("-"); + + if (!variant || lang === variant) { + return lang; + } + + return lang + variant.toUpperCase(); +} + +function mapLanguage(language: string): string { + // Element and Jitsi don't agree how to interpret en, so we go with Elements + // interpretation to stay consistent + switch (language) { + case "en": + return "enGB"; + case "enUS": + return "en"; + default: + return language; + } +} + // event handler bound in HTML // An audio input of undefined instructs Jitsi to start unmuted with whatever // audio input it can find, while an input of null instructs it to start muted, @@ -371,6 +398,7 @@ function joinConference(audioInput?: string | null, videoInput?: string | null): apiLogLevels: ["warn", "error"], } as any, jwt: jwt, + lang: mapLanguage(normalizeLanguage(language)), }; // Video channel widgets need some more tailored config options