Skip to content

Commit

Permalink
Pass current language into Jitsi (#24609
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
Fox32 authored Feb 22, 2023
1 parent 9f673fd commit 5de1b0a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/vector/jitsi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(" ", "_")}`);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5de1b0a

Please sign in to comment.