Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
79a0cd24
Commit
79a0cd24
authored
May 29, 2014
by
Anton Stupak
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3902 from edx/anton/i18n-choice-group
ChoiceGroup i18n.
parents
9cc5cf0e
71b90a91
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
9 deletions
+20
-9
common/lib/capa/capa/inputtypes.py
+18
-8
common/lib/capa/capa/templates/choicetext.html
+2
-1
No files found.
common/lib/capa/capa/inputtypes.py
View file @
79a0cd24
...
...
@@ -433,6 +433,7 @@ class ChoiceGroup(InputTypeBase):
tags
=
[
'choicegroup'
,
'radiogroup'
,
'checkboxgroup'
]
def
setup
(
self
):
i18n
=
self
.
capa_system
.
i18n
# suffix is '' or [] to change the way the input is handled in --as a scalar or vector
# value. (VS: would be nice to make this less hackish).
if
self
.
tag
==
'choicegroup'
:
...
...
@@ -445,16 +446,20 @@ class ChoiceGroup(InputTypeBase):
self
.
html_input_type
=
"checkbox"
self
.
suffix
=
'[]'
else
:
raise
Exception
(
"ChoiceGroup: unexpected tag {0}"
.
format
(
self
.
tag
))
_
=
i18n
.
ugettext
# Translators: 'ChoiceGroup' is an input type and should not be translated.
msg
=
_
(
"ChoiceGroup: unexpected tag {tag_name}"
)
.
format
(
tag_name
=
self
.
tag
)
raise
Exception
(
msg
)
self
.
choices
=
self
.
extract_choices
(
self
.
xml
)
self
.
_choices_map
=
dict
(
self
.
choices
)
# pylint: disable=attribute-defined-outside-init
self
.
choices
=
self
.
extract_choices
(
self
.
xml
,
i18n
)
self
.
_choices_map
=
dict
(
self
.
choices
,
)
# pylint: disable=attribute-defined-outside-init
@classmethod
def
get_attributes
(
cls
):
_
=
lambda
text
:
text
return
[
Attribute
(
"show_correctness"
,
"always"
),
Attribute
(
'label'
,
''
),
Attribute
(
"submitted_message"
,
"Answer received."
)]
Attribute
(
"submitted_message"
,
_
(
"Answer received."
)
)]
def
_extra_context
(
self
):
return
{
'input_type'
:
self
.
html_input_type
,
...
...
@@ -462,7 +467,7 @@ class ChoiceGroup(InputTypeBase):
'name_array_suffix'
:
self
.
suffix
}
@staticmethod
def
extract_choices
(
element
):
def
extract_choices
(
element
,
i18n
):
"""
Extracts choices for a few input types, such as ChoiceGroup, RadioGroup and
CheckboxGroup.
...
...
@@ -474,12 +479,17 @@ class ChoiceGroup(InputTypeBase):
"""
choices
=
[]
_
=
i18n
.
ugettext
for
choice
in
element
:
if
choice
.
tag
!=
'choice'
:
raise
Exception
(
"[capa.inputtypes.extract_choices] Expected a <choice> tag; got
%
s instead"
%
choice
.
tag
)
msg
=
u"[capa.inputtypes.extract_choices] {error_message}"
.
format
(
# Translators: '<choice>' is a tag name and should not be translated.
error_message
=
_
(
"Expected a <choice> tag; got {given_tag} instead"
)
.
format
(
given_tag
=
choice
.
tag
)
)
raise
Exception
(
msg
)
choices
.
append
((
choice
.
get
(
"name"
),
stringify_children
(
choice
)))
return
choices
...
...
common/lib/capa/capa/templates/choicetext.html
View file @
79a0cd24
<
%!
from
django
.
utils
.
translation
import
ugettext
as
_
%
>
<
%
element_checked =
False
%
>
% for choice_id, _ in choices:
<
%
choice_id =
choice_id
%
>
...
...
@@ -62,7 +63,7 @@
</fieldset>
<input
class=
"choicetextvalue"
type=
"hidden"
name=
"input_${id}{}"
id=
"input_${id}"
value=
"${value|h}"
/>
% if show_correctness == "never" and (value or status not in ['unsubmitted']):
<div
class=
"capa_alert"
>
${
submitted_message
}
</div>
<div
class=
"capa_alert"
>
${
_(submitted_message)
}
</div>
%endif
% if msg:
<span
class=
"message"
>
${msg|n}
</span>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment