[PATCH] alias: fixes exception when displaying translated help text

Yuya Nishihara yuya at tcha.org
Thu Feb 25 09:48:19 CST 2010


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1267112630 -32400
# Branch stable
# Node ID bb526a5534650c296d72bc78852197eb7f4a2e61
# Parent  bae9bb09166b934ef78d48e379914ae6e70af627
alias: fixes exception when displaying translated help text

docstring of aliased command can contain non-ASCII characters
since 6e8a16dd3e30, so we cannot do gettext() against it.

This also changed the docstring of aliased command to be fully
translated by dispatch.cmdalias.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1541,7 +1541,9 @@ def help_(ui, name=None, with_version=Fa
             ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:]))
 
         # description
-        doc = gettext(entry[0].__doc__)
+        doc = entry[0].__doc__
+        if not hasattr(entry[0], 'badalias'):  # cmdalias: already translated
+            doc = gettext(doc)
         if not doc:
             doc = _("(no help text available)")
         if ui.quiet:
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -5,7 +5,7 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
-from i18n import _
+from i18n import _, gettext
 import os, sys, atexit, signal, pdb, socket, errno, shlex, time
 import util, commands, hg, fancyopts, extensions, hook, error
 import cmdutil, encoding
@@ -209,7 +209,7 @@ class cmdalias(object):
                 # drop prefix in old-style help lines so hg shows the alias
                 self.help = self.help[4 + len(cmd):]
             self.__doc__ = _("alias for: hg %s\n\n%s") \
-                               % (definition, self.fn.__doc__)
+                               % (definition, gettext(self.fn.__doc__))
 
         except error.UnknownCommand:
             def fn(ui, *args):


More information about the Mercurial-devel mailing list