Commit 1d7424ed by gradyward

Fixes the translation of the Option Points display in Student Training Examples Authoring

parent feb155b0
...@@ -9,14 +9,10 @@ ...@@ -9,14 +9,10 @@
<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 %}
> >
{% if option.points == 1 %}
{{ option.label }} - {{ option.points }} {% trans "point" %}
{% else %}
{{ option.label }} - {{ option.points }} {% trans "points" %} {{ option.label }} - {{ option.points }} {% trans "points" %}
{% endif %}
</option> </option>
{% endfor %} {% endfor %}
</select> </select>
......
...@@ -17,3 +17,15 @@ if (typeof OpenAssessment == "undefined" || !OpenAssessment) { ...@@ -17,3 +17,15 @@ if (typeof OpenAssessment == "undefined" || !OpenAssessment) {
if (typeof window.gettext === 'undefined') { 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;
}
}
}
\ No newline at end of file
...@@ -21,6 +21,33 @@ OpenAssessment.ItemUtilities = { ...@@ -21,6 +21,33 @@ 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');
var singular_string = label + " - " + points + " point";
var multiple_string = 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(singular_string, multiple_string, points)
);
}
} }
}; };
...@@ -281,6 +308,12 @@ OpenAssessment.RubricCriterion.prototype = { ...@@ -281,6 +308,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 ads 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