How to use T to tranlate strings in web2py module?

676 Views Asked by At

I have a countries.py module living in my web2py applications module folder. It defines the following tuple:

COUNTRIES = (
    ('AF', T('Afghanistan')), 
    ('AX', T('Aland Islands')), 
    ('AL', T('Albania')), 
    ('DZ', T('Algeria')), 
    ('AS', T('American Samoa')), 
    ('AD', T('Andorra')), 
    ('AO', T('Angola')), 
    ('AI', T('Anguilla')), 
    ...

Which can be use to create country drop down list. The problem I have is I get an error:

<type 'exceptions.NameError'> name 'T' is not defined

So how can I use the translator T from a web2py module?

1

There are 1 best solutions below

0
On

Based on this post in the google group:

https://groups.google.com/forum/#!topic/web2py/cHSKbhbcSSA

I added

from gluon import current
T = current.T

to the top of my countries.py module and it seems to be working now.