Skip to content

Commit 838bec6

Browse files
author
Alexander Smishlajev
committed
HTMLInputMixin provides translation interface for all its hiers...
HTMLClass, HTMLItem, HTMLProperty and their child classes. all these classes call self._() for string translation.
1 parent a38fcec commit 838bec6

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

roundup/cgi/templating.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,18 @@ def __init__(self):
454454
self.input = input_xhtml
455455
else:
456456
self.input = input_html4
457+
# self._context is used for translations.
458+
# will be initialized by the first call to .gettext()
459+
self._context = None
460+
461+
def gettext(self, msgid):
462+
"""Return the localized translation of msgid"""
463+
if self._context is None:
464+
self._context = context(self._client)
465+
return translationService.translate(domain="roundup",
466+
msgid=msgid, context=self._context)
467+
468+
_ = gettext
457469

458470
class HTMLClass(HTMLInputMixin, HTMLPermissions):
459471
''' Accesses through a class (either through *class* or *db.<classname>*)
@@ -766,12 +778,12 @@ def history(self, direction='descending', dre=re.compile('^\d+$')):
766778

767779
l = ['<table class="history">'
768780
'<tr><th colspan="4" class="header">',
769-
_('History'),
781+
self._('History'),
770782
'</th></tr><tr>',
771-
_('<th>Date</th>'),
772-
_('<th>User</th>'),
773-
_('<th>Action</th>'),
774-
_('<th>Args</th>'),
783+
self._('<th>Date</th>'),
784+
self._('<th>User</th>'),
785+
self._('<th>Action</th>'),
786+
self._('<th>Args</th>'),
775787
'</tr>']
776788
current = {}
777789
comments = {}
@@ -832,9 +844,10 @@ def history(self, direction='descending', dre=re.compile('^\d+$')):
832844
prop = None
833845
if prop is None:
834846
# property no longer exists
835-
comments['no_exist'] = _(
847+
comments['no_exist'] = self._(
836848
"<em>The indicated property no longer exists</em>")
837-
cell.append('<em>%s: %s</em>\n'%(k, str(args[k])))
849+
cell.append(self._('<em>%s: %s</em>\n')
850+
% (k, str(args[k])))
838851
continue
839852

840853
if args[k] and (isinstance(prop, hyperdb.Multilink) or
@@ -845,7 +858,7 @@ def history(self, direction='descending', dre=re.compile('^\d+$')):
845858
linkcl = self._db.getclass(classname)
846859
except KeyError:
847860
labelprop = None
848-
comments[classname] = _(
861+
comments[classname] = self._(
849862
"The linked class %(classname)s no longer exists"
850863
) % locals()
851864
labelprop = linkcl.labelprop(1)
@@ -878,7 +891,7 @@ def history(self, direction='descending', dre=re.compile('^\d+$')):
878891
labelprop != 'id':
879892
label = linkcl.get(linkid, labelprop)
880893
except IndexError:
881-
comments['no_link'] = _(
894+
comments['no_link'] = self._(
882895
"<strike>The linked node"
883896
" no longer exists</strike>")
884897
subml.append('<strike>%s</strike>'%label)
@@ -899,7 +912,7 @@ def history(self, direction='descending', dre=re.compile('^\d+$')):
899912
try:
900913
label = linkcl.get(args[k], labelprop)
901914
except IndexError:
902-
comments['no_link'] = _(
915+
comments['no_link'] = self._(
903916
"<strike>The linked node"
904917
" no longer exists</strike>")
905918
cell.append(' <strike>%s</strike>,\n'%label)
@@ -959,7 +972,8 @@ def history(self, direction='descending', dre=re.compile('^\d+$')):
959972
arg_s = '<br />'.join(cell)
960973
else:
961974
# unkown event!!
962-
comments['unknown'] = _("<strong><em>This event is not handled"
975+
comments['unknown'] = self._(
976+
"<strong><em>This event is not handled"
963977
" by the history display!</em></strong>")
964978
arg_s = '<strong><em>' + str(args) + '</em></strong>'
965979
date_s = date_s.replace(' ', '&nbsp;')
@@ -970,7 +984,8 @@ def history(self, direction='descending', dre=re.compile('^\d+$')):
970984
l.append('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>'%(
971985
date_s, user, action, arg_s))
972986
if comments:
973-
l.append(_('<tr><td colspan=4><strong>Note:</strong></td></tr>'))
987+
l.append(self._(
988+
'<tr><td colspan=4><strong>Note:</strong></td></tr>'))
974989
for entry in comments.values():
975990
l.append('<tr><td colspan=4>%s</td></tr>'%entry)
976991
l.append('</table>')
@@ -1251,7 +1266,7 @@ def plain(self):
12511266

12521267
if self._value is None:
12531268
return ''
1254-
return _('*encrypted*')
1269+
return self._('*encrypted*')
12551270

12561271
def field(self, size = 30):
12571272
''' Render a form edit field for the property.
@@ -1573,7 +1588,7 @@ def menu(self, size=None, height=None, showid=0, additional=[],
15731588
s = ''
15741589
if value is None:
15751590
s = 'selected="selected" '
1576-
l.append(_('<option %svalue="-1">- no selection -</option>')%s)
1591+
l.append(self._('<option %svalue="-1">- no selection -</option>')%s)
15771592
if linkcl.getprops().has_key('order'):
15781593
sort_on = ('+', 'order')
15791594
else:

0 commit comments

Comments
 (0)