Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Translation domains of messages passed to validators #83

rkintzi opened this Issue · 6 comments

4 participants


Take a look at __call__ methods of Range validator:

if self.min is not None:
    if value < self.min:
        min_err = _(self.min_err, mapping={'val':value, 'min':self.min})
        raise Invalid(node, min_err)

Shoudn't there be:

        min_err = translationstring.TranslationString(self.min_err, 
                mapping={'val':value, 'min':self.min})

So it appears that if you pass a TranslationString into a TranslationString, it resolves as you would think. The properties of the inner TranslationString override the outer. So check out this code:

import colander
import translationstring

_ = translationstring.TranslationStringFactory('test')

schema = colander.SchemaNode(colander.Mapping(),
                                                 validator=colander.Range(min=0, max=5, max_err=_('blah'))))

if __name__ == '__main__':
        data = schema.deserialize({'number': 10})
    except Exception as e:
        assert isinstance(e, colander.Invalid)

    # more specifically
    validator = colander.Range(min=0, max=5, max_err=_('blah'))
    assert validator.max_err.domain == 'test'

P.S. sorry for getting around to this so late.


I have a validator:

def age_validator(node, value):
    if value <= 0:
        raise colander.Invalid(node, _(u"Age must be greater then 0"))

Error message is translated to polish, and in a browser I can see translation.

I have just checked that following version of valiadtor does not work (in the browser I see message stored in code).

def age_validator(node, value):
    validator = colander.Range(min=1, min_err=_(u"Age must be greater then 0"))
    assert (validator.min_err.domain == 'KonsultacjeNPR')

For some reason it does not matter that translation domain is correct. The problem does not occur when you use the modified version of the range validator (as I described in first comment).

I am using translationstring-1.1 and colander-0.9.9 (with colander-1.0a2 I have the same problem).

@rkintzi rkintzi closed this
@rkintzi rkintzi reopened this

Ok I have your error reproduced. Going to attempt to find a solution for it.


This issue resulted in a pull request to translationstring, changing the way TranslationStringFactory works. It can be found here: Pylons/translationstring#12.


Marking as "sprintable" to see if someone can determine if this is actually fixed.


Seems to be fixed to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.