Correction crash
[auf_roundup.git] / build / lib / roundup / cgi / PageTemplates / GlobalTranslationService.py
1 ##############################################################################
2 #
3 # Copyright (c) 2002 Zope Corporation and Contributors.
4 # All Rights Reserved.
5 #
6 # This software is subject to the provisions of the Zope Public License,
7 # Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
8 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11 # FOR A PARTICULAR PURPOSE.
12 #
13 ##############################################################################
14 # Modifications for Roundup:
15 # 1. implemented ustr as str
16 # 2. make imports use roundup.cgi
17 """Global Translation Service for providing I18n to Page Templates.
18
19 $Id: GlobalTranslationService.py,v 1.4 2004-05-29 00:08:07 a1s Exp $
20 """
21
22 import re
23
24 from roundup.cgi.TAL.TALDefs import NAME_RE
25
26 ustr = str
27
28 class DummyTranslationService:
29 """Translation service that doesn't know anything about translation."""
30 def translate(self, domain, msgid, mapping=None,
31 context=None, target_language=None, default=None):
32 def repl(m, mapping=mapping):
33 return ustr(mapping[m.group(m.lastindex)])
34 cre = re.compile(r'\$(?:(%s)|\{(%s)\})' % (NAME_RE, NAME_RE))
35 return cre.sub(repl, default or msgid)
36 # XXX Not all of Zope.I18n.ITranslationService is implemented.
37
38 translationService = DummyTranslationService()
39
40 def setGlobalTranslationService(service):
41 """Sets the global translation service, and returns the previous one."""
42 global translationService
43 old_service = translationService
44 translationService = service
45 return old_service
46
47 def getGlobalTranslationService():
48 """Returns the global translation service."""
49 return translationService