Main utils and the T object

63 views
Skip to first unread message

Alan Etkin

unread,
Apr 5, 2026, 10:53:21 AMApr 5
to py4web
Hi to everyone

I was making some little research on Form, Grid, and Auth objects and the way they give support translations. Found that:

Auth does not implement a method to translate strings used for building document elements, but it is possible to overwrite the params attribute on-the-fly to use the T object (by adding a few lines to scaffolding common.py module
Grid does implement translations receiving a T object as argument in constructor
Form labels and other strings do not support translations (there are some threads on this subject)

Perhaps it would be possible that Auth and Form class adds support for translations the same way that Grid implements it? The caveat I see on this is the app will not update translations until the class gets instantiated on an action. Another approach would be to customize classes on the model and find a mechanism to use the updated classes in controller.

Regards

Alan

Alan Etkin

unread,
Apr 6, 2026, 3:03:13 PMApr 6
to py4web
About translating database tables and columns, this seems that doesn't work, as the translation files are not updated:

for table in db:
    for field in table:
        if type(field.label) == str:
            field.label = T(field.label)

I'm using py4web 1.20251212.1 dev server on Ubuntu 25

Any hints?

Alan Etkin

unread,
Apr 6, 2026, 7:36:04 PMApr 6
to py4web
If you instead do

for table in db:
    for field in table:
        if type(field.label) == str:
            field.label = T("Holy canoly!")

T works as expected, updating the translation file, so I belive the __call__ method only accepts a string literal, and passing anything else will not be stored for translation. I can't figure out how to automate the translation of the fields without passing a bare string to the T object.

Alan Etkin

unread,
Apr 7, 2026, 6:19:31 PMApr 7
to py4web
Alright, turns out that find_matches in pluralize "scans" app files, not object properties, so the loop logic has no sense for this case.

So, in order to have a string automatically translated, it has to be "hardcoded" in project files

Alan Etkin

unread,
Apr 17, 2026, 4:03:21 PMApr 17
to py4web
Seems that in last py4web code the auth object supports translations. Still, I would like to:

- translate Grid stuff like "search" and "clear" buttons, search error messages*
- translate Form stuff like "submit", "back" buttons and "check to delete"

PD: using translated field labels is a problem since a grid search box requires the actual field names as argument for searches

Regards

Alan

Alan Etkin

unread,
Apr 17, 2026, 4:10:23 PMApr 17
to py4web
Sorry, the grid search feature DOES support translated fields
Reply all
Reply to author
Forward
0 new messages