Commit fee0c41c by Ned Batchelder

XBlock fields with formatted-in values can now translate properly

parent e00867cc
...@@ -140,10 +140,16 @@ class CourseMetadata(object): ...@@ -140,10 +140,16 @@ class CourseMetadata(object):
for field in descriptor.fields.values(): for field in descriptor.fields.values():
if field.scope != Scope.settings: if field.scope != Scope.settings:
continue continue
field_help = _(field.help) # pylint: disable=translation-of-non-string
help_args = field.runtime_options.get('help_format_args')
if help_args is not None:
field_help = field_help.format(**help_args)
result[field.name] = { result[field.name] = {
'value': field.read_json(descriptor), 'value': field.read_json(descriptor),
'display_name': _(field.display_name), # pylint: disable=translation-of-non-string 'display_name': _(field.display_name), # pylint: disable=translation-of-non-string
'help': _(field.help), # pylint: disable=translation-of-non-string 'help': field_help,
'deprecated': field.runtime_options.get('deprecated', False) 'deprecated': field.runtime_options.get('deprecated', False)
} }
return result return result
......
...@@ -732,7 +732,8 @@ class CourseFields(object): ...@@ -732,7 +732,8 @@ class CourseFields(object):
'For example, to specify that teams should have a maximum of 5 participants and provide a list of ' 'For example, to specify that teams should have a maximum of 5 participants and provide a list of '
'2 topics, enter the configuration in this format: {example_format}. ' '2 topics, enter the configuration in this format: {example_format}. '
'In "id" values, the only supported special characters are underscore, hyphen, and period.' 'In "id" values, the only supported special characters are underscore, hyphen, and period.'
).format( ),
help_format_args=dict(
# Put the sample JSON into a format variable so that translators # Put the sample JSON into a format variable so that translators
# don't muck with it. # don't muck with it.
example_format=( example_format=(
......
...@@ -178,7 +178,8 @@ class InheritanceMixin(XBlockMixin): ...@@ -178,7 +178,8 @@ class InheritanceMixin(XBlockMixin):
"Identify a video, 5-10 seconds in length, to play before course videos. Enter the video ID from " "Identify a video, 5-10 seconds in length, to play before course videos. Enter the video ID from "
"the Video Uploads page and one or more transcript files in the following format: {format}. " "the Video Uploads page and one or more transcript files in the following format: {format}. "
"For example, an entry for a video with two transcripts looks like this: {example}" "For example, an entry for a video with two transcripts looks like this: {example}"
).format( ),
help_format_args=dict(
format='{"video_id": "ID", "transcripts": {"language": "/static/filename.srt"}}', format='{"video_id": "ID", "transcripts": {"language": "/static/filename.srt"}}',
example=( example=(
'{' '{'
......
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