Edgewall Software

Ticket #9439: 9439-notify-missing-r1052.patch

File 9439-notify-missing-r1052.patch, 4.8 KB (added by rblank, 20 months ago)

Handle missing locales and notify user and admin.

  • trac/prefs/templates/prefs_language.html

    diff --git a/trac/prefs/templates/prefs_language.html b/trac/prefs/templates/prefs_language.html
    a b  
    33    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
    44<html xmlns="http://www.w3.org/1999/xhtml" 
    55      xmlns:py="http://genshi.edgewall.org/" 
    6       xmlns:xi="http://www.w3.org/2001/XInclude"> 
     6      xmlns:xi="http://www.w3.org/2001/XInclude" 
     7      xmlns:i18n="http://genshi.edgewall.org/i18n"> 
    78  <xi:include href="prefs.html" /> 
    89  <head> 
    910    <title>Language</title> 
     
    1213 
    1314    <div class="field" py:with="session_language = settings.session.get('language')"> 
    1415      <label>Language: 
    15       <select name="language"> 
    16         <option value="">default language</option> 
    17         <option py:for="locale, language in languages" 
    18                 selected="${session_language == locale or None}" 
    19                 value="$locale">$language</option> 
    20       </select></label> 
     16        <select name="language"> 
     17          <option value="">default language</option> 
     18          <option py:for="locale, language in languages" 
     19                  selected="${session_language == locale or None}" 
     20                  value="$locale">$language</option> 
     21        </select> 
     22      </label> 
    2123      <p class="hint">Configuring your language will result in all text 
    2224      displayed on this site to use your language instead of that of the 
    2325      server.</p> 
    2426 
    2527      <p class="hint">The 'default language' option uses the browser's 
    2628        language negotiation feature to select the appropriate language.</p> 
     29 
     30      <p py:if="not languages" class="hint"> 
     31        <strong>Note:</strong> Translations are currently unavailable. 
     32        <py:choose> 
     33          <py:when test="'TRAC_ADMIN' in req.perm"><i18n:msg> 
     34            Trac has been localized to more than a dozen of languages but in order 
     35            to be able to use them, the <a href="http://babel.edgewall.org">Babel</a> 
     36            package needs to be present when installing Trac. See 
     37            <a href="${href.wiki('TracInstall')}">TracInstall</a> for details. 
     38          </i18n:msg></py:when> 
     39          <py:otherwise><i18n:msg> 
     40            Please contact your 
     41            <a py:strip="not project.admin" href="mailto:${project.admin}">Trac administrator</a> 
     42            to enable existing translations. 
     43          </i18n:msg></py:otherwise> 
     44        </py:choose> 
     45      </p> 
    2746    </div> 
    2847 
    2948  </body> 
  • trac/util/translation.py

    diff --git a/trac/util/translation.py b/trac/util/translation.py
    a b try: 
    141141        def activate(self, locale, env_path=None): 
    142142            try: 
    143143                locale_dir = pkg_resources.resource_filename('trac', 'locale') 
    144             except pkg_resources.ExtractionError: 
    145                 return # delay extraction 
    146             except KeyError: 
    147                 return # No locale data in egg 
     144            except Exception: 
     145                return 
    148146            t = Translations.load(locale_dir, locale or 'en_US') 
    149147            if not t or t.__class__ is NullTranslations: 
    150148                t = self._null_translations 
    try: 
    329327        """Return a list of locale identifiers of the locales for which 
    330328        translations are available. 
    331329        """ 
    332         return [dirname for dirname 
    333                 in pkg_resources.resource_listdir('trac', 'locale') 
    334                 if '.' not in dirname] 
     330        try: 
     331            return [dirname for dirname 
     332                    in pkg_resources.resource_listdir('trac', 'locale') 
     333                    if '.' not in dirname] 
     334        except Exception: 
     335            return [] 
    335336 
    336337    def get_negotiated_locale(preferred_locales): 
    337338        def normalize(locale_ids): 
  • trac/web/chrome.py

    diff --git a/trac/web/chrome.py b/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 _, get_available_locales 
    5151from trac.web.api import IRequestHandler, ITemplateStreamFilter, HTTPNotFound 
    5252from trac.web.href import Href 
    5353from trac.wiki import IWikiSyntaxProvider 
    class Chrome(Component): 
    379379        except ImportError: 
    380380            babel = None 
    381381        if babel is not None: 
    382             yield 'Babel', get_pkginfo(babel).get('version') 
     382            info = get_pkginfo(babel).get('version') 
     383            if not get_available_locales(): 
     384                info += " (translations unavailable)" # No i18n on purpose 
     385            yield 'Babel', info 
    383386 
    384387    # IEnvironmentSetupParticipant methods 
    385388