Skip to content

Commit

Permalink
feat(AU-1950): Match video CC to unit translation language (#34667)
Browse files Browse the repository at this point in the history
* feat(AU-1950): Match video CC to unit translation language

* feat(AU-1950): Update doc string

* fix: make dest_lang optional param
  • Loading branch information
Rodra authored May 6, 2024
1 parent 333f1ff commit 61b2870
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
8 changes: 6 additions & 2 deletions xmodule/video_block/transcripts_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
13 changes: 8 additions & 5 deletions xmodule/video_block/video_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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)
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion xmodule/video_block/video_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ def transcript(self, request, dispatch):
return Response(status=404)

if language != self.transcript_language:

self.transcript_language = language

try:
Expand Down

0 comments on commit 61b2870

Please sign in to comment.