1414# Modifications for Roundup:
1515# 1. implemented ustr as str
1616# 2. make imports use roundup.cgi
17+ # 3. added StaticTranslationService
1718"""Global Translation Service for providing I18n to Page Templates.
1819
19- $Id: GlobalTranslationService.py,v 1.2 2004-05-21 06: 13:39 richard Exp $
20+ $Id: GlobalTranslationService.py,v 1.3 2004-05-23 13:05:43 a1s Exp $
2021"""
2122
2223import re
2324
24- from roundup . i18n import _
25+ from roundup import i18n
2526
2627from roundup .cgi .TAL .TALDefs import NAME_RE
2728
@@ -38,7 +39,31 @@ def repl(m, mapping=mapping):
3839 return cre .sub (repl , default or msgid )
3940 # XXX Not all of Zope.I18n.ITranslationService is implemented.
4041
41- translationService = DummyTranslationService ()
42+ class StaticTranslationService :
43+
44+ """Translation service for application default language
45+
46+ This service uses "static" translation, with single domain
47+ and target language, initialized from OS environment when
48+ roundup.i18n is loaded.
49+
50+ 'domain' and 'target_language' parameters to 'translate()'
51+ are ignored.
52+
53+ Returned strings are always utf8-encoded.
54+
55+ """
56+
57+ OUTPUT_ENCODING = "utf-8"
58+
59+ def translate (self , domain , msgid , mapping = None ,
60+ context = None , target_language = None , default = None
61+ ):
62+ _msg = i18n .ugettext (msgid ).encode (self .OUTPUT_ENCODING )
63+ #print ("TRANSLATE", msgid, _msg, mapping, context)
64+ return _msg
65+
66+ translationService = StaticTranslationService ()
4267
4368def setGlobalTranslationService (service ):
4469 """Sets the global translation service, and returns the previous one."""
0 commit comments