Opened 9 years ago

Closed 9 years ago

#667 closed enhancement (fixed)

Use lazy_pass_to_ugettext for forms

Reported by: Elrond Owned by: aditi
Priority: minor Milestone:
Component: programming Keywords: bitesized sprint
Cc: Christopher Allan Webber Parent Tickets:

Description

(This might be a dupes, but I could not find it.)

To translate forms, we currently go the following route:

  • Mark strings as translatable (only mark, do nothing else)
  • wtforms keeps them for us
  • Our field rendering tools render the complete field nearly completely ba hand to be able to translate it there. Using standard translation tools there.

This works, mostly. It does not work to translate elements of a select box, for example a title like "- Select Collection -". Because we only mark it, but we're not using our translation tools in the rendering. We could go for rendering that part by hand also.

BUT: wtforms recommends something else:

  • Use lazy_pass_to_ugettext() to mark and create a autotranslating object. This feels like a string, but really becomes a translated string, when it is forced to a real string.
  • wtforms keeps this thing as a normal object around.
  • When rendering it, wtforms will force it to a string as late as possible, so that translations can take effect.

So the first idea is to mark strings using lazy_pass_to_ugettext() and just disable the translation in our rendering tools (just remove the _()!) and see, how it works out.

Old in any forms.py:

from mediagoblin.tools.translate import fake_ugettext_passthrough as _

New:

from mediagoblin.tools.translate import lazy_pass_to_ugettext as _

Subtickets

Attachments (1)

0001-Fix-bug-667-Use-lazy_pass_to_ugettext-for-forms.patch (8.4 KB) - added by aditi 9 years ago.
updated patch

Download all attachments as: .zip

Change History (6)

comment:1 Changed 9 years ago by Elrond

Keywords: sprint added

I really think, this is sprintable.

comment:2 Changed 9 years ago by aditi

Owner: set to aditi
Status: newassigned

comment:3 Changed 9 years ago by aditi

I have updated the patch after making changes in wtforms. I still have doubt why we do not intend to update pass_to_ugettext to lazy_pass_to_ugettext in every python module having translatable string.

Changed 9 years ago by aditi

updated patch

comment:4 Changed 9 years ago by Christopher Allan Webber

Heya aditi,

I merged your patch! The issues I was discussing on IRC were not with your patch itself, it was with the library we were using, so that's fixed now. You did a great job implementing things as described on the ticket.

I did revert the other lazy calls to ugettext that didn't have to do with forms; basically, if it's okay to immmediately get the translation at the part of the code you're in it's fine to not use the lazy objects... not a great explaination, sorry, it's late at night, happy to explain more on IRC tomorrow :)

Good work though! This also had the benefit of leading me to find that our lazy_*gettext calls weren't working as they were expected, so those are all fixed now!

comment:5 Changed 9 years ago by Christopher Allan Webber

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.