Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.8, 0.8.1, and 0.8.2

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'.

Changeset 92f839272b73

Parent e63b33ef3201

by Yuki KODAMA

Changes to 2 files · Browse files at 92f839272b73 Showing diff from parent e63b33ef3201 Diff from another changeset...

Change 1 of 1 Show Entire File hggtk/​hgtk.py Stacked
 
21
22
23
24
 
25
26
27
 
21
22
23
 
24
25
26
27
@@ -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  
Change 1 of 1 Show Entire File thgutil/​i18n.py Stacked
 
6
7
8
9
 
10
11
12
13
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
7
8
 
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
@@ -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 +