Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.0, 2.0.1, and 2.0.2

stable i18n: support for message contexts

Adds support for contextualizing messages to avoid ambiguities,
as described in

http://www.gnu.org/software/gettext/manual/gettext.html#Contexts

The "_" functions are enhanced to get an additional context parameter;
for instance, "_('All', 'changesets')" and "_('All', 'files')"
would appear as two separate strings for translation, together
with the context marker. If no contextualized message is found,
we fall back to the old behavior, to reuse existing translations.

Since Python gettext currently doesn't support pgettext
(see http://bugs.python.org/issue2504 ), the messages are
explicitely concatenated with the '\004' context separator
before lookup.

Changeset 07d24580b59c

Parent 7a3ea5f7890e

by Wagner Bruna

Changes to 3 files · Browse files at 07d24580b59c Showing diff from parent 7a3ea5f7890e Diff from another changeset...

Change 1 of 1 Show Entire File setup.py Stacked
 
106
107
108
 
109
110
111
 
106
107
108
109
110
111
112
@@ -106,6 +106,7 @@
  '--msgid-bugs-address', '<thg-devel@googlegroups.com>',   '--copyright-holder', thgcopyright,   '--from-code', 'ISO-8859-1', + '--keyword=_:1,2c,2t',   '--add-comments=i18n:',   '-d', '.',   '-o', potfile,
 
8
9
10
11
12
 
 
13
14
15
16
 
 
17
18
19
20
 
 
 
8
9
10
 
 
11
12
13
14
 
 
15
16
17
18
 
 
19
20
@@ -8,13 +8,13 @@
 from tortoisehg.util.i18n import _ as _gettext  from tortoisehg.util.i18n import agettext   -def _(message): - return unicode(_gettext(message), 'utf-8') +def _(message, context=''): + return unicode(_gettext(message, context), 'utf-8')    class localgettext(object): - def _(self, message): - return agettext(message) + def _(self, message, context=''): + return agettext(message, context='')    class keepgettext(object): - def _(self, message): - return {'id': message, 'str': _(message)} + def _(self, message, context=''): + return {'id': message, 'str': _(message, context)}
 
52
53
54
55
 
 
 
 
 
56
57
58
 
59
60
61
 
64
65
66
67
 
68
69
70
71
72
73
74
 
 
 
52
53
54
 
55
56
57
58
59
60
61
 
62
63
64
65
 
68
69
70
 
71
72
73
74
75
76
 
 
77
78
@@ -52,10 +52,14 @@
  langs.append('en') # means null translation   return sorted(langs)   -def _(message): +def _(message, context=''): + if context: + tmsg = t.gettext(context + '\004' + message) + if '\004' not in tmsg: + return tmsg   return t.gettext(message)   -def agettext(message): +def agettext(message, context=''):   """Translate message and convert to local encoding   such as 'ascii' before being returned.   @@ -64,11 +68,11 @@
  """   try:   from tortoisehg.util import hglib - u = _(message) + u = _(message, context)   return hglib.fromutf(u)   except (LookupError, UnicodeEncodeError):   return message    class keepgettext(object): - def _(self, message): - return {'id': message, 'str': _(message)} + def _(self, message, context=''): + return {'id': message, 'str': _(message, context)}