Is it possible to translate data in SQLFORM.grid?

120 views
Skip to first unread message

Gael Princivalle

unread,
Jul 30, 2015, 2:55:12 AM7/30/15
to web2py-users
Hello all.

Is it possible to translate data in SQLFORM.grid?

MODEL:
db.define_table('fruits',
               
Field('name', type='string'),
                format
='%(name)s')

db
.define_table('cake',
               
Field('name', type='string'),
               
Field('fruit', 'reference fruits', requires = IS_IN_DB(db, db.fruits.id, '%(name)s'), represent=lambda id, r: db.fruits[id].name))

CONTROLLER:
grid=SQLFORM.grid(db.cake)

VIEW:
{{=grid}}

In the fruits table, names are in english, for example "Apple".

Is it possible to set for this field in the grid automatic traductions like T()?

In this case for example I would like to have in an Italian page "Mela" instead of "Apple".

Thanks.

Massimiliano

unread,
Jul 30, 2015, 3:38:01 AM7/30/15
to web...@googlegroups.com
Have you tried?

db.cake.fruit.represent = lambda v, r: T(db.fruits[v].name)
grid=SQLFORM.grid(db.cake)


--
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+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Massimiliano

Gael Princivalle

unread,
Jul 30, 2015, 5:10:24 AM7/30/15
to web2py-users, mbel...@gmail.com
Thank a lot Massimiliano.
I've to remind to search more for solutions with the lambda function.

Yebach

unread,
Nov 15, 2017, 2:47:54 AM11/15/17
to web2py-users
hello

I have a similar problem except it goes for only one table - no parent - child relationship

db.define_table('config',
Field('co_code', type = 'string', length = 256 ,label = T('Code')),
Field('co_organization','reference organizations' ,label = T('Organization')),
Field('co_value', type = 'string', length = 256 ,label = T('Value')),
Field('co_area', type = 'string', length = 256 ,label = T('Area')),
Field('co_note',type = 'text' ,label = T('Note')),
Field('co_access_level',type = 'integer'),
migrate = settings.migrate,
fake_migrate=settings.fake_migrate,
)

I would like to translate values from co_note. 

Different variations of your suggested answer do not work 
db.config.represent = lambda v, r: T(db.config[v])
db.config.represent = lambda v, r: T(db.config[v].co_note)

Any suggestions? I do have translations already in my language.py file

Leonel Câmara

unread,
Nov 15, 2017, 6:44:05 AM11/15/17
to web2py-users
Yebach your code is wrong.


db.config.represent = lambda v, r: T(db.config[v].co_note)



Should be

db
.config.co_note.represent = lambda v, r: T(v)



Bruno Duarte Ramos

unread,
Jun 14, 2018, 10:37:55 AM6/14/18
to web2py-users
Hello,

Is is possible translate a data in a SQLFORM?

Where my controller is:

form=SQLFORM(db.cake)

And my view:

{{=form}}

thanks.

Anthony

unread,
Jun 15, 2018, 9:09:01 AM6/15/18
to web2py-users
On Thursday, June 14, 2018 at 10:37:55 AM UTC-4, Bruno Duarte Ramos wrote:
Hello,

Is is possible translate a data in a SQLFORM?

Where my controller is:

form=SQLFORM(db.cake)

And my view:

{{=form}}

Are you saying you want the stored values of an existing record to be translated before inserting them in an update form? If you did that, when the form is submitted, the translated values would be stored rather than the original ones. What exactly are you trying to achieve?

Anthony

Bruno Duarte Ramos

unread,
Jun 18, 2018, 7:50:23 AM6/18/18
to web...@googlegroups.com
Hi Anthony, actually I just want to translate the form on my view, like my view was {{=T(form)}}.

--
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+unsubscribe@googlegroups.com.

黄祥

unread,
Jun 18, 2018, 8:51:33 AM6/18/18
to web2py-users
perhaps you can achieve it using label=T()
e.g.
table.field.label = T('Field')

best regards,
stifan

Anthony

unread,
Jun 18, 2018, 10:31:31 AM6/18/18
to web2py-users
On Monday, June 18, 2018 at 7:50:23 AM UTC-4, Bruno Duarte Ramos wrote:
Hi Anthony, actually I just want to translate the form on my view, like my view was {{=T(form)}}.

Yes, but what exactly do you want translated in the form? Do you want the actual data values translated? If so, that doesn't quite make sense, because then the translated values would end up getting submitted and saved to the database.

Please described the exact user workflow and experience you are trying to achieve.

Anthony
Reply all
Reply to author
Forward
0 new messages