2021-08-09 09:29:50 +00:00
|
|
|
import i18next from 'i18next';
|
|
|
|
|
2022-09-19 07:40:03 +00:00
|
|
|
import { IConfig } from '../base/config/configType';
|
|
|
|
|
2021-09-09 13:23:03 +00:00
|
|
|
import JITSI_TO_BCP47_MAP from './jitsi-bcp47-map.json';
|
|
|
|
import logger from './logger';
|
|
|
|
import TRANSCRIBER_LANGS from './transcriber-langs.json';
|
2021-08-09 09:29:50 +00:00
|
|
|
|
|
|
|
const DEFAULT_TRANSCRIBER_LANG = 'en-US';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine which language to use for transcribing.
|
|
|
|
*
|
|
|
|
* @param {*} config - Application config.
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2022-09-19 07:40:03 +00:00
|
|
|
export function determineTranscriptionLanguage(config: IConfig) {
|
2022-06-28 11:11:26 +00:00
|
|
|
const { transcription } = config;
|
2021-10-01 15:23:46 +00:00
|
|
|
|
|
|
|
// if transcriptions are not enabled nothing to determine
|
2022-06-28 11:11:26 +00:00
|
|
|
if (!transcription?.enabled) {
|
2021-10-01 15:23:46 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
2021-08-09 09:29:50 +00:00
|
|
|
|
|
|
|
// Depending on the config either use the language that the app automatically detected or the hardcoded
|
2021-09-09 13:23:03 +00:00
|
|
|
// 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.
|
2022-06-28 11:11:26 +00:00
|
|
|
const bcp47Locale = transcription?.useAppLanguage ?? true
|
2022-09-19 07:40:03 +00:00
|
|
|
? JITSI_TO_BCP47_MAP[i18next.language as keyof typeof JITSI_TO_BCP47_MAP]
|
2022-06-28 11:11:26 +00:00
|
|
|
: transcription?.preferredLanguage;
|
2021-09-09 13:23:03 +00:00
|
|
|
|
|
|
|
// Check if the obtained language is supported by the transcriber
|
2022-09-19 07:40:03 +00:00
|
|
|
let safeBCP47Locale = TRANSCRIBER_LANGS[bcp47Locale as keyof typeof TRANSCRIBER_LANGS] && bcp47Locale;
|
2021-09-09 13:23:03 +00:00
|
|
|
|
|
|
|
if (!safeBCP47Locale) {
|
|
|
|
safeBCP47Locale = DEFAULT_TRANSCRIBER_LANG;
|
|
|
|
logger.warn(`Transcriber language ${bcp47Locale} is not supported, using default ${DEFAULT_TRANSCRIBER_LANG}`);
|
|
|
|
}
|
2021-08-09 09:29:50 +00:00
|
|
|
|
2021-09-09 13:23:03 +00:00
|
|
|
logger.info(`Transcriber language set to ${safeBCP47Locale}`);
|
2021-08-09 09:29:50 +00:00
|
|
|
|
2021-09-09 13:23:03 +00:00
|
|
|
return safeBCP47Locale;
|
2021-08-09 09:29:50 +00:00
|
|
|
}
|