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 @@
<select class="openassessment_training_example_criterion_option setting-input" data-criterion="{{ criterion.name }}" data-option="{{ option.name }}">
<option value="">{% trans "Not Scored" %}</option>
{% 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 %}
>
{{ option.label }} - {{ option.points }} {% trans "points" %}
......
......@@ -18,6 +18,19 @@ if (typeof window.gettext === 'undefined') {
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
if (typeof window.Logger === 'undefined') {
window.Logger = {
......
......@@ -21,6 +21,37 @@ OpenAssessment.ItemUtilities = {
index++;
}
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 = {
**/
OpenAssessment.TrainingExample = function(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 = {
......
......@@ -25,8 +25,10 @@ OpenAssessment.StudentTrainingListener.prototype = {
$(sel, this.element).each(
function() {
var criterion = this;
var option = $('option[value="' + data.name + '"]', criterion);
$(option).text(view._generateOptionString(data.label, data.points));
var option = $('option[value="' + data.name + '"]', criterion)
.data("points", data.points)
.data("label", data.label);
OpenAssessment.ItemUtilities.refreshOptionString(option);
}
);
},
......@@ -64,9 +66,14 @@ OpenAssessment.StudentTrainingListener.prototype = {
// Risky; making an assumption that options will remain simple.
// updates could cause this to get out of sync with templates,
// but this avoids overly complex templating code.
$(criterion).append($("<option></option>")
var option = $("<option></option>")
.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;
}
});
......@@ -328,19 +335,5 @@ OpenAssessment.StudentTrainingListener.prototype = {
}
);
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