[CMF-checkins] SVN: CMF/trunk/C - translate portal status messages
before they are added to the query string of a redirect
Yvo Schubbe
y.2006_ at wcm-solutions.de
Fri Feb 24 16:34:28 EST 2006
Log message for revision 41782:
- translate portal status messages before they are added to the query string of a redirect
Changed:
U CMF/trunk/CHANGES.txt
U CMF/trunk/CMFDefault/browser/utils.py
U CMF/trunk/CMFDefault/skins/zpt_control/setRedirect.py
U CMF/trunk/CMFDefault/skins/zpt_control/setStatus.py
U CMF/trunk/CMFDefault/skins/zpt_generic/getMainGlobals.py
U CMF/trunk/CMFDefault/skins/zpt_generic/main_template.pt
U CMF/trunk/CMFDefault/utils.py
-=-
Modified: CMF/trunk/CHANGES.txt
===================================================================
--- CMF/trunk/CHANGES.txt 2006-02-24 20:57:17 UTC (rev 41781)
+++ CMF/trunk/CHANGES.txt 2006-02-24 21:34:28 UTC (rev 41782)
@@ -2,6 +2,14 @@
New Features
+ - CMFDefault skins: Improved support for custom i18n domains.
+ If setStatus is used portal status messages are now translated before
+ they are added to the query string of a redirect.
+
+ - CMFDefault utils: Added 'translate' function.
+ This should only be used if the message can't be translated in the
+ template. It is a small shortcut to getGlobalTranslationService.
+
- CMFDefault: Added experimental Zope 3-style browser views.
The views are disabled by default. See README.txt of the browser
sub-package for further information.
Modified: CMF/trunk/CMFDefault/browser/utils.py
===================================================================
--- CMF/trunk/CMFDefault/browser/utils.py 2006-02-24 20:57:17 UTC (rev 41781)
+++ CMF/trunk/CMFDefault/browser/utils.py 2006-02-24 21:34:28 UTC (rev 41782)
@@ -22,6 +22,7 @@
from Products.CMFCore.utils import getToolByName
from Products.CMFDefault.utils import html_marshal
from Products.CMFDefault.utils import Message as _
+from Products.CMFDefault.utils import translate
from Products.CMFDefault.utils import toUnicode
@@ -95,6 +96,8 @@
kw = {}
message = self.request.other.get('portal_status_message', '')
if message:
+ if isinstance(message, unicode):
+ message = message.encode(self._getDefaultCharset())
kw['portal_status_message'] = message
for k in keys.split(','):
k = k.strip()
@@ -122,7 +125,8 @@
if isinstance(status, bool):
status = (status,)
if len(status) > 1:
- self.request.other['portal_status_message'] = status[1]
+ message = translate(status[1], self.context)
+ self.request.other['portal_status_message'] = message
if not status[0]:
return self.index()
if self._setRedirect(*button['redirect']):
Modified: CMF/trunk/CMFDefault/skins/zpt_control/setRedirect.py
===================================================================
--- CMF/trunk/CMFDefault/skins/zpt_control/setRedirect.py 2006-02-24 20:57:17 UTC (rev 41781)
+++ CMF/trunk/CMFDefault/skins/zpt_control/setRedirect.py 2006-02-24 21:34:28 UTC (rev 41782)
@@ -4,6 +4,8 @@
from Products.CMFCore.utils import getToolByName
utool = getToolByName(script, 'portal_url')
+ptool = getToolByName(script, 'portal_properties')
+default_charset = ptool.getProperty('default_charset', None)
portal_url = utool()
@@ -13,7 +15,10 @@
target = portal_url
message = context.REQUEST.other.get('portal_status_message', '')
-kw['portal_status_message'] = message
+if message:
+ if isinstance(message, unicode):
+ message = message.encode(default_charset)
+ kw['portal_status_message'] = message
for k, v in kw.items():
if not v:
del kw[k]
Modified: CMF/trunk/CMFDefault/skins/zpt_control/setStatus.py
===================================================================
--- CMF/trunk/CMFDefault/skins/zpt_control/setStatus.py 2006-02-24 20:57:17 UTC (rev 41781)
+++ CMF/trunk/CMFDefault/skins/zpt_control/setStatus.py 2006-02-24 21:34:28 UTC (rev 41782)
@@ -1,8 +1,9 @@
-## Script (Python) "setStatus"
##parameters=success, message='', **kw
-##title=
##
+from Products.CMFDefault.utils import translate
+
if message:
+ message = translate(message, context)
context.REQUEST.other['portal_status_message'] = message
if kw:
for k, v in kw.items():
Modified: CMF/trunk/CMFDefault/skins/zpt_generic/getMainGlobals.py
===================================================================
--- CMF/trunk/CMFDefault/skins/zpt_generic/getMainGlobals.py 2006-02-24 20:57:17 UTC (rev 41781)
+++ CMF/trunk/CMFDefault/skins/zpt_generic/getMainGlobals.py 2006-02-24 21:34:28 UTC (rev 41782)
@@ -15,6 +15,10 @@
context.REQUEST.RESPONSE.setHeader('Content-Type',
'text/html;charset=%s' % default_charset)
+message = context.REQUEST.get('portal_status_message')
+if message and isinstance(message, str):
+ message = message.decode(default_charset)
+
globals = {'utool': utool,
'mtool': mtool,
'atool': atool,
@@ -27,6 +31,7 @@
'member': mtool.getAuthenticatedMember(),
'membersfolder': mtool.getMembersFolder(),
'isAnon': mtool.isAnonymousUser(),
- 'wf_state': wtool.getInfoFor(context, 'review_state', '')}
+ 'wf_state': wtool.getInfoFor(context, 'review_state', ''),
+ 'status_message': message}
return decode(globals, context)
Modified: CMF/trunk/CMFDefault/skins/zpt_generic/main_template.pt
===================================================================
--- CMF/trunk/CMFDefault/skins/zpt_generic/main_template.pt 2006-02-24 20:57:17 UTC (rev 41781)
+++ CMF/trunk/CMFDefault/skins/zpt_generic/main_template.pt 2006-02-24 21:34:28 UTC (rev 41782)
@@ -266,8 +266,8 @@
</p>
<p id="DesktopStatusBar"
- tal:condition="request/portal_status_message|nothing"
- tal:content="request/portal_status_message"
+ tal:condition="globals/status_message"
+ tal:content="globals/status_message"
i18n:translate="">Status message.</p>
<metal:slot metal:define-slot="header">
Modified: CMF/trunk/CMFDefault/utils.py
===================================================================
--- CMF/trunk/CMFDefault/utils.py 2006-02-24 20:57:17 UTC (rev 41781)
+++ CMF/trunk/CMFDefault/utils.py 2006-02-24 21:34:28 UTC (rev 41782)
@@ -24,6 +24,8 @@
from AccessControl import ModuleSecurityInfo
from Globals import package_home
+from Products.PageTemplates.GlobalTranslationService \
+ import getGlobalTranslationService
from ZTUtils.Zope import complex_marshal
from zope.i18nmessageid import MessageFactory
@@ -437,5 +439,12 @@
default_charset = ptool.getProperty('default_charset', None)
return toUnicode(value, default_charset)
+security.declarePublic('translate')
+def translate(message, context):
+ """ Translate i18n message.
+ """
+ GTS = getGlobalTranslationService()
+ return GTS.translate('cmf_default', message, context=context)
+
security.declarePublic('Message')
Message = MessageFactory('cmf_default')
More information about the CMF-checkins
mailing list