Opened 11 years ago
Last modified 9 years ago
#11338 new enhancement
[Patch] Switch language based on URL prefix
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | normal | Milestone: | undecided |
Component: | i18n | Version: | 1.0.1 |
Severity: | trivial | Keywords: | patch |
Cc: | olemis+trac@…, leho@… | Branch: | |
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description (last modified by )
Hello,
I would like to propose my first patch to Trac. The target is to switch language according to this principle: https://docs.djangoproject.com/en/dev/topics/i18n/translation/#how-django-discovers-language-preference
I worked with Trac version 1.0.1 on a Debian Testing.
I modified the file trac/web/main.py and class RequestDispatcher
method
_get_locale:
def _get_locale(self, req): if has_babel: language_prefix_regexp = re.compile('^/([A-Za-z\-]+)/') match = language_prefix_regexp.match(req.base_path) if req.base_path else None language_prefix = match.groups()[0] if match else None preferred = req.session.get('language') default = self.env.config.get('trac', 'default_language','') negotiated = get_negotiated_locale([language_prefix, preferred, default] + req.languages) self.log.debug("Negotiated locale: %s -> %s", preferred, negotiated) return negotiated
Basically it changes the language if there is a language prefix. Of course it may be a problem for site which doesn't use language prefix but which have an URL similar to a language prefix. So we may need to make that an option (but I don't know yet how to do that)
Attachments (1)
Change History (9)
comment:1 by , 11 years ago
comment:3 by , 11 years ago
Cc: | added |
---|
comment:4 by , 11 years ago
Description: | modified (diff) |
---|
by , 11 years ago
Attachment: | t11338_language_prefix.diff added |
---|
Patch to set language based on URL prefix
comment:5 by , 11 years ago
Ok I created a patch on the current 1.0.2dev changeset. Hope that it is OK !
comment:6 by , 11 years ago
Cc: | added |
---|
comment:7 by , 10 years ago
Keywords: | patch added |
---|
comment:8 by , 9 years ago
Summary: | Switch language based on URL prefix → [Patch] Switch language based on URL prefix |
---|
If possible, would you kindly create a patch as described in TracDev/SubmittingPatches?