Skip to content

Commit e9fd5de

Browse files
author
Alexander Smishlajev
committed
StaticTranslationService got methods gettext() and ngettext()...
...to be usable instead of 'i18n' module; added module-level variable 'translationService'; DateHTMLProperty and IntervalHTMLProperty apply templates translation service to their values
1 parent 814bfb8 commit e9fd5de

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

roundup/cgi/templating.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,21 @@ class StaticTranslationService:
6161
def translate(self, domain, msgid, mapping=None,
6262
context=None, target_language=None, default=None
6363
):
64-
_msg = i18n.ugettext(msgid).encode(self.OUTPUT_ENCODING)
64+
_msg = self.gettext(msgid)
6565
#print ("TRANSLATE", msgid, _msg, mapping, context)
6666
_msg = TALInterpreter.interpolate(_msg, mapping)
6767
return _msg
6868

69-
GlobalTranslationService.setGlobalTranslationService(
70-
StaticTranslationService())
69+
def gettext(self, msgid):
70+
return i18n.ugettext(msgid).encode(self.OUTPUT_ENCODING)
71+
72+
def ngettext(self, singular, plural, number):
73+
return i18n.ungettext(singular, plural, number).encode(
74+
self.OUTPUT_ENCODING)
75+
76+
translationService = StaticTranslationService()
77+
78+
GlobalTranslationService.setGlobalTranslationService(translationService)
7179

7280
### templating
7381

@@ -1311,6 +1319,8 @@ def __init__(self, client, classname, nodeid, prop, name, value,
13111319
anonymous=0, offset=None):
13121320
HTMLProperty.__init__(self, client, classname, nodeid, prop, name,
13131321
value, anonymous=anonymous)
1322+
if self._value:
1323+
self._value.setTranslator(translationService)
13141324
self._offset = offset
13151325

13161326
def plain(self):
@@ -1397,6 +1407,13 @@ def local(self, offset):
13971407
self._prop, self._formname, self._value, offset=offset)
13981408

13991409
class IntervalHTMLProperty(HTMLProperty):
1410+
def __init__(self, client, classname, nodeid, prop, name, value,
1411+
anonymous=0):
1412+
HTMLProperty.__init__(self, client, classname, nodeid, prop,
1413+
name, value, anonymous)
1414+
if self._value:
1415+
self._value.setTranslator(translationService)
1416+
14001417
def plain(self):
14011418
''' Render a "plain" representation of the property
14021419
'''

0 commit comments

Comments
 (0)