From 0f381bcdba8009179cb64254e84e35bfb46efa08 Mon Sep 17 00:00:00 2001 From: shooding Date: Wed, 27 Nov 2024 16:11:31 +0800 Subject: [PATCH 1/2] fix: transcript 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. --- react/features/subtitles/middleware.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/react/features/subtitles/middleware.ts b/react/features/subtitles/middleware.ts index a5cbb58e004e..5ea61975fcf8 100644 --- a/react/features/subtitles/middleware.ts +++ b/react/features/subtitles/middleware.ts @@ -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); } @@ -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. From f42497de81dadbfcda0971d404fb6f9b32822df7 Mon Sep 17 00:00:00 2001 From: shooding Date: Mon, 16 Dec 2024 11:30:06 +0800 Subject: [PATCH 2/2] fix: lint issue --- react/features/subtitles/middleware.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/react/features/subtitles/middleware.ts b/react/features/subtitles/middleware.ts index 5ea61975fcf8..760aa82dd463 100644 --- a/react/features/subtitles/middleware.ts +++ b/react/features/subtitles/middleware.ts @@ -261,10 +261,10 @@ function _endpointMessageReceived(store: IStore, next: Function, action: AnyActi } /** - * 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 + * 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) {