Translation domains of messages passed to validators #83

Open
rkintzi opened this Issue Feb 18, 2013 · 6 comments

Comments

Projects
None yet
4 participants
@rkintzi

rkintzi commented Feb 18, 2013

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, 
                domain=self.min_err.domain, 
                default=self.min_err.default,
                mapping={'val':value, 'min':self.min})
@jayd3e

This comment has been minimized.

Show comment Hide comment
@jayd3e

jayd3e Mar 18, 2013

Contributor

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(),
                             colander.SchemaNode(colander.Int(),
                                                 name='number',
                                                 validator=colander.Range(min=0, max=5, max_err=_('blah'))))

if __name__ == '__main__':
    try:
        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.

Contributor

jayd3e commented Mar 18, 2013

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(),
                             colander.SchemaNode(colander.Int(),
                                                 name='number',
                                                 validator=colander.Range(min=0, max=5, max_err=_('blah'))))

if __name__ == '__main__':
    try:
        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.

@rkintzi

This comment has been minimized.

Show comment Hide comment
@rkintzi

rkintzi Mar 18, 2013

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')
    validator(node,value)

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 commented Mar 18, 2013

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')
    validator(node,value)

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 Mar 18, 2013

@rkintzi rkintzi reopened this Mar 18, 2013

@jayd3e

This comment has been minimized.

Show comment Hide comment
@jayd3e

jayd3e Mar 18, 2013

Contributor

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

Contributor

jayd3e commented Mar 18, 2013

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

@jayd3e

This comment has been minimized.

Show comment Hide comment
@jayd3e

jayd3e Mar 19, 2013

Contributor

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

Contributor

jayd3e commented Mar 19, 2013

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

@mcdonc

This comment has been minimized.

Show comment Hide comment
@mcdonc

mcdonc Aug 10, 2013

Member

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

Member

mcdonc commented Aug 10, 2013

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

@latteier

This comment has been minimized.

Show comment Hide comment
@latteier

latteier Apr 15, 2014

Contributor

Seems to be fixed to me.

Contributor

latteier commented Apr 15, 2014

Seems to be fixed to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment