2022-08-31 15:57:31 +00:00
|
|
|
/* eslint-disable lines-around-comment */
|
2022-10-18 11:42:51 +00:00
|
|
|
import i18next from 'i18next';
|
2022-09-27 07:10:28 +00:00
|
|
|
import React, { useCallback, useEffect, useState } from 'react';
|
2022-10-18 11:42:51 +00:00
|
|
|
import { WithTranslation } from 'react-i18next';
|
2022-08-31 15:57:31 +00:00
|
|
|
import { useDispatch } from 'react-redux';
|
2022-10-18 11:42:51 +00:00
|
|
|
import { makeStyles } from 'tss-react/mui';
|
2022-08-31 15:57:31 +00:00
|
|
|
|
2022-10-20 09:11:27 +00:00
|
|
|
import { IReduxState } from '../../app/types';
|
2022-08-31 15:57:31 +00:00
|
|
|
// @ts-ignore
|
2022-09-29 11:44:59 +00:00
|
|
|
import { TRANSLATION_LANGUAGES, TRANSLATION_LANGUAGES_HEAD } from '../../base/i18n';
|
2022-10-18 11:42:51 +00:00
|
|
|
import { translate, translateToHTML } from '../../base/i18n/functions';
|
2022-09-05 11:24:13 +00:00
|
|
|
import { connect } from '../../base/redux/functions';
|
2022-10-10 09:12:02 +00:00
|
|
|
import Dialog from '../../base/ui/components/web/Dialog';
|
2022-08-31 15:57:31 +00:00
|
|
|
// @ts-ignore
|
2022-10-18 11:42:51 +00:00
|
|
|
import { openSettingsDialog } from '../../settings/actions';
|
|
|
|
import { SETTINGS_TABS } from '../../settings/constants';
|
|
|
|
// @ts-ignore
|
2022-09-29 11:44:59 +00:00
|
|
|
import { setRequestingSubtitles, toggleLanguageSelectorDialog, updateTranslationLanguage } from '../actions';
|
2022-08-31 15:57:31 +00:00
|
|
|
|
2022-10-21 11:09:15 +00:00
|
|
|
import LanguageList from './LanguageList.web';
|
2022-08-31 15:57:31 +00:00
|
|
|
|
2022-10-18 11:42:51 +00:00
|
|
|
|
|
|
|
interface ILanguageSelectorDialogProps extends WithTranslation {
|
2022-09-08 09:52:36 +00:00
|
|
|
_language: string;
|
2022-09-29 11:44:59 +00:00
|
|
|
_translationLanguages: Array<string>;
|
|
|
|
_translationLanguagesHead: Array<string>;
|
2022-08-31 15:57:31 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 07:50:22 +00:00
|
|
|
const useStyles = makeStyles()(theme => {
|
2022-10-18 11:42:51 +00:00
|
|
|
return {
|
|
|
|
paragraphWrapper: {
|
|
|
|
fontSize: 14,
|
|
|
|
margin: '10px 0px',
|
|
|
|
color: theme.palette.text01
|
|
|
|
},
|
|
|
|
spanWrapper: {
|
|
|
|
fontWeight: 700,
|
|
|
|
cursor: 'pointer',
|
|
|
|
color: theme.palette.link01,
|
|
|
|
'&:hover': {
|
|
|
|
backgroundColor: theme.palette.ui04,
|
|
|
|
color: theme.palette.link01Hover
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2022-08-31 15:57:31 +00:00
|
|
|
/**
|
|
|
|
* Component that renders the subtitle language selector dialog.
|
|
|
|
*
|
|
|
|
* @returns {React$Element<any>}
|
|
|
|
*/
|
2022-10-10 09:12:02 +00:00
|
|
|
const LanguageSelectorDialog = ({
|
2022-10-18 11:42:51 +00:00
|
|
|
t,
|
2022-10-10 09:12:02 +00:00
|
|
|
_language,
|
|
|
|
_translationLanguages,
|
|
|
|
_translationLanguagesHead
|
|
|
|
}: ILanguageSelectorDialogProps) => {
|
2022-10-18 11:42:51 +00:00
|
|
|
const { classes: styles } = useStyles();
|
2022-08-31 15:57:31 +00:00
|
|
|
const dispatch = useDispatch();
|
|
|
|
const off = 'transcribing.subtitlesOff';
|
|
|
|
const [ language, setLanguage ] = useState(off);
|
|
|
|
|
2022-09-29 11:44:59 +00:00
|
|
|
const languagesHead = _translationLanguagesHead.map((lang: string) => `translation-languages:${lang}`);
|
|
|
|
// The off and the head languages are always on the top of the list. But once you are selecting
|
|
|
|
// a language from the translationLanguages, that language is moved under the fixedItems list,
|
|
|
|
// until a new languages is selected. FixedItems keep their positions.
|
|
|
|
const fixedItems = [ off, ...languagesHead ];
|
|
|
|
const languages = _translationLanguages
|
|
|
|
.map((lang: string) => `translation-languages:${lang}`)
|
|
|
|
.filter((lang: string) => !(lang === language || languagesHead.includes(lang)));
|
2022-08-31 15:57:31 +00:00
|
|
|
|
|
|
|
const listItems = (fixedItems.includes(language)
|
|
|
|
? [ ...fixedItems, ...languages ]
|
|
|
|
: [ ...fixedItems, language, ...languages ])
|
|
|
|
.map((lang, index) => {
|
|
|
|
return {
|
|
|
|
id: lang + index,
|
|
|
|
lang,
|
|
|
|
selected: lang === language
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
_language ? setLanguage(_language) : setLanguage(off);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const onLanguageSelected = useCallback((e: string) => {
|
|
|
|
setLanguage(e);
|
|
|
|
dispatch(updateTranslationLanguage(e));
|
|
|
|
dispatch(setRequestingSubtitles(e !== off));
|
2022-09-29 11:44:59 +00:00
|
|
|
dispatch(toggleLanguageSelectorDialog());
|
2022-08-31 15:57:31 +00:00
|
|
|
}, [ _language ]);
|
|
|
|
|
2022-10-18 11:42:51 +00:00
|
|
|
const onSourceLanguageClick = useCallback(() => {
|
|
|
|
dispatch(openSettingsDialog(SETTINGS_TABS.MORE, false));
|
|
|
|
}, []);
|
|
|
|
|
2022-08-31 15:57:31 +00:00
|
|
|
return (
|
|
|
|
<Dialog
|
2022-10-10 09:12:02 +00:00
|
|
|
cancel = {{ hidden: true }}
|
|
|
|
ok = {{ hidden: true }}
|
|
|
|
titleKey = 'transcribing.subtitles'>
|
2022-10-18 11:42:51 +00:00
|
|
|
<p className = { styles.paragraphWrapper } >
|
|
|
|
{
|
|
|
|
translateToHTML(t, 'transcribing.sourceLanguageDesc', {
|
|
|
|
'sourceLanguage': t(`languages:${i18next.language}`).toLowerCase()
|
|
|
|
})
|
|
|
|
}<span
|
|
|
|
className = { styles.spanWrapper }
|
|
|
|
onClick = { onSourceLanguageClick }>{t('transcribing.sourceLanguageHere')}.</span>
|
|
|
|
</p>
|
2022-08-31 15:57:31 +00:00
|
|
|
<LanguageList
|
|
|
|
items = { listItems }
|
|
|
|
onLanguageSelected = { onLanguageSelected }
|
|
|
|
selectedLanguage = { language } />
|
|
|
|
</Dialog>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps (parts of) the Redux state to the associated props for the
|
|
|
|
* {@code LanguageSelectorDialog} component.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
|
|
|
* @private
|
|
|
|
* @returns {Props}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
function mapStateToProps(state: IReduxState) {
|
2022-09-29 11:44:59 +00:00
|
|
|
const { conference } = state['features/base/conference'];
|
|
|
|
const { _language } = state['features/subtitles'];
|
|
|
|
const { transcription } = state['features/base/config'];
|
2022-08-31 15:57:31 +00:00
|
|
|
|
2022-09-29 11:44:59 +00:00
|
|
|
const languages = transcription?.translationLanguages ?? TRANSLATION_LANGUAGES;
|
|
|
|
const languagesHead = transcription?.translationLanguagesHead ?? TRANSLATION_LANGUAGES_HEAD;
|
2022-08-31 15:57:31 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
_conference: conference,
|
2022-09-29 11:44:59 +00:00
|
|
|
_language,
|
|
|
|
_translationLanguages: languages,
|
|
|
|
_translationLanguagesHead: languagesHead
|
2022-08-31 15:57:31 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-10-18 11:42:51 +00:00
|
|
|
export default translate(connect(mapStateToProps)(LanguageSelectorDialog));
|