Can you post a minimal app the reproduces the problem?

On Saturday, April 6, 2019 at 4:24:12 AM UTC-4, João Matos wrote:
>
> All my grids and forms get auto-translated validation messages correctly. 
> Here is an example
>
>         table = db.sn_counter  # type: Table
>
>         grid = SQLFORM.grid(
>             table,
>             csv=False,
>             details=False,
>             ondelete=on_delete,  # Grid only.
>             onvalidation=on_validation,  # Form only.
>             orderby=db.sn_counter.name,
>             paginate=session.auth.user.pagination,
>             # represent_none='',  # Grid and view form only.
>             sortable=False,
>         )  # type: gluon.DIV
>
> which uses this table
>
> db.define_table('sn_counter',
>                 Field('name', 'string', label=T('Name'), length=NAME_LEN, 
> notnull=True,
>                       required=True, unique=True),
>                 Field('last_assigned', 'integer', default=0, label=T('Last 
> assigned'),
>                       notnull=True, required=True),
>                 Field('canceled_on', 'datetime', label=T('Canceled on'), 
> writable=False),
>                 Field('canceled_by', 'reference auth_user', label=T('Canceled 
> by'),
>                       writable=False),
>                 Field('cancel_approved_by', 'reference auth_user',
>                       label=T('Cancel approved by'), writable=False),
>                 auth.signature,
>                 # common_filter = lambda query: db.sn_counter.is_active 
> == True,
>                 format='%(name)s',
>                 # plural=T('sn counters'), singular=T('sn counter'),
>                 )
>
> # db.sn_counter.name.requires = (IS_NOT_EMPTY(), IS_NOT_IN_DB(db, '
> sn_counter.name'))
> db.sn_counter.last_assigned.requires = IS_INT_IN_RANGE(0, 100000)
>
> I give the option to the user to change the language between PT and EN. 
> Yes, it overrides T.force('pt') with T.force('en') and update sthe page.
> My original code didn't have a T.force('pt') before the extra_fields and 
> so all my validation messages appeared correctly in PT or EN, except for 
> the validation messages of the extra_fields (they always appeared in EN).
> If I add the T.force('pt') before adding the extra_fields, all my 
> validation messages appear correctly in PT or EN, but all the extra_fields 
> validation messages appear only in PT.
>
> No, I'm using just one application.
>
>
> sexta-feira, 5 de Abril de 2019 às 23:35:38 UTC+1, Anthony escreveu:
>>
>> Hmm, I see that the framework does add the T translator to the Validator 
>> class, so validation messages should be getting translated. There is 
>> nothing special about Auth extra_fields -- the validators you add there are 
>> no different from the validators added to other fields.
>>
>> Can you give an example of code using the same validator where the 
>> message is translated outside of extra_fields but not within extra_fields?
>>
>> Also, in your example, you mentioned when setting T.force('pt'), all 
>> messages came out in Portuguese, even if you "change the language to 
>> English". What do you mean by "change the language to English" there? 
>> Setting T.force('pt') should force all translations to Portuguese unless 
>> you override the T.force('pt').
>>
>> Finally, are you running/sending requests to more than one application, 
>> not all of which have the same translation files?
>>
>> Anthony
>>
>> On Friday, April 5, 2019 at 2:03:57 PM UTC-4, João Matos wrote:
>>>
>>> All my other error messages (from built-in validators) are 
>>> auto-translated. Including for the default auth_user fields (eg. username). 
>>> Only the extra_fields are not.
>>>
>>> Is there a fix?
>>>
>>>
>>> sexta-feira, 5 de Abril de 2019 às 18:56:10 UTC+1, Anthony escreveu:
>>>>
>>>> Note, this is due to the recent refactoring of all built-in validators 
>>>> (moved from web2py to pydal). Previously, all default error messages were 
>>>> translated, but that is no longer the case. Although the automatic 
>>>> translation was not documented, I would still consider this a break in 
>>>> backward compatibility (particularly given that all Auth error messages 
>>>> are 
>>>> still being translated automatically).
>>>>
>>>> Anthony
>>>>
>>>> On Thursday, April 4, 2019 at 3:25:10 PM UTC-4, João Matos wrote:
>>>>>
>>>>> When creating extra fields for auth_user, the validation messages for 
>>>>> those fields are always in English. They don't comply with the 
>>>>> translations 
>>>>> available.
>>>>>
>>>>> This does not happen on the default fields.
>>>>>
>>>>>
>>>>> I added this to db.py
>>>>>
>>>>>
>>>>> auth.settings.extra_fields['auth_user'] = [Field('pagination', 
>>>>> 'integer', default=9, label=T('Pagination'), notnull=True, required=
>>>>> True, requires=IS_INT_IN_RANGE(5, 51))] 
>>>>>
>>>>>
>>>>> When inserting an invalid value, the returned message is always
>>>>>
>>>>> Enter an integer between 5 and 50
>>>>>>
>>>>> even when the web2py language is not English and the languages files 
>>>>> have the correct translation available.
>>>>>
>>>>>
>>>>> web2py 2.18.4
>>>>> Python 3.7.1 x86
>>>>> Firefox 66.0.2 x64
>>>>> Windows 7 Pro x64 SP1+all updates
>>>>>
>>>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to