You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.js 1.3KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // @flow
  2. import i18next from 'i18next';
  3. import JITSI_TO_BCP47_MAP from './jitsi-bcp47-map.json';
  4. import logger from './logger';
  5. import TRANSCRIBER_LANGS from './transcriber-langs.json';
  6. const DEFAULT_TRANSCRIBER_LANG = 'en-US';
  7. /**
  8. * Determine which language to use for transcribing.
  9. *
  10. * @param {*} config - Application config.
  11. * @returns {string}
  12. */
  13. export function determineTranscriptionLanguage(config: Object) {
  14. const { preferredTranscribeLanguage, transcribeWithAppLanguage = true } = config;
  15. // Depending on the config either use the language that the app automatically detected or the hardcoded
  16. // config BCP47 value.
  17. // Jitsi language detections uses custom language tags, but the transcriber expects BCP-47 compliant tags,
  18. // we use a mapping file to convert them.
  19. const bcp47Locale = transcribeWithAppLanguage ? JITSI_TO_BCP47_MAP[i18next.language] : preferredTranscribeLanguage;
  20. // Check if the obtained language is supported by the transcriber
  21. let safeBCP47Locale = TRANSCRIBER_LANGS[bcp47Locale] && bcp47Locale;
  22. if (!safeBCP47Locale) {
  23. safeBCP47Locale = DEFAULT_TRANSCRIBER_LANG;
  24. logger.warn(`Transcriber language ${bcp47Locale} is not supported, using default ${DEFAULT_TRANSCRIBER_LANG}`);
  25. }
  26. logger.info(`Transcriber language set to ${safeBCP47Locale}`);
  27. return safeBCP47Locale;
  28. }