changeset 16845:4594729c61ee

help: fix search with `-k` option in non-ASCII locales Keyword search in help (introduced in 497deec204d1 and a17983680f12 by Augie Fackler) tries to translate already translated strings, which results in Unicode errors in gettext when non-ASCII locale is used. Also command descriptions should be translated before searching there (thanks to FUJIWARA Katsunori for pointing this out and actual fix), (issue3482).
author Nikolaj Sjujskij <sterkrig@myopera.com>
date Mon, 04 Jun 2012 10:45:56 +0400
parents 61f3ca8e4d39
children e38ed2ceabe7
files mercurial/help.py
diffstat 1 files changed, 6 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/help.py	Sun Jun 03 19:35:45 2012 +0200
+++ b/mercurial/help.py	Mon Jun 04 10:45:56 2012 +0400
@@ -70,7 +70,7 @@
     """
     kw = encoding.lower(kw)
     def lowercontains(container):
-        return kw in encoding.lower(_(container))
+        return kw in encoding.lower(container)  # translated in helptable
     results = {'topics': [],
                'commands': [],
                'extensions': [],
@@ -89,9 +89,10 @@
             summary = entry[2]
         else:
             summary = ''
-        docs = getattr(entry[0], '__doc__', None) or ''
+        # translate docs *before* searching there
+        docs = _(getattr(entry[0], '__doc__', None)) or ''
         if kw in cmd or lowercontains(summary) or lowercontains(docs):
-            doclines = _(docs).splitlines()
+            doclines = docs.splitlines()
             if doclines:
                 summary = doclines[0]
             cmdname = cmd.split('|')[0].lstrip('^')
@@ -102,7 +103,8 @@
         # extensions.load ignores the UI argument
         mod = extensions.load(None, name, '')
         if lowercontains(name) or lowercontains(docs):
-            results['extensions'].append((name, _(docs).splitlines()[0]))
+            # extension docs are already translated
+            results['extensions'].append((name, docs.splitlines()[0]))
         for cmd, entry in getattr(mod, 'cmdtable', {}).iteritems():
             if kw in cmd or (len(entry) > 2 and lowercontains(entry[2])):
                 cmdname = cmd.split('|')[0].lstrip('^')