Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

fix(subtitles): address review comments

damencho26cdc545e8ea
diff --git a/react/features/subtitles/middleware.ts b/react/features/subtitles/middleware.ts
index 9d6e2e1e42..9df91545ba 100644
--- a/react/features/subtitles/middleware.ts
+++ b/react/features/subtitles/middleware.ts
@@ -286,11 +286,17 @@ function _endpointMessageReceived(store: IStore, next: Function, action: AnyActi
// Only display transcription results when the local user is showing subtitles and either
// wants the source language (no translation language selected) or the transcription's
- // language matches the selected one.
+ // language matches the selected one. We rely on the redux _language (which is cleared when
+ // switching back to the original language) rather than the translation_language participant
+ // property, which is never cleared and can become stale.
// The primary language code comparison catches all country-code notations like 'en-GB',
// 'en_GB' and 'enGB' independent of the country code length.
- if (!state['features/subtitles']._requestingSubtitles
- || (language && _getPrimaryLanguageCode(json.language) !== _getPrimaryLanguageCode(language))) {
+ const { _language, _requestingSubtitles } = state['features/subtitles'];
+ const selectedLanguage = _language?.replace('translation-languages:', '');
+
+ if (!_requestingSubtitles
+ || (selectedLanguage
+ && _getPrimaryLanguageCode(json.language) !== _getPrimaryLanguageCode(selectedLanguage))) {
return next(action);
}
diff --git a/react/features/transcribing/functions.ts b/react/features/transcribing/functions.ts
index d3782de2f8..1af862764c 100644
--- a/react/features/transcribing/functions.ts
+++ b/react/features/transcribing/functions.ts
@@ -11,6 +11,25 @@ import TRANSCRIBER_LANGS from './transcriber-langs.json';
const DEFAULT_TRANSCRIBER_LANG = 'en-US';
+/**
+ * Resolves the requested transcription locale from config, without validating it against the
+ * languages supported by the transcriber.
+ *
+ * @param {IConfig} config - Application config.
+ * @returns {string|undefined} - The requested BCP-47 locale, if any.
+ */
+function getRequestedTranscriptionLocale(config: IConfig) {
+ const { transcription } = config;
+
+ // Depending on the config either use the language that the app automatically detected or the hardcoded
+ // config BCP47 value.
+ // Jitsi language detections uses custom language tags, but the transcriber expects BCP-47 compliant tags,
+ // we use a mapping file to convert them.
+ return transcription?.useAppLanguage ?? true
+ ? JITSI_TO_BCP47_MAP[i18next.language as keyof typeof JITSI_TO_BCP47_MAP]
+ : transcription?.preferredLanguage;
+}
+
/**
* Resolves the BCP-47 locale the transcriber will use, without any logging side effect. Safe to
* call from selectors / mapStateToProps.
@@ -30,17 +49,10 @@ export function getTranscriptionLanguage(config: IConfig) {
...TRANSCRIBER_LANGS,
...(transcription.customLanguages ?? {})
};
-
- // Depending on the config either use the language that the app automatically detected or the hardcoded
- // config BCP47 value.
- // Jitsi language detections uses custom language tags, but the transcriber expects BCP-47 compliant tags,
- // we use a mapping file to convert them.
- const bcp47Locale = transcription?.useAppLanguage ?? true
- ? JITSI_TO_BCP47_MAP[i18next.language as keyof typeof JITSI_TO_BCP47_MAP]
- : transcription?.preferredLanguage;
+ const bcp47Locale = getRequestedTranscriptionLocale(config);
// Check if the obtained language is supported by the transcriber
- if (transcriberLangs[bcp47Locale as keyof typeof transcriberLangs] && bcp47Locale) {
+ if (bcp47Locale && transcriberLangs[bcp47Locale as keyof typeof transcriberLangs]) {
return bcp47Locale;
}
@@ -48,10 +60,10 @@ export function getTranscriptionLanguage(config: IConfig) {
}
/**
- * Determine which language to use for transcribing.
+ * Determines which language to use for transcribing and logs the decision.
*
- * @param {*} config - Application config.
- * @returns {string}
+ * @param {IConfig} config - Application config.
+ * @returns {string|undefined} - The resolved BCP-47 locale, or undefined if transcriptions are not enabled.
*/
export function determineTranscriptionLanguage(config: IConfig) {
const safeBCP47Locale = getTranscriptionLanguage(config);
@@ -60,8 +72,11 @@ export function determineTranscriptionLanguage(config: IConfig) {
return undefined;
}
- if (safeBCP47Locale === DEFAULT_TRANSCRIBER_LANG) {
- logger.warn(`Transcriber language unsupported or unset, using default ${DEFAULT_TRANSCRIBER_LANG}`);
+ const requested = getRequestedTranscriptionLocale(config);
+
+ // We fell back to the default only if the requested locale wasn't the one we resolved to.
+ if (requested !== safeBCP47Locale) {
+ logger.warn(`Transcriber language ${requested} is not supported, using default ${DEFAULT_TRANSCRIBER_LANG}`);
}
logger.info(`Transcriber language set to ${safeBCP47Locale}`);