Edgewall Software

Ticket #9439: 9493-has_babel-False.2.patch

File 9493-has_babel-False.2.patch, 2.5 KB (added by cboos, 20 months ago)

Polished version

  • trac/util/translation.py

    # 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 b try: 
    341341         
    342342    has_babel = True 
    343343 
     344    try: 
     345        locales = pkg_resources.resource_listdir('trac', 'locale') 
     346        # TODO: (optimization) early extraction of all locales 
     347    except pkg_resources.ExtractionError: 
     348        pass # delay extraction 
     349    except Exception: 
     350        has_babel = False # No locale data in egg 
     351 
    344352except ImportError: # fall back on 0.11 behavior, i18n functions are no-ops 
     353    has_babel = None 
     354 
     355if not has_babel: 
    345356    gettext = _ = gettext_noop 
    346357    dgettext = dgettext_noop 
    347358    ngettext = ngettext_noop 
  • trac/web/chrome.py

    diff -r 4893f3183519 trac/web/chrome.py
    a b from trac.util.text import pretty_size,  
    4747                           javascript_quote, exception_to_unicode 
    4848from trac.util.datefmt import pretty_timedelta, format_datetime, format_date, \ 
    4949                              format_time, from_utimestamp, http_date, utc 
    50 from trac.util.translation import _ 
     50from trac.util.translation import _, has_babel 
    5151from trac.web.api import IRequestHandler, ITemplateStreamFilter, HTTPNotFound 
    5252from trac.web.href import Href 
    5353from trac.wiki import IWikiSyntaxProvider 
    class Chrome(Component): 
    374374    def get_system_info(self): 
    375375        import genshi 
    376376        yield 'Genshi', get_pkginfo(genshi).get('version') 
    377         try: 
     377        if has_babel is not None: 
    378378            import babel 
    379         except ImportError: 
    380             babel = None 
    381         if babel is not None: 
    382             yield 'Babel', get_pkginfo(babel).get('version') 
     379            babel_info = get_pkginfo(babel).get('version') 
     380            if has_babel is False:  
     381                babel_info += " (Babel was installed after Trac, " \ 
     382                    "no translations are available)" # Note: no i18n on purpose 
     383                self.log.warning("Babel: version %s", babel_info) 
     384            yield 'Babel', babel_info 
    383385 
    384386    # IEnvironmentSetupParticipant methods 
    385387