Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
feat(audio-translation): make the offered target languages configurable (#18142)
Jonathan Lennoxa1744cc18863
diff --git a/config.js b/config.jsindex 16a7881285..7ba09fd87b 100644--- a/config.js+++ b/config.js@@ -258,6 +258,29 @@ var config = {// // Defaults to 0.15. Ignored on iOS, where the original is muted instead because the// // element volume cannot be lowered there.// duckedVolume: 0.15,+ //+ // // Target languages offered in the audio-translation picker, as the codes the+ // // deployment's speech-to-speech translation provider accepts (they are sent to the+ // // bridge verbatim, and the translated track is named <source>.<code>). Defaults to the+ // // 13 languages every provider supports: en, es, pt, fr, de, it, ru, zh, ja, ko, hi, id,+ // // vi. Extend this only if the translation service accepts more: a language the+ // // provider rejects is dropped server-side and the picker entry produces no audio.+ // // A code must be 1-20 ASCII letters: prosody's audio-translation component refuses any+ // // other language with bad-request, and one bad code in a meeting-wide request fails+ // // translation for every speaker, so region or script tags ('pt-BR') and codes like+ // // 'pt_BR' are dropped from the list with a warning. A list that is+ // // set but leaves nothing usable offers no language at all, with a warning, rather+ // // than the defaults. Codes outside the default list are labelled with the language's+ // // own name where the platform has Intl.DisplayNames (browsers; the mobile apps do not),+ // // else with the English name from lang/translation-languages.json. Same keys as+ // // transcription.translationLanguages.+ // translationLanguages: [ 'en', 'es', 'fr', 'nl' ],+ //+ // // Languages from the offered list to pin to the top of the picker, in this order. Unlike+ // // transcription.translationLanguagesHead this only reorders: a head entry that is not+ // // in the offered list is ignored, so it cannot add a language the provider may reject,+ // // and it takes the list's spelling.+ // translationLanguagesHead: [ 'en' ],// },// Noise suppression configuration. By default rnnoise is used. Optionally Krispdiff --git a/lang/main.json b/lang/main.jsonindex 93e73b805a..c8f8b6d648 100644--- a/lang/main.json+++ b/lang/main.json@@ -41,6 +41,7 @@},"audioTranslation": {"disabledForRoom": "Audio translation has been turned off for this meeting.",+ "errorBadRequest": "The meeting server rejected the translation request. If this keeps happening, ask your administrator to check the configured translation languages.","errorForbidden": "You don't have permission to use audio translation.","errorGeneric": "Couldn't enable audio translation. Please try again.","errorLimitReached": "Couldn't translate everyone at once. Turn on translation for individual participants instead.",diff --git a/package-lock.json b/package-lock.jsonindex 25356d245d..dfcc0e42a8 100644--- a/package-lock.json+++ b/package-lock.json@@ -70,7 +70,7 @@"js-md5": "0.6.1","js-sha512": "0.8.0","jwt-decode": "2.2.0",- "lib-jitsi-meet": "https://github.com/jitsi/lib-jitsi-meet/releases/download/v2233.0.0+7634be62/lib-jitsi-meet.tgz",+ "lib-jitsi-meet": "https://github.com/jitsi/lib-jitsi-meet/releases/download/v2236.0.0+51058e35/lib-jitsi-meet.tgz","lodash-es": "4.18.1","null-loader": "4.0.1","optional-require": "1.0.3",@@ -14407,8 +14407,9 @@},"node_modules/lib-jitsi-meet": {"version": "0.0.0",- "resolved": "https://github.com/jitsi/lib-jitsi-meet/releases/download/v2233.0.0+7634be62/lib-jitsi-meet.tgz",- "integrity": "sha512-DNk4Ylo4T69N9d9jRv8u94T88nzZgvHVVFd1W254EYrjYEqzVUcmqVQAgdzhqcTH3RLO3OQ8NvgnVYfBLKNuvQ==",+ "resolved": "https://github.com/jitsi/lib-jitsi-meet/releases/download/v2236.0.0+51058e35/lib-jitsi-meet.tgz",+ "integrity": "sha512-AIbDciGJrCKNIK1YVGZ4o41dV/lVdgXM6RT6CdetMWr0mmAkxH3DRCdY0drtfx3ORIjFqhyPdF/7h6fy1cAowA==",+ "license": "Apache-2.0","dependencies": {"@jitsi/js-utils": "12.0.7","@jitsi/logger": "2.1.1",@@ -31727,8 +31728,8 @@}},"lib-jitsi-meet": {- "version": "https://github.com/jitsi/lib-jitsi-meet/releases/download/v2233.0.0+7634be62/lib-jitsi-meet.tgz",- "integrity": "sha512-DNk4Ylo4T69N9d9jRv8u94T88nzZgvHVVFd1W254EYrjYEqzVUcmqVQAgdzhqcTH3RLO3OQ8NvgnVYfBLKNuvQ==",+ "version": "https://github.com/jitsi/lib-jitsi-meet/releases/download/v2236.0.0+51058e35/lib-jitsi-meet.tgz",+ "integrity": "sha512-AIbDciGJrCKNIK1YVGZ4o41dV/lVdgXM6RT6CdetMWr0mmAkxH3DRCdY0drtfx3ORIjFqhyPdF/7h6fy1cAowA==","requires": {"@jitsi/js-utils": "12.0.7","@jitsi/logger": "2.1.1",diff --git a/package.json b/package.jsonindex fb42c5d6d6..516ab3c2ba 100644--- a/package.json+++ b/package.json@@ -76,7 +76,7 @@"js-md5": "0.6.1","js-sha512": "0.8.0","jwt-decode": "2.2.0",- "lib-jitsi-meet": "https://github.com/jitsi/lib-jitsi-meet/releases/download/v2233.0.0+7634be62/lib-jitsi-meet.tgz",+ "lib-jitsi-meet": "https://github.com/jitsi/lib-jitsi-meet/releases/download/v2236.0.0+51058e35/lib-jitsi-meet.tgz","lodash-es": "4.18.1","null-loader": "4.0.1","optional-require": "1.0.3",diff --git a/react/features/audio-translation/components/native/AudioTranslationDialog.tsx b/react/features/audio-translation/components/native/AudioTranslationDialog.tsxindex 3749cc66ea..fbf79b3aaa 100644--- a/react/features/audio-translation/components/native/AudioTranslationDialog.tsx+++ b/react/features/audio-translation/components/native/AudioTranslationDialog.tsx@@ -1,4 +1,4 @@-import React, { useCallback } from 'react';+import React, { useCallback, useMemo } from 'react';import { WithTranslation } from 'react-i18next';import { ScrollView, StyleProp, ViewStyle } from 'react-native';import { useDispatch, useSelector } from 'react-redux';@@ -8,7 +8,7 @@ import { translate } from '../../../base/i18n/functions';import JitsiScreen from '../../../base/modal/components/JitsiScreen';import { goBack } from '../../../mobile/navigation/components/conference/ConferenceNavigationContainerRef';import { setAudioTranslationLanguage, setParticipantAudioTranslationLanguage } from '../../actions';-import { SUPPORTED_TRANSLATION_LANGUAGES } from '../../constants';+import { getAudioTranslationLanguageLabel, orderAudioTranslationLanguages } from '../../functions';import AudioTranslationLanguageItem from './AudioTranslationLanguageItem';import styles from './styles';@@ -33,6 +33,7 @@ const AudioTranslationDialog = ({ route, t }: IProps) => {const defaultLanguage = useSelector((state: IReduxState) => state['features/audio-translation'].language);const participantLanguages= useSelector((state: IReduxState) => state['features/audio-translation'].participantLanguages);+ const languagesConfig = useSelector((state: IReduxState) => state['features/base/config'].audioTranslation);// Highlight the effective language for the target: the per-participant override if one is set, else the// default. (For the conference-wide screen there is no participantId, so this is just the default.)@@ -40,6 +41,10 @@ const AudioTranslationDialog = ({ route, t }: IProps) => {? participantLanguages[participantId]: defaultLanguage;+ // Recomputed only when the config block or the active language changes, not on every store update.+ const languages = useMemo(+ () => orderAudioTranslationLanguages(languagesConfig, language), [ languagesConfig, language ]);+const onSelect = useCallback((code: string | null) => {if (participantId) {dispatch(setParticipantAudioTranslationLanguage(participantId, code));@@ -59,11 +64,11 @@ const AudioTranslationDialog = ({ route, t }: IProps) => {label = { t('toolbar.audioTranslationOff') }onSelect = { onSelect }selected = { !language } />- { SUPPORTED_TRANSLATION_LANGUAGES.map(({ code, label }) => (+ { languages.map(code => (<AudioTranslationLanguageItemcode = { code }key = { code }- label = { label }+ label = { getAudioTranslationLanguageLabel(code, t) }onSelect = { onSelect }selected = { language === code } />)) }diff --git a/react/features/audio-translation/components/web/AudioTranslationDialog.tsx b/react/features/audio-translation/components/web/AudioTranslationDialog.tsxindex 8b2ce47fd5..38fb821479 100644--- a/react/features/audio-translation/components/web/AudioTranslationDialog.tsx+++ b/react/features/audio-translation/components/web/AudioTranslationDialog.tsx@@ -1,4 +1,4 @@-import React, { useCallback } from 'react';+import React, { useCallback, useMemo } from 'react';import { useDispatch, useSelector } from 'react-redux';import { makeStyles } from 'tss-react/mui';@@ -7,7 +7,7 @@ import { hideDialog } from '../../../base/dialog/actions';import { translate } from '../../../base/i18n/functions';import Dialog from '../../../base/ui/components/web/Dialog';import { setAudioTranslationLanguage, setParticipantAudioTranslationLanguage } from '../../actions';-import { SUPPORTED_TRANSLATION_LANGUAGES } from '../../constants';+import { getAudioTranslationLanguageLabel, orderAudioTranslationLanguages } from '../../functions';import AudioTranslationLanguageItem from './AudioTranslationLanguageItem';@@ -46,6 +46,7 @@ const AudioTranslationDialog = ({ participantId, t }: IProps) => {const defaultLanguage = useSelector((state: IReduxState) => state['features/audio-translation'].language);const participantLanguages= useSelector((state: IReduxState) => state['features/audio-translation'].participantLanguages);+ const languagesConfig = useSelector((state: IReduxState) => state['features/base/config'].audioTranslation);// Highlight the effective language for the target: the per-participant override if one is set, else the// default. (For the conference-wide dialog there is no participantId, so this is just the default.)@@ -53,6 +54,10 @@ const AudioTranslationDialog = ({ participantId, t }: IProps) => {? participantLanguages[participantId]: defaultLanguage;+ // Recomputed only when the config block or the active language changes, not on every store update.+ const languages = useMemo(+ () => orderAudioTranslationLanguages(languagesConfig, language), [ languagesConfig, language ]);+const onSelect = useCallback((code: string | null) => {if (participantId) {dispatch(setParticipantAudioTranslationLanguage(participantId, code));@@ -73,11 +78,11 @@ const AudioTranslationDialog = ({ participantId, t }: IProps) => {label = { t('toolbar.audioTranslationOff') }onSelect = { onSelect }selected = { !language } />- { SUPPORTED_TRANSLATION_LANGUAGES.map(({ code, label }) => (+ { languages.map(code => (<AudioTranslationLanguageItemcode = { code }key = { code }- label = { label }+ label = { getAudioTranslationLanguageLabel(code, t) }onSelect = { onSelect }selected = { language === code } />)) }diff --git a/react/features/audio-translation/constants.ts b/react/features/audio-translation/constants.tsindex 2c0e50c4f9..cd3b64a48f 100644--- a/react/features/audio-translation/constants.ts+++ b/react/features/audio-translation/constants.ts@@ -1,7 +1,9 @@/**- * Supported AI audio-translation target languages: ISO code + picker label.+ * Default AI audio-translation target languages offered when config.audioTranslation.translationLanguages is unset: the+ * set every speech-to-speech provider supports, as code + native-script picker label. A deployment whose+ * provider accepts more can replace the offered set in config (see orderAudioTranslationLanguages).*/-export const SUPPORTED_TRANSLATION_LANGUAGES: Array<{ code: string; label: string; }> = [+export const DEFAULT_TRANSLATION_LANGUAGES: Array<{ code: string; label: string; }> = [{ code: 'en', label: 'English' },{ code: 'es', label: 'Español' },{ code: 'pt', label: 'Português' },diff --git a/react/features/audio-translation/functions.ts b/react/features/audio-translation/functions.tsindex a86f581d25..6b86e838e6 100644--- a/react/features/audio-translation/functions.ts+++ b/react/features/audio-translation/functions.ts@@ -1,4 +1,5 @@import { IReduxState } from '../app/types';+import { IConfig } from '../base/config/configType';import { AUDIO_TRANSLATION_ENABLED } from '../base/flags/constants';import { getFeatureFlag } from '../base/flags/functions';import { MEET_FEATURES } from '../base/jwt/constants';@@ -6,7 +7,8 @@ import { isJwtFeatureEnabled } from '../base/jwt/functions';import { isLocalParticipantModerator } from '../base/participants/functions';import { ITrack } from '../base/tracks/types';-import { DUCKED_ORIGINAL_VOLUME } from './constants';+import { DEFAULT_TRANSLATION_LANGUAGES, DUCKED_ORIGINAL_VOLUME } from './constants';+import logger from './logger';/*** Whether audio translation is enabled for the room. Driven by the {@code audioTranslation} RoomMetadata flag,@@ -161,6 +163,188 @@ export function shouldDuckOriginalAudio(state: IReduxState, sourceName?: string,return getTranslatedSourceNames(state).has(`${sourceName}.${language}`);}+/**+ * Configuration problems already logged by {@link orderAudioTranslationLanguages}, so each is reported once rather+ * than on every render.+ */+const reportedConfigProblems = new Set<string>();++/**+ * Whether a configured code can be requested as a translation language today. Prosody's audio-translation+ * component ({@code mod_audio_translation_component.lua}, {@code is_valid_language}) accepts only ASCII letters,+ * at most 20 of them, and rejects the whole request with {@code bad-request} on the first invalid entry, so one bad+ * code configured for a meeting-wide language fails translation for every speaker. The lib-jitsi-meet source-name+ * parser accepts a region or script subtag ('pt-BR'), so the prosody check is what has to change before such+ * codes can be offered.+ *+ * @param {string} code - The language code.+ * @returns {boolean}+ */+function isUsableAudioTranslationCode(code: string): boolean {+ return /^[a-z]{1,20}$/i.test(code);+}++/**+ * The target languages offered in the audio-translation picker, in order:+ * {@code config.audioTranslation.translationLanguages} (else the built-in default list every provider supports),+ * with the codes named in {@code translationLanguagesHead} moved to the top. The head only reorders: a head entry+ * is matched to the offered list case-insensitively and takes the list's spelling, and one that is not in the list+ * is ignored, so it can neither add a language the deployment's provider may not accept nor change the exact code+ * sent. The currently selected language, if any, is kept in the list even when the configuration no longer offers+ * it, so the picker can still show what is active (the rows match it by exact string). Codes are kept as spelled+ * (they go to the bridge and on to the translation provider as-is) and deduplicated case-insensitively; blanks are+ * dropped, and codes prosody would refuse are dropped with a warning (see {@link isUsableAudioTranslationCode}).+ * The defaults apply only when {@code translationLanguages} is unset ({@code undefined}, or {@code null}, which is+ * how a {@code configOverwrite} resets a key): a list that is set but unusable (not an array, empty, or every+ * entry dropped) is a misconfiguration, logged once, and offers nothing rather than 13 languages the deployer did+ * not choose and the provider may not accept.+ *+ * @param {Object | undefined} config - The {@code audioTranslation} config block ({@code IConfig['audioTranslation']}).+ * @param {string | null | undefined} selectedLanguage - The language currently active for the picker's target.+ * @returns {Array<string>} The language codes, in picker order.+ */+export function orderAudioTranslationLanguages(+ config: IConfig['audioTranslation'],+ selectedLanguage?: string | null): Array<string> {+ const key = (code: string) => code.toLowerCase();+ const reportOnce = (what: string, message: string) => {+ if (!reportedConfigProblems.has(what)) {+ reportedConfigProblems.add(what);+ logger.warn(message);+ }+ };+ const clean = (codes: unknown, what: 'language' | 'head entry'): Array<string> => {+ const seen = new Set<string>();+ const out: Array<string> = [];++ for (const code of Array.isArray(codes) ? codes : []) {+ const trimmed = typeof code === 'string' ? code.trim() : '';++ if (!trimmed || seen.has(key(trimmed))) {+ continue;+ }+ if (!isUsableAudioTranslationCode(trimmed)) {+ reportOnce(`${what}:${trimmed}`, `Ignoring audio-translation ${what} "${trimmed}": prosody accepts `+ + 'only codes of 1-20 ASCII letters');+ continue;+ }+ seen.add(key(trimmed));+ out.push(trimmed);+ }++ return out;+ };+ const configured = config?.translationLanguages;+ let list: Array<string>;++ if (configured === undefined || configured === null) {+ list = DEFAULT_TRANSLATION_LANGUAGES.map(({ code }) => code);+ } else {+ list = clean(configured, 'language');+ if (list.length === 0) {+ // Keyed on the value, so a different bad list on a later join in the same session is reported too.+ const shown = JSON.stringify(configured);++ reportOnce(`list:${shown}`, 'config.audioTranslation.translationLanguages is set but offers no usable '+ + `language (${shown}); the picker offers none`);+ }+ }++ // Head entries take the list's spelling, so the head cannot change the code that is sent.+ const byKey = new Map(list.map(code => [ key(code), code ]));+ const head = clean(config?.translationLanguagesHead, 'head entry')+ .map(code => byKey.get(key(code)))+ .filter((code): code is string => Boolean(code));+ const headKeys = new Set(head.map(key));+ const selected = selectedLanguage && !list.includes(selectedLanguage) ? [ selectedLanguage ] : [];++ return [ ...head, ...selected, ...list.filter(code => !headKeys.has(key(code))) ];+}++/**+ * Own-locale language names already resolved through {@code Intl.DisplayNames}, by code. The lookups are cheap but+ * run per row per render, and the answer for a code never changes within a session.+ */+const displayNameCache = new Map<string, string | undefined>();++/**+ * The name of a language in that language, from the platform's CLDR data via {@code Intl.DisplayNames}, or+ * undefined when the API is missing (Hermes implements no {@code Intl.DisplayNames}, so this is always undefined+ * on mobile), the code is not a valid tag, the platform has no locale data for that language, or CLDR has no name+ * for it ({@code fallback: 'none'}). The locale-data check matters: without it the API quietly resolves to the+ * viewer's default locale and returns the name in the viewer's language ('Klingon' for 'tlh' on an English+ * browser), which would differ per viewer and skip the documented English fallback. CLDR gives Latin-script names+ * in lower case ('español'), so the first letter is upper-cased in the language's own locale.+ *+ * @param {string} code - The language code.+ * @returns {string | undefined}+ */+function getOwnLocaleLanguageName(code: string): string | undefined {+ if (displayNameCache.has(code)) {+ return displayNameCache.get(code);+ }++ let name: string | undefined;++ if (typeof Intl !== 'undefined' && typeof Intl.DisplayNames === 'function') {+ try {+ if (Intl.DisplayNames.supportedLocalesOf([ code ]).length > 0) {+ const raw = new Intl.DisplayNames([ code ], { fallback: 'none', type: 'language' }).of(code);++ if (raw) {+ name = raw.charAt(0).toLocaleUpperCase(code) + raw.slice(1);+ }+ }+ } catch (_) {+ // An invalid language tag throws RangeError; fall through to the i18n lookup.+ }+ }+ displayNameCache.set(code, name);++ return name;+}++/**+ * The picker label for an audio-translation language code: the hand-written native-script label of the default+ * list when the code is on it (the same on every platform); else the language's own name from+ * {@code Intl.DisplayNames} where the platform has it (browsers; not Hermes, see {@link getOwnLocaleLanguageName});+ * else the English name from the {@code translation-languages} i18n namespace (lang/translation-languages.json);+ * else the code itself.+ *+ * @param {string} code - The language code.+ * @param {Function} t - The i18n translate function.+ * @returns {string}+ */+export function getAudioTranslationLanguageLabel(code: string, t: (key: string) => string): string {+ const builtIn = DEFAULT_TRANSLATION_LANGUAGES.find(entry => entry.code === code);++ if (builtIn) {+ return builtIn.label;+ }++ const ownName = getOwnLocaleLanguageName(code);++ if (ownName) {+ return ownName;+ }++ // Try the code as configured first, then lower-cased, which is how translation-languages.json keys the plain+ // codes the picker can offer (isUsableAudioTranslationCode admits no subtags, so there is no region or script+ // casing to normalise).+ const lower = code.toLowerCase();++ for (const candidate of lower === code ? [ code ] : [ code, lower ]) {+ const translated = t(`translation-languages:${candidate}`);++ // i18next returns the key without its namespace when there is no translation.+ if (translated && translated !== candidate) {+ return translated;+ }+ }++ return code;+}+/*** The ducked volume (0..1) from config.audioTranslation.duckedVolume; invalid values fall back to default.*diff --git a/react/features/audio-translation/middleware.any.ts b/react/features/audio-translation/middleware.any.tsindex 98d7cb54cd..e20751a1a0 100644--- a/react/features/audio-translation/middleware.any.ts+++ b/react/features/audio-translation/middleware.any.ts@@ -24,6 +24,10 @@ import logger from './logger';* fall back to {@link DEFAULT_ERROR_KEY}.*/const ERROR_NOTIFICATION_KEYS: { [condition: string]: string; } = {+ // The component refused the request itself: most often a language code it does not accept (letters only),+ // though a malformed payload gets the same condition. Retrying cannot help, so the message says what happened+ // and points at the configuration as the thing to check, rather than saying "try again".+ [JitsiAudioTranslationErrors.BAD_REQUEST]: 'audioTranslation.errorBadRequest',[JitsiAudioTranslationErrors.FORBIDDEN]: 'audioTranslation.errorForbidden',[JitsiAudioTranslationErrors.SPEAKER_UNAVAILABLE]: 'audioTranslation.errorSpeakerUnavailable',[JitsiAudioTranslationErrors.SUBSCRIPTION_LIMIT_REACHED]: 'audioTranslation.errorLimitReached'diff --git a/react/features/base/config/configType.ts b/react/features/base/config/configType.tsindex 89853a4570..d7286ff697 100644--- a/react/features/base/config/configType.ts+++ b/react/features/base/config/configType.ts@@ -232,6 +232,8 @@ export interface IConfig {audioTranslation?: {duckedVolume?: number;enabled?: boolean;+ translationLanguages?: Array<string>;+ translationLanguagesHead?: Array<string>;};/*** @deprecated Use `transcription.autoTranscribeOnRecord` instead.