localize strings in captions pad

This commit is contained in:
KDSBrowne 2019-06-14 14:33:46 +00:00
parent 127f4ac19e
commit ab1610615b
3 changed files with 61 additions and 18 deletions

View File

@ -21,6 +21,22 @@ const intlMessages = defineMessages({
id: 'app.captions.pad.ownership', id: 'app.captions.pad.ownership',
description: 'Label for taking ownership of closed captions pad', description: 'Label for taking ownership of closed captions pad',
}, },
dictationStart: {
id: 'app.captions.pad.dictationStart',
description: 'Label for starting speech recognition',
},
dictationStop: {
id: 'app.captions.pad.dictationStop',
description: 'Label for stoping speech recognition',
},
dictationOnDesc: {
id: 'app.captions.pad.dictationOnDesc',
description: 'Aria description for button that turns on speech recognition',
},
dictationOffDesc: {
id: 'app.captions.pad.dictationOffDesc',
description: 'Aria description for button that turns off speech recognition',
},
}); });
const propTypes = { const propTypes = {
@ -31,26 +47,23 @@ const propTypes = {
name: PropTypes.string.isRequired, name: PropTypes.string.isRequired,
amIModerator: PropTypes.bool.isRequired, amIModerator: PropTypes.bool.isRequired,
editCaptions: PropTypes.func.isRequired, editCaptions: PropTypes.func.isRequired,
initVoiceRecognition: PropTypes.func.isRequired,
intl: PropTypes.shape({ intl: PropTypes.shape({
formatMessage: PropTypes.func.isRequired, formatMessage: PropTypes.func.isRequired,
}).isRequired, }).isRequired,
}; };
class Pad extends Component { class Pad extends Component {
constructor() { constructor(props) {
super(); super(props);
this.state = { this.state = {
listening: false, listening: false,
text: '', text: '',
}; };
const SR = window.SpeechRecognition || window.webkitSpeechRecognition; const { initVoiceRecognition } = props;
this.recognition = new SR(); this.recognition = initVoiceRecognition();
this.recognition.continuous = true;
this.recognition.interimResults = true;
this.recognition.lang = 'en-CA';
this.toggleListen = this.toggleListen.bind(this); this.toggleListen = this.toggleListen.bind(this);
this.handleListen = this.handleListen.bind(this); this.handleListen = this.handleListen.bind(this);
@ -62,12 +75,13 @@ class Pad extends Component {
listening, listening,
} = this.state; } = this.state;
if (nextState.text !== text && nextState.text !== '') { const padTextUpdate = nextState.text !== text && nextState.text !== '';
return true; const listeningUpdate = nextState.listening !== listening;
}
if (nextState.listening !== listening) { if (padTextUpdate || listeningUpdate) {
return true; return true;
} }
return false; return false;
} }
@ -160,11 +174,23 @@ class Pad extends Component {
className={styles.hideBtn} className={styles.hideBtn}
/> />
</div> </div>
<Button <span>
onClick={() => { this.toggleListen(); }} <Button
label="Voice Recognition" onClick={() => { this.toggleListen(); }}
color="primary" label={listening
/> ? intl.formatMessage(intlMessages.dictationStop)
: intl.formatMessage(intlMessages.dictationStart)
}
aria-describedby="dictationBtnDesc"
color="primary"
/>
<div id="dictationBtnDesc" hidden>
{listening
? intl.formatMessage(intlMessages.dictationOffDesc)
: intl.formatMessage(intlMessages.dictationOnDesc)
}
</div>
</span>
{CaptionsService.canIOwnThisPad(ownerId) {CaptionsService.canIOwnThisPad(ownerId)
? ( ? (
<Button <Button

View File

@ -30,6 +30,18 @@ export default withTracker(() => {
const { name } = caption ? caption.locale : ''; const { name } = caption ? caption.locale : '';
const initVoiceRecognition = (lang = 'en-CA') => {
const SR = window.SpeechRecognition || window.webkitSpeechRecognition;
let recognition = null;
if (SR) {
recognition = new SR();
recognition.continuous = true;
recognition.interimResults = true;
recognition.lang = lang;
}
return recognition;
};
return { return {
locale, locale,
name, name,
@ -38,5 +50,6 @@ export default withTracker(() => {
readOnlyPadId, readOnlyPadId,
amIModerator: CaptionsService.amIModerator(), amIModerator: CaptionsService.amIModerator(),
editCaptions, editCaptions,
initVoiceRecognition,
}; };
})(PadContainer); })(PadContainer);

View File

@ -33,6 +33,10 @@
"app.captions.pad.hide": "Hide closed captions", "app.captions.pad.hide": "Hide closed captions",
"app.captions.pad.tip": "Press Esc to focus editor toolbar", "app.captions.pad.tip": "Press Esc to focus editor toolbar",
"app.captions.pad.ownership": "Take ownership", "app.captions.pad.ownership": "Take ownership",
"app.captions.pad.dictationStart": "Start Dictation",
"app.captions.pad.dictationStop": "Stop Dictation",
"app.captions.pad.dictationOnDesc": "Turns speech recognition on",
"app.captions.pad.dictationOffDesc": "Turns speech recognition off",
"app.note.title": "Shared Notes", "app.note.title": "Shared Notes",
"app.note.label": "Note", "app.note.label": "Note",
"app.note.hideNoteLabel": "Hide note", "app.note.hideNoteLabel": "Hide note",