More about translations

21 views
Skip to first unread message

Alan Etkin

unread,
Apr 18, 2026, 2:03:19 PMApr 18
to py4web
I'm stuck with the same issue that found Stefan about the "Submit" text in FormStyleFactory, here:

https://groups.google.com/g/py4web/c/dMn8c-I7zMI/m/OmWcegPIAQAJ

Any suggestions on how to workaround this, perhaps a patch on FormStyleFactory class to make the text customizable?

Also, I can't find where the " check to delete" text of deletable forms is set, so I can translate it with T object or else customize it on Form() calls

Regards

Alan

Alan Etkin

unread,
Apr 18, 2026, 3:38:45 PMApr 18
to py4web
def t_wrapper(obj):
    # A workaround for elements that
    # do not support translations
    if type(obj) == Grid:
        f = obj.form
    else:
        f = obj
    inputs = f.structure.find("input[type=submit]")
    if inputs:
        inputs[0].attributes["_value"] = T("Submit")
    labels = f.structure.find("label.help")
    if labels:
        labels[0].children = " " + T("Check to delete")            
    return obj

I'm using this "wrapper" to wrap calls to Form and Grid at the controller, not very elegant, but works

Alan Etkin

unread,
Apr 18, 2026, 3:51:56 PMApr 18
to py4web
Update, catches None grid.form attributes

def t_wrapper(obj):
    # A workaround for elements that
    # do not support translations
    if type(obj) == Grid:
        f = obj.form
        if not f:
            return obj
    else:
        f = obj
    inputs = f.structure.find("input[type=submit]")
    if inputs:
        inputs[0].attributes["_value"] = T("Submit")
    labels = f.structure.find("label.help")
    if labels:
        labels[0].children = " " + T("Check to delete")            
    return obj

Christian Varas

unread,
Apr 18, 2026, 4:20:11 PMApr 18
to Alan Etkin, py4web
maybe this helps 

Customize Auth messages
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Every form and action message has a standard text for labels, buttons, and emails; however, these can be customized by overriding the values.

For example in ``settings.py`` you can add:

.. code:: python
MESSAGES = {
"verify_email": {
"subject": "Please confirm your email address",
"body": "Hi {first_name},\n\nThank you for joining us! To activate your account, simply click the link below:\n\n{link}\n\nIf you didn’t create an account, please ignore this email.\n\nBest regards,\nThe Team"
},
"reset_password": {
"subject": "Reset your password",
"body": "Hello {first_name},\n\nWe received a request to reset your password. Click the link below to choose a new one:\n\n{link}\n\nIf you didn’t request this, please ignore the email or contact support.\n\nThanks,\nSupport Team"
},
"unsubscribe": {
"subject": "You’re unsubscribed",
"body": "Hi {first_name},\n\nWe’re sorry to see you go. You’ve been removed from our mailing list and will no longer receive emails.\n\nIf you change your mind, feel free to re‑subscribe anytime by visiting our website.\n\nThank you for having been with us.\n\nBest,\nThe Team"
},
"flash": {
"user-registered": "User registered",
"password-reset-link-sent": "Password reset link sent",
"password-changed": "Password changed",
"profile-saved": "Profile saved",
"user-logout": "User logout",
"email-verified": "Email verified",
"link-expired": "Link invalid or expired",
"login-required": "Login required",
},
"labels": {
"username": "Username",
"email": "Email",
"first_name": "First Name",
"last_name": "Last Name",
"phone_number": "Phone Number",
"username_or_email": "Username or Email",
"password": "Password",
"new_password": "New Password",
"old_password": "Old Password",
"login_password": "Password",
"password_again": "Password (again)",
"created_on": "Created On",
"created_by": "Created By",
"modified on": "Modified On",
"modified by": "Modified By",
"two_factor": "Authentication Code",
},
"buttons": {
"lost-password": "Lost Password",
"register": "Register",
"request": "Request",
"sign-in": "Sign In",
"sign-up": "Sign Up",
"submit": "Submit",
},
"errors": {
"registration_is_pending": "Registration is pending",
"account_is_blocked": "Account is blocked",
"account_needs_to_be_approved": "Account needs to be approved",
"invalid_credentials": "Invalid Credentials",
"invalid_token": "invalid token",
"password_doesnt_match": "Password doesn't match",
"invalid_current_password": "invalid current password",
"new_password_is_the_same_as_previous_password": "new password is the same as previous password",
"new_password_was_already_used": "new password was already used",
"invalid": "invalid",
"no_post_payload": "no post payload",
"two_factor": "Verification code does not match",
"two_factor_max_tries": "Two factor max tries exceeded",
},
}
BUTTON_CLASSES = {
"lost-password": "white",
"register": "white",
"request": "white",
"sign-in": "white",
"sign-up": "white",
"submit": "white",
}
In ``common.py`` in Auth section you need to add: auth.param.messages = settings.AUTH_MESSAGES**

#Auth messages
auth.param.messages = settings.AUTH_MESSAGES
auth.define_tables()
auth.fix_actions()
auth.logger = logger





--
You received this message because you are subscribed to the Google Groups "py4web" group.
To unsubscribe from this group and stop receiving emails from it, send an email to py4web+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/py4web/bef11971-8754-4a78-807c-70164e7703d3n%40googlegroups.com.

Alan Etkin

unread,
Apr 18, 2026, 4:41:25 PMApr 18
to py4web
Thanks, at this point what I'm struggling with are Form and Grid classes. Seems that Auth performs some automatic translation of its internal text, as I managed to implement an app without customizing it.
Reply all
Reply to author
Forward
0 new messages