Mercurial > p > roundup > code
comparison roundup/cgi/templating.py @ 2377:a53f87f2488a
StaticTranslationService moved here out of the code originating from Zope;
install the translation service on load
| author | Alexander Smishlajev <a1s@users.sourceforge.net> |
|---|---|
| date | Fri, 28 May 2004 23:53:35 +0000 |
| parents | fbbda3b1816d |
| children | 2ff93cee9c63 |
comparison
equal
deleted
inserted
replaced
| 2374:31cb1014300c | 2377:a53f87f2488a |
|---|---|
| 15 from __future__ import nested_scopes | 15 from __future__ import nested_scopes |
| 16 | 16 |
| 17 import sys, cgi, urllib, os, re, os.path, time, errno, mimetypes | 17 import sys, cgi, urllib, os, re, os.path, time, errno, mimetypes |
| 18 | 18 |
| 19 from roundup import hyperdb, date, rcsv | 19 from roundup import hyperdb, date, rcsv |
| 20 from roundup import i18n | |
| 20 from roundup.i18n import _ | 21 from roundup.i18n import _ |
| 21 | 22 |
| 22 try: | 23 try: |
| 23 import cPickle as pickle | 24 import cPickle as pickle |
| 24 except ImportError: | 25 except ImportError: |
| 31 import StructuredText | 32 import StructuredText |
| 32 except ImportError: | 33 except ImportError: |
| 33 StructuredText = None | 34 StructuredText = None |
| 34 | 35 |
| 35 # bring in the templating support | 36 # bring in the templating support |
| 36 from roundup.cgi.PageTemplates import PageTemplate | 37 from roundup.cgi.PageTemplates import PageTemplate, GlobalTranslationService |
| 37 from roundup.cgi.PageTemplates.Expressions import getEngine | 38 from roundup.cgi.PageTemplates.Expressions import getEngine |
| 38 from roundup.cgi.TAL.TALInterpreter import TALInterpreter | 39 from roundup.cgi.TAL import TALInterpreter |
| 39 from roundup.cgi import ZTUtils | 40 from roundup.cgi import ZTUtils |
| 41 | |
| 42 ### i18n services | |
| 43 | |
| 44 class StaticTranslationService: | |
| 45 | |
| 46 """Translation service for application default language | |
| 47 | |
| 48 This service uses "static" translation, with single domain | |
| 49 and target language, initialized from OS environment when | |
| 50 roundup.i18n is loaded. | |
| 51 | |
| 52 'domain' and 'target_language' parameters to 'translate()' | |
| 53 are ignored. | |
| 54 | |
| 55 Returned strings are always utf8-encoded. | |
| 56 | |
| 57 """ | |
| 58 | |
| 59 OUTPUT_ENCODING = "utf-8" | |
| 60 | |
| 61 def translate(self, domain, msgid, mapping=None, | |
| 62 context=None, target_language=None, default=None | |
| 63 ): | |
| 64 _msg = i18n.ugettext(msgid).encode(self.OUTPUT_ENCODING) | |
| 65 #print ("TRANSLATE", msgid, _msg, mapping, context) | |
| 66 _msg = TALInterpreter.interpolate(_msg, mapping) | |
| 67 return _msg | |
| 68 | |
| 69 GlobalTranslationService.setGlobalTranslationService( | |
| 70 StaticTranslationService()) | |
| 71 | |
| 72 ### templating | |
| 40 | 73 |
| 41 class NoTemplate(Exception): | 74 class NoTemplate(Exception): |
| 42 pass | 75 pass |
| 43 | 76 |
| 44 class Unauthorised(Exception): | 77 class Unauthorised(Exception): |
| 240 c = self.getContext(client, classname, request) | 273 c = self.getContext(client, classname, request) |
| 241 c.update({'options': options}) | 274 c.update({'options': options}) |
| 242 | 275 |
| 243 # and go | 276 # and go |
| 244 output = StringIO.StringIO() | 277 output = StringIO.StringIO() |
| 245 TALInterpreter(self._v_program, self.macros, | 278 TALInterpreter.TALInterpreter(self._v_program, self.macros, |
| 246 getEngine().getContext(c), output, tal=1, strictinsert=0)() | 279 getEngine().getContext(c), output, tal=1, strictinsert=0)() |
| 247 return output.getvalue() | 280 return output.getvalue() |
| 248 | 281 |
| 249 def __repr__(self): | 282 def __repr__(self): |
| 250 return '<Roundup PageTemplate %r>'%self.id | 283 return '<Roundup PageTemplate %r>'%self.id |
