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
fix(subtitles): keep CC button title in sync with subtitles state
damenchoffef8d28cfee
diff --git a/react/features/base/toolbox/components/AbstractButton.tsx b/react/features/base/toolbox/components/AbstractButton.tsxindex d93205f396..45f007b788 100644--- a/react/features/base/toolbox/components/AbstractButton.tsx+++ b/react/features/base/toolbox/components/AbstractButton.tsx@@ -265,6 +265,19 @@ export default class AbstractButton<P extends IProps, S = any> extends Component|| this.label;}+ /**+ * Gets the props used to interpolate the label's translation. Subclasses can+ * override this to compute them from the current props so the label stays in+ * sync with state changes (a static {@code labelProps} field is only evaluated+ * once on construction).+ *+ * @protected+ * @returns {Object}+ */+ _getLabelProps() {+ return this.labelProps;+ }+/*** Gets the current accessibility label, taking the toggled state into* account. If no toggled label is provided, the regular accessibility label@@ -391,7 +404,7 @@ export default class AbstractButton<P extends IProps, S = any> extends ComponentelementAfter: this._getElementAfter(),icon: this._getIcon(),label: this._getLabel(),- labelProps: this.labelProps,+ labelProps: this._getLabelProps(),styles: this._getStyles(),toggled: this._isToggled(),tooltip: this._getTooltip()diff --git a/react/features/subtitles/components/AbstractClosedCaptionButton.tsx b/react/features/subtitles/components/AbstractClosedCaptionButton.tsxindex 59354c85ce..ad3936e753 100644--- a/react/features/subtitles/components/AbstractClosedCaptionButton.tsx+++ b/react/features/subtitles/components/AbstractClosedCaptionButton.tsx@@ -14,6 +14,12 @@ import { canStartSubtitles, isCCTabEnabled } from '../functions.any';*/export interface IAbstractProps extends AbstractButtonProps {+ /**+ * The default language used for transcriptions, shown on the button when subtitles are enabled+ * without a translation language selected (i.e. the source language).+ */+ _defaultLanguage?: string;+/*** Whether the subtitles tab is enabled in the UI.*/diff --git a/react/features/subtitles/components/web/ClosedCaptionButton.tsx b/react/features/subtitles/components/web/ClosedCaptionButton.tsxindex 0d7dfe940a..07dc15b2e4 100644--- a/react/features/subtitles/components/web/ClosedCaptionButton.tsx+++ b/react/features/subtitles/components/web/ClosedCaptionButton.tsx@@ -2,8 +2,10 @@ import { connect } from 'react-redux';import { IReduxState } from '../../../app/types';import { translate } from '../../../base/i18n/functions';+import { DEFAULT_LANGUAGE } from '../../../base/i18n/i18next';import { IconSubtitles } from '../../../base/icons/svg';import { openCCPanel } from '../../../chat/actions.any';+import { getTranscriptionLanguage } from '../../../transcribing/functions';import { setRequestingSubtitles } from '../../actions.any';import { toggleLanguageSelectorDialog } from '../../actions.web';import { canStartSubtitles, isCCTabEnabled, isTranslationEnabled } from '../../functions.any';@@ -19,11 +21,26 @@ import {class ClosedCaptionButtonextends AbstractClosedCaptionButton {override icon = IconSubtitles;- override labelProps = {- language: this.props.t(this.props._language ?? 'transcribing.subtitlesOff'),- languages: this.props.t(this.props.languages ?? ''),- languagesHead: this.props.t(this.props.languagesHead ?? '')- };++ /**+ * Computes the label interpolation props from the current props on every render so the button+ * title stays in sync when subtitles are toggled (the button instance is not always remounted).+ * When subtitles are on without a translation language selected, the default transcription+ * (source) language is shown.+ *+ * @returns {Object}+ */+ override _getLabelProps() {+ const { t, _defaultLanguage, _language, _requestingSubtitles, languages, languagesHead } = this.props;++ return {+ language: t(_requestingSubtitles+ ? _language ?? `translation-languages:${_defaultLanguage}`+ : 'transcribing.subtitlesOff'),+ languages: t(languages ?? ''),+ languagesHead: t(languagesHead ?? '')+ };+ }/*** Gets the current button label based on the CC tab state.@@ -88,11 +105,16 @@ class ClosedCaptionButtonfunction mapStateToProps(state: IReduxState, ownProps: IAbstractProps) {const { visible = canStartSubtitles(state) || isCCTabEnabled(state) } = ownProps;+ const transcriptionLanguage = getTranscriptionLanguage(state['features/base/config']);+return {..._abstractMapStateToProps(state, {...ownProps,visible}),++ // Strip the region from the BCP-47 locale (e.g. en-US -> en) to match the translation-languages keys.+ _defaultLanguage: transcriptionLanguage?.replace(/[-_].*/, '') ?? DEFAULT_LANGUAGE,_isTranslationEnabled: isTranslationEnabled(state)};}diff --git a/react/features/transcribing/functions.ts b/react/features/transcribing/functions.tsindex e597b0383e..d3782de2f8 100644--- a/react/features/transcribing/functions.ts+++ b/react/features/transcribing/functions.ts@@ -12,12 +12,13 @@ import TRANSCRIBER_LANGS from './transcriber-langs.json';const DEFAULT_TRANSCRIBER_LANG = 'en-US';/**- * Determine which language to use for transcribing.+ * Resolves the BCP-47 locale the transcriber will use, without any logging side effect. Safe to+ * call from selectors / mapStateToProps.*- * @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) {+export function getTranscriptionLanguage(config: IConfig) {const { transcription } = config;// if transcriptions are not enabled nothing to determine@@ -39,11 +40,28 @@ export function determineTranscriptionLanguage(config: IConfig) {: transcription?.preferredLanguage;// Check if the obtained language is supported by the transcriber- let safeBCP47Locale = transcriberLangs[bcp47Locale as keyof typeof transcriberLangs] && bcp47Locale;+ if (transcriberLangs[bcp47Locale as keyof typeof transcriberLangs] && bcp47Locale) {+ return bcp47Locale;+ }++ return DEFAULT_TRANSCRIBER_LANG;+}++/**+ * Determine which language to use for transcribing.+ *+ * @param {*} config - Application config.+ * @returns {string}+ */+export function determineTranscriptionLanguage(config: IConfig) {+ const safeBCP47Locale = getTranscriptionLanguage(config);++ if (typeof safeBCP47Locale === 'undefined') {+ return undefined;+ }- if (!safeBCP47Locale) {- safeBCP47Locale = DEFAULT_TRANSCRIBER_LANG;- logger.warn(`Transcriber language ${bcp47Locale} is not supported, using default ${DEFAULT_TRANSCRIBER_LANG}`);+ if (safeBCP47Locale === DEFAULT_TRANSCRIBER_LANG) {+ logger.warn(`Transcriber language unsupported or unset, using default ${DEFAULT_TRANSCRIBER_LANG}`);}logger.info(`Transcriber language set to ${safeBCP47Locale}`);