Skip to content

Commit 7614ca0

Browse files
author
Alexander Smishlajev
committed
TranslationService definitions moved to separate module;
global variable translationService is obsolecent: it is not thread-safe, we must use client.translator (or 'i18n' variable in template contexts) instead
1 parent 2c7572e commit 7614ca0

File tree

1 file changed

+5
-36
lines changed

1 file changed

+5
-36
lines changed

roundup/cgi/templating.py

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -41,44 +41,13 @@
4141
from roundup.cgi.PageTemplates import PageTemplate, GlobalTranslationService
4242
from roundup.cgi.PageTemplates.Expressions import getEngine
4343
from roundup.cgi.TAL import TALInterpreter
44-
from roundup.cgi import ZTUtils
44+
from roundup.cgi import TranslationService, ZTUtils
4545

4646
### i18n services
47-
48-
class StaticTranslationService:
49-
50-
"""Translation service for application default language
51-
52-
This service uses "static" translation, with single domain
53-
and target language, initialized from OS environment when
54-
roundup.i18n is loaded.
55-
56-
'domain' and 'target_language' parameters to 'translate()'
57-
are ignored.
58-
59-
Returned strings are always utf8-encoded.
60-
61-
"""
62-
63-
OUTPUT_ENCODING = "utf-8"
64-
65-
def translate(self, domain, msgid, mapping=None,
66-
context=None, target_language=None, default=None
67-
):
68-
_msg = self.gettext(msgid)
69-
#print ("TRANSLATE", msgid, _msg, mapping, context)
70-
_msg = TALInterpreter.interpolate(_msg, mapping)
71-
return _msg
72-
73-
def gettext(self, msgid):
74-
return i18n.ugettext(msgid).encode(self.OUTPUT_ENCODING)
75-
76-
def ngettext(self, singular, plural, number):
77-
return i18n.ungettext(singular, plural, number).encode(
78-
self.OUTPUT_ENCODING)
79-
80-
translationService = StaticTranslationService()
81-
47+
# this global translation service is not thread-safe.
48+
# it is left here for backward compatibility
49+
# until all Web UI translations are done via client.translator object
50+
translationService = TranslationService.get_translation()
8251
GlobalTranslationService.setGlobalTranslationService(translationService)
8352

8453
### templating

0 commit comments

Comments
 (0)