From 27238654fd56b2879d61ac9f1b28de06ac750a45 Mon Sep 17 00:00:00 2001 From: Matjaz Gregoric Date: Wed, 21 Oct 2015 16:02:00 +0200 Subject: [PATCH] Extract translatable strings from edx.utils.validate.js. The JS validation utility functions from edx.utils.validate.js file that are used on the combined login registration page include some translatable strings that weren't getting extracted by the i18n tools because they were defined inside underscore template strings. This commit pulls the translatable strings out of the templates to make sure gettext detects the strings at extraction time. --- .../common/js/utils/edx.utils.validate.js | 39 +++++++------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/common/static/common/js/utils/edx.utils.validate.js b/common/static/common/js/utils/edx.utils.validate.js index 8fff89cd81..4d82f9ff7a 100644 --- a/common/static/common/js/utils/edx.utils.validate.js +++ b/common/static/common/js/utils/edx.utils.validate.js @@ -24,12 +24,13 @@ var _fn = { validate: { + template: _.template( '
  • <%= content %>
  • ' ), + msg: { - email: '
  • <%- gettext("The email address you\'ve provided isn\'t formatted correctly.") %>
  • ', - min: '
  • <%- _.sprintf( gettext("%(field)s must have at least %(count)d characters."), context ) %>
  • ', - max: '
  • <%- _.sprintf( gettext("%(field)s can only contain up to %(count)d characters."), context ) %>
  • ', - required: '
  • <%- _.sprintf( gettext("Please enter your %(field)s."), context ) %>
  • ', - custom: '
  • <%= content %>
  • ' + email: gettext("The email address you've provided isn't formatted correctly."), + min: gettext("%(field)s must have at least %(count)d characters."), + max: gettext("%(field)s can only contain up to %(count)d characters."), + required: gettext("Please enter your %(field)s.") }, field: function( el ) { @@ -131,9 +132,9 @@ getMessage: function( $el, tests ) { var txt = [], - tpl, label, - obj, + context, + content, customMsg; _.each( tests, function( value, key ) { @@ -143,30 +144,20 @@ // If the field has a custom error msg attached, use it if ( customMsg ) { - tpl = _fn.validate.msg.custom; - - obj = { - content: customMsg - }; + content = customMsg; } else { - tpl = _fn.validate.msg[key]; - - obj = { - // We pass the context object to the template so that - // we can perform variable interpolation using sprintf - context: { - field: label - } - }; + context = {field: label}; if ( key === 'min' ) { - obj.context.count = parseInt( $el.attr('minlength'), 10 ); + context.count = parseInt( $el.attr('minlength'), 10 ); } 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} ) ); } });