# HG changeset patch # User Nikolaj Sjujskij # Date 1338792356 -14400 # Node ID 4594729c61ee23d500674257051dcd7dcd204c08 # Parent 61f3ca8e4d39fd401b358856ad132419d827c5e2 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). diff -r 61f3ca8e4d39 -r 4594729c61ee mercurial/help.py --- 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('^')