Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

functions.js 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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, transcribingEnabled } = config;
  15. // if transcriptions are not enabled nothing to determine
  16. if (!transcribingEnabled) {
  17. return undefined;
  18. }
  19. // Depending on the config either use the language that the app automatically detected or the hardcoded
  20. // config BCP47 value.
  21. // Jitsi language detections uses custom language tags, but the transcriber expects BCP-47 compliant tags,
  22. // we use a mapping file to convert them.
  23. const bcp47Locale = transcribeWithAppLanguage ? JITSI_TO_BCP47_MAP[i18next.language] : preferredTranscribeLanguage;
  24. // Check if the obtained language is supported by the transcriber
  25. let safeBCP47Locale = TRANSCRIBER_LANGS[bcp47Locale] && bcp47Locale;
  26. if (!safeBCP47Locale) {
  27. safeBCP47Locale = DEFAULT_TRANSCRIBER_LANG;
  28. logger.warn(`Transcriber language ${bcp47Locale} is not supported, using default ${DEFAULT_TRANSCRIBER_LANG}`);
  29. }
  30. logger.info(`Transcriber language set to ${safeBCP47Locale}`);
  31. return safeBCP47Locale;
  32. }