Ticket #1363 (closed defect: fixed)
PATCH: i18n.kidutils.translate_all: tail translation and whitespace handling
| Reported by: | cvogler | Owned by: | anonymous |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.0.x bugfix |
| Component: | TurboGears | Version: | 1.0 |
| Severity: | normal | Keywords: | |
| Cc: |
Description
Using the lang attribute in HTML tags to translate strings selectively misses the tails of HTML elements. Consider the following match template, as per the TG documentation and book:
<?python
from turbogears.i18n import translate
?>
<translate xmlns:py="http://purl.org/kid/ns#" py:match="item.attrib.has_key('lang')"
py:replace="translate(item)"/>
Then not everything is translated in this snippet below:
<p lang="">This is translated. <a href="http://www.google.com">So is this.</a> But this is not.</p>
The reason is that translate_all() in i18n.kidutils translates only the text of the elements, when it should translate both the text and the tails.
In addition, translate_all() discards leading and trailing whitespaces of the text, which leads to run-on sentences in the above example (spaces between the periods go missing).
I propose the attached patch to fix both issues.
Attachments
Change History
Note: See
TracTickets for help on using
tickets.
