Commit f788986f by gradyward

Merge pull request #552 from edx/grady/ORA-689

Fixes the translation of the Option Points display in Student Training Examples Authoring
parents b8cd6294 75b5d5af
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<select class="openassessment_training_example_criterion_option setting-input" data-criterion="{{ criterion.name }}" data-option="{{ option.name }}"> <select class="openassessment_training_example_criterion_option setting-input" data-criterion="{{ criterion.name }}" data-option="{{ option.name }}">
<option value="">{% trans "Not Scored" %}</option> <option value="">{% trans "Not Scored" %}</option>
{% for option in criterion.options %} {% for option in criterion.options %}
<option value={{ option.name }} <option value="{{ option.name }}" data-points="{{ option.points }}" data-label="{{ option.label }}"
{% if criterion.option_selected == option.name %} selected {% endif %} {% if criterion.option_selected == option.name %} selected {% endif %}
> >
{{ option.label }} - {{ option.points }} {% trans "points" %} {{ option.label }} - {{ option.points }} {% trans "points" %}
......
...@@ -18,6 +18,19 @@ if (typeof window.gettext === 'undefined') { ...@@ -18,6 +18,19 @@ if (typeof window.gettext === 'undefined') {
window.gettext = function(text) { return text; }; window.gettext = function(text) { return text; };
} }
// If ngettext isn't found (workbench, testing, etc.), return the simplistic english version
if (typeof window.ngetgext === 'undefined') {
window.ngettext = function (singular_text, plural_text, n) {
if (n > 1) {
return plural_text;
} else {
return singular_text;
}
}
}
// Stub event logging if the runtime doesn't provide it // Stub event logging if the runtime doesn't provide it
if (typeof window.Logger === 'undefined') { if (typeof window.Logger === 'undefined') {
window.Logger = { window.Logger = {
......
...@@ -21,6 +21,37 @@ OpenAssessment.ItemUtilities = { ...@@ -21,6 +21,37 @@ OpenAssessment.ItemUtilities = {
index++; index++;
} }
return index.toString(); return index.toString();
},
/**
Format the option label, including the point value, and add it to the option.
Relies on the data-points and data-label attributes to provide information about the option.
Args:
element (Jquery Element): The element that represents the object.
**/
refreshOptionString: function(element) {
var points = $(element).data('points');
var label = $(element).data('label');
// We don't want the lack of a label to make it look like - 1 points.
if (label == ""){
label = gettext('Unnamed Option');
}
var singularString = label + " - " + points + " point";
var multipleString = label + " - " + points + " points";
// If the option doesn't have a data points value, that indicates to us that it is not a user-specified option,
// but represents the "Not Selected" option which all criterion drop-downs have.
if (typeof points === 'undefined') {
$(element).text(
gettext('Not Selected')
);
}
// Otherwise, set the text of the option element to be the properly conjugated, translated string.
else {
$(element).text(
ngettext(singularString, multipleString, points)
);
}
} }
}; };
...@@ -281,6 +312,12 @@ OpenAssessment.RubricCriterion.prototype = { ...@@ -281,6 +312,12 @@ OpenAssessment.RubricCriterion.prototype = {
**/ **/
OpenAssessment.TrainingExample = function(element){ OpenAssessment.TrainingExample = function(element){
this.element = element; this.element = element;
// Goes through and instantiates the option description in the training example for each option.
$(".openassessment_training_example_criterion_option", this.element) .each( function () {
$('option', this).each(function(){
OpenAssessment.ItemUtilities.refreshOptionString($(this));
});
});
}; };
OpenAssessment.TrainingExample.prototype = { OpenAssessment.TrainingExample.prototype = {
......
...@@ -25,8 +25,10 @@ OpenAssessment.StudentTrainingListener.prototype = { ...@@ -25,8 +25,10 @@ OpenAssessment.StudentTrainingListener.prototype = {
$(sel, this.element).each( $(sel, this.element).each(
function() { function() {
var criterion = this; var criterion = this;
var option = $('option[value="' + data.name + '"]', criterion); var option = $('option[value="' + data.name + '"]', criterion)
$(option).text(view._generateOptionString(data.label, data.points)); .data("points", data.points)
.data("label", data.label);
OpenAssessment.ItemUtilities.refreshOptionString(option);
} }
); );
}, },
...@@ -64,9 +66,14 @@ OpenAssessment.StudentTrainingListener.prototype = { ...@@ -64,9 +66,14 @@ OpenAssessment.StudentTrainingListener.prototype = {
// Risky; making an assumption that options will remain simple. // Risky; making an assumption that options will remain simple.
// updates could cause this to get out of sync with templates, // updates could cause this to get out of sync with templates,
// but this avoids overly complex templating code. // but this avoids overly complex templating code.
$(criterion).append($("<option></option>") var option = $("<option></option>")
.attr("value", data.name) .attr("value", data.name)
.text(view._generateOptionString(data.label, data.points))); .data("points", data.points)
.data("label", data.label);
// Sets the option's text description, and adds it to the criterion.
OpenAssessment.ItemUtilities.refreshOptionString(option);
$(criterion).append(option);
examplesUpdated = true; examplesUpdated = true;
} }
}); });
...@@ -328,19 +335,5 @@ OpenAssessment.StudentTrainingListener.prototype = { ...@@ -328,19 +335,5 @@ OpenAssessment.StudentTrainingListener.prototype = {
} }
); );
return examples; return examples;
},
/**
Format the option label, including the point value.
Args:
name (string): The option label (e.g. "Good", "Fair").
points (int): The number of points that the option is worth.
Returns:
string
**/
_generateOptionString: function(name, points) {
return name + ' - ' + points + gettext(' points');
} }
}; };
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