Version initiale.
[Portfolio.git] / utils.py
1 # -*- coding: utf-8 -*-
2 ############################################################
3 # Copyright © 2008 Benoît PIN <benoit.pin@ensmp.fr> #
4 # Plinn - http://plinn.org #
5 # #
6 # This program is free software; you can redistribute it #
7 # and/or modify it under the terms of the Creative Commons #
8 # "Attribution-Noncommercial 2.0 Generic" #
9 # http://creativecommons.org/licenses/by-nc/2.0/ #
10 ############################################################
11 """ Global utilities for portfolio / photo objects.
12 $Id: utils.py 1200 2009-07-08 15:50:15Z pin $
13 $URL: http://svn.luxia.fr/svn/labo/projects/zope/Portfolio/trunk/utils.py $
14 """
15
16 from AccessControl import ModuleSecurityInfo
17 from Products.PageTemplates.GlobalTranslationService import getGlobalTranslationService
18 from zope.i18nmessageid import MessageFactory
19
20 security = ModuleSecurityInfo('Products.Portfolio.utils')
21
22 security.declarePublic('Message')
23 Message = MessageFactory('portfolio')
24
25 security.declarePublic('translate')
26 def translate(message, context):
27 """ Translate i18n message.
28 """
29 GTS = getGlobalTranslationService()
30 if isinstance(message, Exception):
31 try:
32 message = message[0]
33 except (TypeError, IndexError):
34 pass
35 return GTS.translate('portfolio', message, context=context)