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 <oliver.sand@nordeck.net>

* Map between Element and Jitsi language codes

---------

Signed-off-by: Oliver Sand <oliver.sand@nordeck.net>
pull/24562/head
Oliver Sand 2023-02-22 19:21:05 +01:00 committed by GitHub
parent 9f673fdb04
commit 5de1b0a012
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 0 deletions

View File

@ -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<string | void> => {
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