Skip to content

Commit

Permalink
fix(transcript) fix matching languages with variants
Browse files Browse the repository at this point in the history
* fixtranscript results from whisper may have json.language="zh-TW" also requesting transcriptions language could be "zh-CN". Use _getPrimaryLanguageCode func to compare only the main lang code.

* fix: lint issue
  • Loading branch information
shooding authored Dec 16, 2024
1 parent 3745c19 commit 9d7237d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion react/features/subtitles/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ function _endpointMessageReceived(store: IStore, next: Function, action: AnyActi
// Regex to filter out all possible country codes after language code:
// this should catch all notations like 'en-GB' 'en_GB' and 'enGB'
// and be independent of the country code length
if (json.language.replace(/[-_A-Z].*/, '') !== language) {
if (_getPrimaryLanguageCode(json.language) !== _getPrimaryLanguageCode(language)) {
return next(action);
}

Expand Down Expand Up @@ -260,6 +260,17 @@ function _endpointMessageReceived(store: IStore, next: Function, action: AnyActi
return next(action);
}

/**
* Utility function to extract the primary language code like 'en-GB' 'en_GB'
* 'enGB' 'zh-CN' and 'zh-TW'.
*
* @param {string} language - The language to use for translation or user requested.
* @returns {string}
*/
function _getPrimaryLanguageCode(language: string) {
return language.replace(/[-_A-Z].*/, '');
}

/**
* Toggle the local property 'requestingTranscription'. This will cause Jicofo
* and Jigasi to decide whether the transcriber needs to be in the room.
Expand Down

0 comments on commit 9d7237d

Please sign in to comment.