Main utils and the T object

38 views
Skip to first unread message

Alan Etkin

unread,
Apr 5, 2026, 10:53:21 AM (8 days ago) Apr 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 PM (7 days ago) Apr 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 PM (7 days ago) Apr 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 PM (6 days ago) Apr 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
Reply all
Reply to author
Forward
0 new messages