I wanted to use translatable fields using T() function. I couldn't find any
information for this in the document. I could only find the info from forum
discussions. But still there are some problems:
COURSES = {'math': T('Math'), 'phy': T('Physics')}
...
Field(course, requires=IS_IN_SET(COURSES))
works. Only keys (e.g. 'phy') are stored in DB and COURSES dictionary can
be used to display the value (e.g. COURSES['phy']). However, order is not
retained.
Massimo recommends using sets to retain the order here
<https://groups.google.com/d/msg/web2py/Q51pSDExMcE/m-q85-PVggAJ>:
COURSES = (('math', T('Math')), ('phy', T('Physics')))
...
Field(course, requires=IS_IN_SET(COURSES))
This time order is retained but then display will be problematic. Probably
we can use list comprehension to display the translated value but not very
intuitive.
My questions are:
- Is there an easy way for retaining the order and displaying correctly?
- How can we set the default value? e.g. if we set default to 'phy', I
still want to show COURSES['phy'] in the dropdown menu in the form
- Would it be possible to add more info and examples for this function
in the documentation? I think this is very basic function and used
extensively.
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.