CARVIEW |
Select Language
HTTP/2 200
server: nginx
content-type: text/html;charset=utf-8
cache-control: must-revalidate
expires: Fri, 01 Jan 1999 00:00:00 GMT
set-cookie: trac_form_token=570e3d603b64895281e78be3; HttpOnly; Path=/; Secure
set-cookie: trac_session=9de864301738a4ad9790768f; expires=Tue, 21 Oct 2025 09:33:40 GMT; HttpOnly; Path=/; Secure
strict-transport-security: max-age=31536000; includeSubDomains; preload
permissions-policy: interest-cohort=()
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
accept-ranges: bytes
via: 1.1 varnish, 1.1 varnish
date: Wed, 23 Jul 2025 09:33:40 GMT
x-served-by: cache-fra-eddf8230047-FRA, cache-bom-vanm7210027-BOM
x-cache: MISS, MISS
x-cache-hits: 0, 0
x-timer: S1753263221.710115,VS0,VE266
vary: Accept-Encoding
CookBookTemplateTagTranslation – Django
Back to Top
Django
The web framework for perfectionists with deadlines.
Issues
CookBook - Template tags
Easy translation
This creates a new tag pair, {% translate %
} and {% endtranslate %
}
which will translate every string between two backquotes. I made this
because I found the default i18n "trans" tag too bulky.
import re from django.core import template from django.utils import translation register = template.Library() transl = re.compile("`(.*?)`") class TranslateNode(template.Node): def __init__(self, nodelist): self.nodelist = nodelist def render(self, context): output = self.nodelist.render(context) return transl.sub(lambda match: translation.gettext(match.group(1)), output) def do_translate(parser, token): nodelist = parser.parse(('endtranslate',)) parser.delete_first_token() return TranslateNode(nodelist) register.tag('translate', do_translate)
Can you explain the difference between:
{% blocktrans %} asd adlkjfjalkdsfj lksajdfl sdkf jslakdfj asd adlkjfjalkdsfj lksajdfl sdkf jslakdfj asd adlkjfjalkdsfj lksajdfl sdkf jslakdfj {% endblocktrans %}
and your method?
{% translate %} `saddasdasd asd ad asd` `saddasdasd asd ad asd` {% endtranslate %}
Also, your tags are not picked up with make-messages
so you must insert them manually into .po files.
Last modified
19 years ago
Last modified on Apr 6, 2006, 2:27:50 AM
Note:
See TracWiki
for help on using the wiki.
Download in other formats:
Django Links
Learn More
Get Involved
Follow Us
- Hosting by In-kind donors
- Design by Threespot &
© 2005-2025 Django SoftwareFoundation unless otherwise noted. Django is a registered trademark of the Django Software Foundation.