9f4fb8a3d012aaa1a873060c3566f9b0c3996e24
[photoprint.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 """
12 Global utilities
13
14 $Id: utils.py 651 2009-02-04 15:38:20Z pin $
15 $URL: http://svn.luxia.fr/svn/labo/projects/zope/photoprint/trunk/utils.py $
16 """
17
18 from AccessControl import ModuleSecurityInfo
19 from Products.PageTemplates.GlobalTranslationService import getGlobalTranslationService
20 from zope.i18nmessageid import MessageFactory
21
22 security = ModuleSecurityInfo('Products.photoprint.utils')
23
24 security.declarePublic('translate')
25 def translate(message, context):
26 """ Translate i18n message.
27 """
28 GTS = getGlobalTranslationService()
29 if isinstance(message, Exception):
30 try:
31 message = message[0]
32 except (TypeError, IndexError):
33 pass
34 return GTS.translate('photoprint', message, context=context)
35
36 security.declarePublic('Message')
37 Message = _ = MessageFactory('photoprint')