grid: top + button: how to adapt dynamically & translate the title 'add record to database' ?

46 views
Skip to first unread message

Serge Bourgeois

unread,
Feb 12, 2018, 5:01:17 AM2/12/18
to web2py-users

Hello,
The following codes changes dynamically the title of the button on the top left of the form in English.
But when I switch to another language (exemple FR), I get the French translation of 'Add record to database', and not the translation of what I have placed in the title of this button.

Example:
  
    form = SQLFOR.smartgrid(db[my_table]..., showbuttontext=False, ...)

    if not 'view' in request.args and not 'edit' in request.args and not 'new' in request.args:
       addbutton = form.element(_title='Add record to database')
       my_table = 'my application table'
       addbutton['_title'] = '%s %s' % ( T('Add'), db[my_table]._singular
    return dict(form = form)
=> in English, the title of the + button is 'Add' + the value of db[my_table]._singular : This is perfect!
=> in French, I always get 'Ajout d'un enregistrement', which is the translation of 'Add record to database'. : this is not what I want...

I have tried the following, but, same result:
   if not 'view' in request.args and not 'edit' in request.args and not 'new' in request.args:
       my_title = T('Add record to database)'
       addbutton = form.element(_title= my_title)
       my_table = 'my application table'
       addbutton['_title'] = '%s %s' % ( T('Add'), db[my_table]._singular
    return dict(form = form)

Thanks for any advise for translating the title of the top left '+' button when I change if in the controller.

Luciano Bovio

unread,
May 5, 2020, 12:44:31 AM5/5/20
to web2py-users
I have the same problem on translation.... I have to modify button text with jQuery. Any ideas ?
Reply all
Reply to author
Forward
0 new messages