Skip to content

Commit 5de1b0a

Browse files
authored
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 <[email protected]> * Map between Element and Jitsi language codes --------- Signed-off-by: Oliver Sand <[email protected]>
1 parent 9f673fd commit 5de1b0a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/vector/jitsi/index.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ let roomName: string;
5757
let startAudioOnly: boolean;
5858
let isVideoChannel: boolean;
5959
let supportsScreensharing: boolean;
60+
let language: string;
6061

6162
let widgetApi: WidgetApi;
6263
let meetApi: any; // JitsiMeetExternalAPI
@@ -86,6 +87,7 @@ const setupCompleted = (async (): Promise<string | void> => {
8687
const parentUrl = qsParam("parentUrl", true);
8788
const widgetId = qsParam("widgetId", true);
8889
const theme = qsParam("theme", true);
90+
language = qsParam("language", true) ?? "en";
8991

9092
if (theme) {
9193
document.body.classList.add(`theme-${theme.replace(" ", "_")}`);
@@ -313,6 +315,31 @@ function closeConference(): void {
313315
}
314316
}
315317

318+
// Converts from IETF language tags used by Element (en-US) to the format used
319+
// by Jitsi (enUS)
320+
function normalizeLanguage(language: string): string {
321+
const [lang, variant] = language.replace("_", "-").split("-");
322+
323+
if (!variant || lang === variant) {
324+
return lang;
325+
}
326+
327+
return lang + variant.toUpperCase();
328+
}
329+
330+
function mapLanguage(language: string): string {
331+
// Element and Jitsi don't agree how to interpret en, so we go with Elements
332+
// interpretation to stay consistent
333+
switch (language) {
334+
case "en":
335+
return "enGB";
336+
case "enUS":
337+
return "en";
338+
default:
339+
return language;
340+
}
341+
}
342+
316343
// event handler bound in HTML
317344
// An audio input of undefined instructs Jitsi to start unmuted with whatever
318345
// 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):
371398
apiLogLevels: ["warn", "error"],
372399
} as any,
373400
jwt: jwt,
401+
lang: mapLanguage(normalizeLanguage(language)),
374402
};
375403

376404
// Video channel widgets need some more tailored config options

0 commit comments

Comments
 (0)