Internationalization and localization (Ticket #65)

2 views
Skip to first unread message

nesh

unread,
Jul 22, 2005, 4:39:47 PM7/22/05
to django-d...@googlegroups.com
Adding ability to translate django messages into another language using
gettext.

Posted example implementation as a comment for Ticket #65.

I put gettext initialization in __init__ of ModPythonRequest (R291) or
is the better place for that? Added new local var locale for holding
translations. Probably I'll add another (in HttpRequest?) for holding
negotated/user selected locale from request.

p.s. sorry on my bad,bad,bad english :)

Nebojša Đorđević

unread,
Jul 23, 2005, 6:32:05 AM7/23/05
to django-d...@googlegroups.com
I moved localization into separate class.

Where I can upload/attach this? In ticket or I can post here?

To enable localization support simply include following in *Request
class __init__ method:

self.locale = locale.Locale(self)

to change locale use: request.locale = 'locale'
to get current locale use: request.locale - is there any way to pass
this to template?

For template.py change regexp to:

# gettext tags
GETTEXT_START = '_("'
GETTEXT_END = '")'

tag_re = re.compile('(%s.*?%s|%s.*?%s|%s.*?%s)' % \
(re.escape(BLOCK_TAG_START),
re.escape(BLOCK_TAG_END),
re.escape(VARIABLE_TAG_START),
re.escape(VARIABLE_TAG_END),
re.escape(GETTEXT_START),
re.escape(GETTEXT_END)))

and in create_token add before last else:
# gettext support
elif token_string.startswith(GETTEXT_START):
return Token(TOKEN_TEXT,
_(token_string[len(GETTEXT_START):-len(GETTEXT_END)].strip()))

this enable use _("") as a gettext tag in html templates

I localized admin interface and admin templates and all works great.
Probably I'll add some type of admin interface for working with
translation files later (when form tutorial comes up :) ).

--
Đorđević Nebojša
Studio Quattro - Niš - SCG
Reply all
Reply to author
Forward
0 new messages