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

hgtk 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 b578229a8af5

Parent 8db3637d6fe2

by Wagner Bruna

Changes to one file · Browse files at b578229a8af5 Showing diff from parent 8db3637d6fe2 Diff from another changeset...

 
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)}