py4web translations

70 views
Skip to first unread message

clara

unread,
Feb 17, 2020, 10:08:05 PM2/17/20
to web2py-users
Hi,

I just tried using translations in a template in py4web: [[ =T('some text') ]]

but it doesn't work. I tried importing T in the template but then I got:

"No module named 'yatl.common'"

Probably I am overlooking something...

Any help will be appreciated! 

Thanks,

Clara

Massimo Di Pierro

unread,
Feb 17, 2020, 10:47:41 PM2/17/20
to web2py-users
You have to pass T to the view

@action('index')
@action.uses('index.html', T)
def index():
     return dict(message="hello world", T=T)
# in view .... [[=T(message)]]

or 

@unauthenticated
def index():
     return dict(message="hello world")

and it is all automatic. Need the latest common.py from scaffold.

clara

unread,
Feb 18, 2020, 5:12:56 AM2/18/20
to web2py-users
Thanks Massimo, it works!
Reply all
Reply to author
Forward
0 new messages