Commit 6bbc37de by Sarina Canelake

Merge pull request #10287 from open-craft/validate-utils-gettext-extraction

Extract translatable strings from edx.utils.validate.js.
parents cabe396a 27238654
...@@ -24,12 +24,13 @@ ...@@ -24,12 +24,13 @@
var _fn = { var _fn = {
validate: { validate: {
template: _.template( '<li><%= content %></li>' ),
msg: { msg: {
email: '<li><%- gettext("The email address you\'ve provided isn\'t formatted correctly.") %></li>', email: gettext("The email address you've provided isn't formatted correctly."),
min: '<li><%- _.sprintf( gettext("%(field)s must have at least %(count)d characters."), context ) %></li>', min: gettext("%(field)s must have at least %(count)d characters."),
max: '<li><%- _.sprintf( gettext("%(field)s can only contain up to %(count)d characters."), context ) %></li>', max: gettext("%(field)s can only contain up to %(count)d characters."),
required: '<li><%- _.sprintf( gettext("Please enter your %(field)s."), context ) %></li>', required: gettext("Please enter your %(field)s.")
custom: '<li><%= content %></li>'
}, },
field: function( el ) { field: function( el ) {
...@@ -131,9 +132,9 @@ ...@@ -131,9 +132,9 @@
getMessage: function( $el, tests ) { getMessage: function( $el, tests ) {
var txt = [], var txt = [],
tpl,
label, label,
obj, context,
content,
customMsg; customMsg;
_.each( tests, function( value, key ) { _.each( tests, function( value, key ) {
...@@ -143,30 +144,20 @@ ...@@ -143,30 +144,20 @@
// If the field has a custom error msg attached, use it // If the field has a custom error msg attached, use it
if ( customMsg ) { if ( customMsg ) {
tpl = _fn.validate.msg.custom; content = customMsg;
obj = {
content: customMsg
};
} else { } else {
tpl = _fn.validate.msg[key]; context = {field: label};
obj = {
// We pass the context object to the template so that
// we can perform variable interpolation using sprintf
context: {
field: label
}
};
if ( key === 'min' ) { if ( key === 'min' ) {
obj.context.count = parseInt( $el.attr('minlength'), 10 ); context.count = parseInt( $el.attr('minlength'), 10 );
} else if ( key === 'max' ) { } else if ( key === 'max' ) {
obj.context.count = parseInt( $el.attr('maxlength'), 10 ); context.count = parseInt( $el.attr('maxlength'), 10 );
} }
content = _.sprintf( _fn.validate.msg[key], context );
} }
txt.push( _.template( tpl, obj ) ); txt.push( _fn.validate.template( {content: content} ) );
} }
}); });
......
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