# HG changeset patch
# User Yuki KODAMA <[email protected]>
# Date 1243187015 -32400
# Node ID f24d52e19d130c5bd5582a166fd5a47b552ca23a
# Parent  e63b33ef3201bc8f5a6763058e314b0672c2f9f5
i18n: change encoding of translated message for command-line

With this changes, TortoiseHg can be shown the help
text correctly ('hgtk help' command).
'agettext' is THG own function, means 'a(scii)gettext'.

diff --git a/hggtk/hgtk.py b/hggtk/hgtk.py
--- a/hggtk/hgtk.py
+++ b/hggtk/hgtk.py
@@ -21,7 +21,7 @@
 import mercurial.ui as _ui
 from mercurial import hg, util, fancyopts, cmdutil, extensions

-from thgutil.i18n import _
+from thgutil.i18n import agettext as _
 from thgutil import hglib, paths, shlib
 from thgutil import version as thgversion

diff --git a/thgutil/i18n.py b/thgutil/i18n.py
--- a/thgutil/i18n.py
+++ b/thgutil/i18n.py
@@ -6,9 +6,23 @@
 of the GNU General Public License, incorporated herein by reference.
 """

-import gettext
+import gettext, sys
 from gettext import gettext as _
 import paths

 gettext.bindtextdomain("tortoisehg", paths.get_locale_path())
 gettext.textdomain("tortoisehg")
+
+def agettext(message):
+    """Translate message and convert to local encoding
+    such as 'ascii' before being returned.
+
+    Only use this if you need to output translated messages
+    to command-line interface (ie: Windows Command Prompt).
+    """
+    try:
+        u = _(message)
+        return u.encode(sys.stdout.encoding, "replace")
+    except LookupError:
+        return message
+

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________
Tortoisehg-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tortoisehg-develop

Reply via email to