# HG changeset patch
# User Christian Boos <cboos@neuf.fr>
# Date 1285878280 -7200
# Branch 0.12-stable
# Node ID 9ae5065f71cf88e63e27388d38b05c1b80e874f0
# Parent 4893f31835196bb97bab595b2dffc4d67eebea8d
0.12.1dev: add an explicit warning in the log and in the About page when Babel was installed after Trac and no catalogs are available.

Related to #9439.

diff -r 4893f3183519 trac/util/translation.py
--- a/trac/util/translation.py	Thu Sep 30 19:57:23 2010 +0000
+++ b/trac/util/translation.py	Fri Oct 01 07:19:58 2010 +0200
@@ -341,7 +341,18 @@ try:
         
     has_babel = True
 
+    try:
+        locales = pkg_resources.resource_listdir('trac', 'locale')
+        # TODO: (optimization) early extraction of all locales
+    except pkg_resources.ExtractionError:
+        pass # delay extraction
+    except Exception:
+        has_babel = False # No locale data in egg
+
 except ImportError: # fall back on 0.11 behavior, i18n functions are no-ops
+    has_babel = None
+
+if not has_babel:
     gettext = _ = gettext_noop
     dgettext = dgettext_noop
     ngettext = ngettext_noop
diff -r 4893f3183519 trac/web/chrome.py
--- a/trac/web/chrome.py	Thu Sep 30 19:57:23 2010 +0000
+++ b/trac/web/chrome.py	Fri Oct 01 07:19:58 2010 +0200
@@ -47,7 +47,7 @@ from trac.util.text import pretty_size, 
                            javascript_quote, exception_to_unicode
 from trac.util.datefmt import pretty_timedelta, format_datetime, format_date, \
                               format_time, from_utimestamp, http_date, utc
-from trac.util.translation import _
+from trac.util.translation import _, has_babel
 from trac.web.api import IRequestHandler, ITemplateStreamFilter, HTTPNotFound
 from trac.web.href import Href
 from trac.wiki import IWikiSyntaxProvider
@@ -374,12 +374,14 @@ class Chrome(Component):
     def get_system_info(self):
         import genshi
         yield 'Genshi', get_pkginfo(genshi).get('version')
-        try:
+        if has_babel is not None:
             import babel
-        except ImportError:
-            babel = None
-        if babel is not None:
-            yield 'Babel', get_pkginfo(babel).get('version')
+            babel_info = get_pkginfo(babel).get('version')
+            if has_babel is False: 
+                babel_info += " (Babel was installed after Trac, " \
+                    "no translations are available)" # Note: no i18n on purpose
+                self.log.warning("Babel: version %s", babel_info)
+            yield 'Babel', babel_info
 
     # IEnvironmentSetupParticipant methods
 

