- Bump PORTREVISION

Current Trac port requires no Babel (devel/py-babel), but it behaves
differently when Babel is present and when it is not present in the
system. Most notably, when one installs Trac 0.12 without installed
Babel and installs Babel later, Trac will refuse to work with the error
"KeyError: trac/locale".

PR:             ports/150483
Submitted by:   Eygene Ryabinkin <rea-fbsd@codelabs.ru>
Approved by:    maintainer timeout (clsung ; 30 days)
This commit is contained in:
Philip M. Gollucci 2010-10-12 06:20:30 +00:00
parent 608b7cb7fc
commit 569b879858
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=262872
3 changed files with 96 additions and 1 deletions

View file

@ -7,6 +7,7 @@
PORTNAME= trac
PORTVERSION= 0.12
PORTREVISION= 1
CATEGORIES= www devel python
MASTER_SITES= http://ftp.edgewall.com/pub/trac/ \
ftp://ftp.edgewall.com/pub/trac/
@ -15,7 +16,8 @@ DISTNAME= Trac-${PORTVERSION}
MAINTAINER= clsung@FreeBSD.org
COMMENT= An enhanced wiki and issue tracking system for software projects
BUILD_DEPENDS= ${PYTHON_PKGNAMEPREFIX}Genshi>=0.5:${PORTSDIR}/textproc/py-genshi
BUILD_DEPENDS= ${PYTHON_PKGNAMEPREFIX}Genshi>=0.5:${PORTSDIR}/textproc/py-genshi \
${PYTHON_PKGNAMEPREFIX}Babel>=0.9:${PORTSDIR}/devel/py-babel
RUN_DEPENDS= ${BUILD_DEPENDS}
OPTIONS= SILVERCITY "Use Silvercity for syntax highlighting" On \

View file

@ -0,0 +1,35 @@
--- ./trac/util/translation.py.orig 2010-06-13 20:36:24.000000000 +0000
+++ ./trac/util/translation.py 2010-10-12 06:14:47.021523796 +0000
@@ -101,8 +101,10 @@
def dungettext(self, domain, singular, plural, num):
return self.ungettext(singular, plural, num)
+has_babel = False
try:
+ from babel import Locale
from babel.support import LazyProxy, Translations
class TranslationsProxy(object):
@@ -329,6 +331,14 @@
in pkg_resources.resource_listdir('trac', 'locale')
if '.' not in dirname]
+ def get_negotiated_locale(preferred_locales):
+ def normalize(locale_ids):
+ return [id.replace('_', '-') for id in locale_ids if id]
+ return Locale.negotiate(normalize(preferred_locales),
+ normalize(get_available_locales()), sep='-')
+
+ has_babel = True
+
except ImportError: # fall back on 0.11 behavior, i18n functions are no-ops
gettext = _ = gettext_noop
dgettext = dgettext_noop
@@ -358,3 +368,6 @@
def get_available_locales():
return []
+
+ def get_negotiated_locale(preferred=None, default=None):
+ return None

View file

@ -0,0 +1,58 @@
--- ./trac/web/main.py.orig 2010-06-13 20:36:24.000000000 +0000
+++ ./trac/web/main.py 2010-10-12 06:14:47.022524485 +0000
@@ -26,10 +26,6 @@
from pprint import pformat, pprint
import sys
-try:
- from babel import Locale
-except ImportError:
- Locale = None
from genshi.core import Markup
from genshi.builder import Fragment, tag
from genshi.output import DocType
@@ -48,7 +44,8 @@
from trac.util.concurrency import threading
from trac.util.datefmt import format_datetime, http_date, localtz, timezone
from trac.util.text import exception_to_unicode, shorten_line, to_unicode
-from trac.util.translation import safefmt, tag_, _
+from trac.util.translation import _, get_negotiated_locale, has_babel, \
+ safefmt, tag_
from trac.web.api import *
from trac.web.chrome import Chrome
from trac.web.clearsilver import HDFWrapper
@@ -150,6 +147,11 @@
default_timezone = Option('trac', 'default_timezone', '',
"""The default timezone to use""")
+ default_language = Option('trac', 'default_language', '',
+ """The preferred language to use if no user preference has been set.
+ (''since 0.12.1'')
+ """)
+
# Public API
def authenticate(self, req):
@@ -302,16 +304,12 @@
return FakeSession()
def _get_locale(self, req):
- if Locale:
- available = [locale_id.replace('_', '-') for locale_id in
- translation.get_available_locales()]
-
- preferred = req.session.get('language', req.languages)
- if not isinstance(preferred, list):
- preferred = [preferred]
- negotiated = Locale.negotiate(preferred, available, sep='-')
- self.log.debug("Negotiated locale: %s -> %s",
- preferred, negotiated)
+ if has_babel:
+ preferred = req.session.get('language')
+ default = self.env.config.get('trac', 'default_language', '')
+ negotiated = get_negotiated_locale([preferred, default] +
+ req.languages)
+ self.log.debug("Negotiated locale: %s -> %s", preferred, negotiated)
return negotiated
def _get_timezone(self, req):