From 61b2870dfff4f6871bf6eb2cb8bed08d0f772e5c Mon Sep 17 00:00:00 2001 From: Rodrigo Martin Date: Mon, 6 May 2024 11:32:55 -0300 Subject: [PATCH] feat(AU-1950): Match video CC to unit translation language (#34667) * feat(AU-1950): Match video CC to unit translation language * feat(AU-1950): Update doc string * fix: make dest_lang optional param --- xmodule/video_block/transcripts_utils.py | 8 ++++++-- xmodule/video_block/video_block.py | 13 ++++++++----- xmodule/video_block/video_handlers.py | 1 - 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/xmodule/video_block/transcripts_utils.py b/xmodule/video_block/transcripts_utils.py index 3dd88c2f313e..16de851ea5f2 100644 --- a/xmodule/video_block/transcripts_utils.py +++ b/xmodule/video_block/transcripts_utils.py @@ -856,15 +856,19 @@ def available_translations(self, transcripts, verify_assets=None, is_bumper=Fals # to clean redundant language codes. return list(set(translations)) - def get_default_transcript_language(self, transcripts): + def get_default_transcript_language(self, transcripts, dest_lang=None): """ Returns the default transcript language for this video block. Args: transcripts (dict): A dict with all transcripts and a sub. + dest_lang (unicode): language coming from unit translation language selector. """ sub, other_lang = transcripts["sub"], transcripts["transcripts"] - if self.transcript_language in other_lang: + + if dest_lang and dest_lang in other_lang.keys(): + transcript_language = dest_lang + elif self.transcript_language in other_lang: transcript_language = self.transcript_language elif sub: transcript_language = 'en' diff --git a/xmodule/video_block/video_block.py b/xmodule/video_block/video_block.py index 0df838f90c09..b4fddb63fa7a 100644 --- a/xmodule/video_block/video_block.py +++ b/xmodule/video_block/video_block.py @@ -159,7 +159,7 @@ class VideoBlock( uses_xmodule_styles_setup = True - def get_transcripts_for_student(self, transcripts): + def get_transcripts_for_student(self, transcripts, dest_lang=None): """Return transcript information necessary for rendering the XModule student view. This is more or less a direct extraction from `get_html`. @@ -180,7 +180,7 @@ def get_transcripts_for_student(self, transcripts): elif sub or other_lang: track_url = self.runtime.handler_url(self, 'transcript', 'download').rstrip('/?') - transcript_language = self.get_default_transcript_language(transcripts) + transcript_language = self.get_default_transcript_language(transcripts, dest_lang) native_languages = {lang: label for lang, label in settings.LANGUAGES if len(lang) == 2} languages = { lang: native_languages.get(lang, display) @@ -237,11 +237,11 @@ def prioritize_hls(self, youtube_streams, html5_sources): return False - def student_view(self, _context): + def student_view(self, context): """ Return the student view. """ - fragment = Fragment(self.get_html()) + fragment = Fragment(self.get_html(context=context)) add_sass_to_fragment(fragment, 'VideoBlockDisplay.scss') add_webpack_js_to_fragment(fragment, 'VideoBlockDisplay') shim_xmodule_js(fragment, 'Video') @@ -371,7 +371,10 @@ def get_html(self, view=STUDENT_VIEW, context=None): # lint-amnesty, pylint: di download_video_link = next((url for url in self.html5_sources if not url.endswith('.m3u8')), None) transcripts = self.get_transcripts_info() - track_url, transcript_language, sorted_languages = self.get_transcripts_for_student(transcripts=transcripts) + track_url, transcript_language, sorted_languages = self.get_transcripts_for_student( + transcripts=transcripts, + dest_lang=context.get("dest_lang") + ) cdn_eval = False cdn_exp_group = None diff --git a/xmodule/video_block/video_handlers.py b/xmodule/video_block/video_handlers.py index f79820603043..c835298b1dcb 100644 --- a/xmodule/video_block/video_handlers.py +++ b/xmodule/video_block/video_handlers.py @@ -330,7 +330,6 @@ def transcript(self, request, dispatch): return Response(status=404) if language != self.transcript_language: - self.transcript_language = language try: