Commit f3371643 by louyihua

i18n: Make translation works for video editor tabs

Now the display_name & help strings in video editor tabs can be extracted and translated.
parent 6c7ca7ae
...@@ -44,6 +44,7 @@ def get_ext(filename): ...@@ -44,6 +44,7 @@ def get_ext(filename):
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
_ = lambda text: text
class VideoModule(VideoFields, VideoStudentViewHandlers, XModule): class VideoModule(VideoFields, VideoStudentViewHandlers, XModule):
...@@ -177,12 +178,12 @@ class VideoDescriptor(VideoFields, VideoStudioViewHandlers, TabsEditingDescripto ...@@ -177,12 +178,12 @@ class VideoDescriptor(VideoFields, VideoStudioViewHandlers, TabsEditingDescripto
tabs = [ tabs = [
{ {
'name': "Basic", 'name': _("Basic"),
'template': "video/transcripts.html", 'template': "video/transcripts.html",
'current': True 'current': True
}, },
{ {
'name': "Advanced", 'name': _("Advanced"),
'template': "tabs/metadata-edit-tab.html" 'template': "tabs/metadata-edit-tab.html"
} }
] ]
...@@ -358,7 +359,7 @@ class VideoDescriptor(VideoFields, VideoStudioViewHandlers, TabsEditingDescripto ...@@ -358,7 +359,7 @@ class VideoDescriptor(VideoFields, VideoStudioViewHandlers, TabsEditingDescripto
_ = self.runtime.service(self, "i18n").ugettext _ = self.runtime.service(self, "i18n").ugettext
video_url.update({ video_url.update({
'help': _('The URL for your video. This can be a YouTube URL or a link to an .mp4, .ogg, or .webm video file hosted elsewhere on the Internet.'), 'help': _('The URL for your video. This can be a YouTube URL or a link to an .mp4, .ogg, or .webm video file hosted elsewhere on the Internet.'),
'display_name': 'Default Video URL', 'display_name': _('Default Video URL'),
'field_name': 'video_url', 'field_name': 'video_url',
'type': 'VideoList', 'type': 'VideoList',
'default_value': [get_youtube_link(youtube_id_1_0['default_value'])] 'default_value': [get_youtube_link(youtube_id_1_0['default_value'])]
......
...@@ -14,51 +14,52 @@ _ = lambda text: text ...@@ -14,51 +14,52 @@ _ = lambda text: text
class VideoFields(object): class VideoFields(object):
"""Fields for `VideoModule` and `VideoDescriptor`.""" """Fields for `VideoModule` and `VideoDescriptor`."""
display_name = String( display_name = String(
display_name="Component Display Name", help="The name students see. This name appears in the course ribbon and as a header for the video.", help=_("The name students see. This name appears in the course ribbon and as a header for the video."),
display_name=_("Component Display Name"),
default="Video", default="Video",
scope=Scope.settings scope=Scope.settings
) )
saved_video_position = RelativeTime( saved_video_position = RelativeTime(
help="Current position in the video.", help=_("Current position in the video."),
scope=Scope.user_state, scope=Scope.user_state,
default=datetime.timedelta(seconds=0) default=datetime.timedelta(seconds=0)
) )
# TODO: This should be moved to Scope.content, but this will # TODO: This should be moved to Scope.content, but this will
# require data migration to support the old video module. # require data migration to support the old video module.
youtube_id_1_0 = String( youtube_id_1_0 = String(
help="Optional, for older browsers: the YouTube ID for the normal speed video.", help=_("Optional, for older browsers: the YouTube ID for the normal speed video."),
display_name="YouTube ID", display_name=_("YouTube ID"),
scope=Scope.settings, scope=Scope.settings,
default="OEoXaMPEzfM" default="OEoXaMPEzfM"
) )
youtube_id_0_75 = String( youtube_id_0_75 = String(
help="Optional, for older browsers: the YouTube ID for the .75x speed video.", help=_("Optional, for older browsers: the YouTube ID for the .75x speed video."),
display_name="YouTube ID for .75x speed", display_name=_("YouTube ID for .75x speed"),
scope=Scope.settings, scope=Scope.settings,
default="" default=""
) )
youtube_id_1_25 = String( youtube_id_1_25 = String(
help="Optional, for older browsers: the YouTube ID for the 1.25x speed video.", help=_("Optional, for older browsers: the YouTube ID for the 1.25x speed video."),
display_name="YouTube ID for 1.25x speed", display_name=_("YouTube ID for 1.25x speed"),
scope=Scope.settings, scope=Scope.settings,
default="" default=""
) )
youtube_id_1_5 = String( youtube_id_1_5 = String(
help="Optional, for older browsers: the YouTube ID for the 1.5x speed video.", help=_("Optional, for older browsers: the YouTube ID for the 1.5x speed video."),
display_name="YouTube ID for 1.5x speed", display_name=_("YouTube ID for 1.5x speed"),
scope=Scope.settings, scope=Scope.settings,
default="" default=""
) )
start_time = RelativeTime( # datetime.timedelta object start_time = RelativeTime( # datetime.timedelta object
help="Time you want the video to start if you don't want the entire video to play. Formatted as HH:MM:SS. The maximum value is 23:59:59.", help=_("Time you want the video to start if you don't want the entire video to play. Formatted as HH:MM:SS. The maximum value is 23:59:59."),
display_name="Video Start Time", display_name=_("Video Start Time"),
scope=Scope.settings, scope=Scope.settings,
default=datetime.timedelta(seconds=0) default=datetime.timedelta(seconds=0)
) )
end_time = RelativeTime( # datetime.timedelta object end_time = RelativeTime( # datetime.timedelta object
help="Time you want the video to stop if you don't want the entire video to play. Formatted as HH:MM:SS. The maximum value is 23:59:59.", help=_("Time you want the video to stop if you don't want the entire video to play. Formatted as HH:MM:SS. The maximum value is 23:59:59."),
display_name="Video Stop Time", display_name=_("Video Stop Time"),
scope=Scope.settings, scope=Scope.settings,
default=datetime.timedelta(seconds=0) default=datetime.timedelta(seconds=0)
) )
...@@ -67,61 +68,61 @@ class VideoFields(object): ...@@ -67,61 +68,61 @@ class VideoFields(object):
# `source` is deprecated field and should not be used in future. # `source` is deprecated field and should not be used in future.
# `download_video` is used instead. # `download_video` is used instead.
source = String( source = String(
help="The external URL to download the video.", help=_("The external URL to download the video."),
display_name="Download Video", display_name=_("Download Video"),
scope=Scope.settings, scope=Scope.settings,
default="" default=""
) )
download_video = Boolean( download_video = Boolean(
help="Allow students to download versions of this video in different formats if they cannot use the edX video player or do not have access to YouTube. You must add at least one non-YouTube URL in the Video File URLs field.", help=_("Allow students to download versions of this video in different formats if they cannot use the edX video player or do not have access to YouTube. You must add at least one non-YouTube URL in the Video File URLs field."),
display_name="Video Download Allowed", display_name=_("Video Download Allowed"),
scope=Scope.settings, scope=Scope.settings,
default=False default=False
) )
html5_sources = List( html5_sources = List(
help="The URL or URLs where you've posted non-YouTube versions of the video. Each URL must end in .mpeg, .mp4, .ogg, or .webm and cannot be a YouTube URL. Students will be able to view the first listed video that's compatible with the student's computer. To allow students to download these videos, set Video Download Allowed to True.", help=_("The URL or URLs where you've posted non-YouTube versions of the video. Each URL must end in .mpeg, .mp4, .ogg, or .webm and cannot be a YouTube URL. Students will be able to view the first listed video that's compatible with the student's computer. To allow students to download these videos, set Video Download Allowed to True."),
display_name="Video File URLs", display_name=_("Video File URLs"),
scope=Scope.settings, scope=Scope.settings,
) )
track = String( track = String(
help="By default, students can download an .srt or .txt transcript when you set Download Transcript Allowed to True. If you want to provide a downloadable transcript in a different format, we recommend that you upload a handout by using the Upload a Handout field. If this isn't possible, you can post a transcript file on the Files & Uploads page or on the Internet, and then add the URL for the transcript here. Students see a link to download that transcript below the video.", help=_("By default, students can download an .srt or .txt transcript when you set Download Transcript Allowed to True. If you want to provide a downloadable transcript in a different format, we recommend that you upload a handout by using the Upload a Handout field. If this isn't possible, you can post a transcript file on the Files & Uploads page or on the Internet, and then add the URL for the transcript here. Students see a link to download that transcript below the video."),
display_name="Downloadable Transcript URL", display_name=_("Downloadable Transcript URL"),
scope=Scope.settings, scope=Scope.settings,
default='' default=''
) )
download_track = Boolean( download_track = Boolean(
help="Allow students to download the timed transcript. A link to download the file appears below the video. By default, the transcript is an .srt or .txt file. If you want to provide the transcript for download in a different format, upload a file by using the Upload Handout field.", help=_("Allow students to download the timed transcript. A link to download the file appears below the video. By default, the transcript is an .srt or .txt file. If you want to provide the transcript for download in a different format, upload a file by using the Upload Handout field."),
display_name="Download Transcript Allowed", display_name=_("Download Transcript Allowed"),
scope=Scope.settings, scope=Scope.settings,
default=False default=False
) )
sub = String( sub = String(
help="The default transcript for the video, from the Default Timed Transcript field on the Basic tab. This transcript should be in English. You don't have to change this setting.", help=_("The default transcript for the video, from the Default Timed Transcript field on the Basic tab. This transcript should be in English. You don't have to change this setting."),
display_name="Default Timed Transcript", display_name=_("Default Timed Transcript"),
scope=Scope.settings, scope=Scope.settings,
default="" default=""
) )
show_captions = Boolean( show_captions = Boolean(
help="Specify whether the transcripts appear with the video by default.", help=_("Specify whether the transcripts appear with the video by default."),
display_name="Show Transcript", display_name=_("Show Transcript"),
scope=Scope.settings, scope=Scope.settings,
default=True default=True
) )
# Data format: {'de': 'german_translation', 'uk': 'ukrainian_translation'} # Data format: {'de': 'german_translation', 'uk': 'ukrainian_translation'}
transcripts = Dict( transcripts = Dict(
help="Add transcripts in different languages. Click below to specify a language and upload an .srt transcript file for that language.", help=_("Add transcripts in different languages. Click below to specify a language and upload an .srt transcript file for that language."),
display_name="Transcript Languages", display_name=_("Transcript Languages"),
scope=Scope.settings, scope=Scope.settings,
default={} default={}
) )
transcript_language = String( transcript_language = String(
help="Preferred language for transcript.", help=_("Preferred language for transcript."),
display_name="Preferred language for transcript", display_name=_("Preferred language for transcript"),
scope=Scope.preferences, scope=Scope.preferences,
default="en" default="en"
) )
transcript_download_format = String( transcript_download_format = String(
help="Transcript file format to download by user.", help=_("Transcript file format to download by user."),
scope=Scope.preferences, scope=Scope.preferences,
values=[ values=[
# Translators: This is a type of file used for captioning in the video player. # Translators: This is a type of file used for captioning in the video player.
...@@ -131,22 +132,22 @@ class VideoFields(object): ...@@ -131,22 +132,22 @@ class VideoFields(object):
default='srt', default='srt',
) )
speed = Float( speed = Float(
help="The last speed that the user specified for the video.", help=_("The last speed that the user specified for the video."),
scope=Scope.user_state, scope=Scope.user_state,
) )
global_speed = Float( global_speed = Float(
help="The default speed for the video.", help=_("The default speed for the video."),
scope=Scope.preferences, scope=Scope.preferences,
default=1.0 default=1.0
) )
youtube_is_available = Boolean( youtube_is_available = Boolean(
help="Specify whether YouTube is available for the user.", help=_("Specify whether YouTube is available for the user."),
scope=Scope.user_info, scope=Scope.user_info,
default=True default=True
) )
handout = String( handout = String(
help="Upload a handout to accompany this video. Students can download the handout by clicking Download Handout under the video.", help=_("Upload a handout to accompany this video. Students can download the handout by clicking Download Handout under the video."),
display_name="Upload Handout", display_name=_("Upload Handout"),
scope=Scope.settings, scope=Scope.settings,
) )
...@@ -788,11 +788,14 @@ class XModuleDescriptor(XModuleMixin, HTMLSnippet, ResourceTemplates, XBlock): ...@@ -788,11 +788,14 @@ class XModuleDescriptor(XModuleMixin, HTMLSnippet, ResourceTemplates, XBlock):
if field.scope != Scope.settings or field in self.non_editable_metadata_fields: if field.scope != Scope.settings or field in self.non_editable_metadata_fields:
continue continue
def get_text(value):
return self.runtime.service(self, "i18n").ugettext(value) if value is not None else None
# gets the 'default_value' and 'explicitly_set' attrs # gets the 'default_value' and 'explicitly_set' attrs
metadata_fields[field.name] = self.runtime.get_field_provenance(self, field) metadata_fields[field.name] = self.runtime.get_field_provenance(self, field)
metadata_fields[field.name]['field_name'] = field.name metadata_fields[field.name]['field_name'] = field.name
metadata_fields[field.name]['display_name'] = field.display_name metadata_fields[field.name]['display_name'] = get_text(field.display_name)
metadata_fields[field.name]['help'] = field.help metadata_fields[field.name]['help'] = get_text(field.help)
metadata_fields[field.name]['value'] = field.read_json(self) metadata_fields[field.name]['value'] = field.read_json(self)
# We support the following editors: # We support the following editors:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment