X-Git-Url: https://scm.cri.mines-paristech.fr/git/Plinn.git/blobdiff_plain/26f4d954aca9474519a7fc5562ec7a04a58a0b4b..8393e88f33f604ce16fb229cf7f116ac106e2b0f:/utils.py diff --git a/utils.py b/utils.py index 726c4e8..863b94e 100755 --- a/utils.py +++ b/utils.py @@ -18,8 +18,8 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # ####################################################################################### """ Plinn public utilities -$Id: utils.py 1534 2009-09-07 11:05:57Z pin $ -$URL: http://svn.cri.ensmp.fr/svn/Plinn/branches/CMF-2.1/utils.py $ + + """ import string @@ -36,7 +36,7 @@ from Products.CMFCore.utils import getToolByName, getUtilityByInterfaceName from Products.CMFCore.exceptions import BadRequest from Products.Utf8Splitter.Utf8Splitter import Utf8Utils from Globals import REPLACEABLE, NOT_REPLACEABLE, UNIQUE -#from Products.PageTemplates.GlobalTranslationService import getGlobalTranslationService +from zope.i18n import translate as i18ntranslate from zope.i18n.interfaces import IUserPreferredLanguages from zope.i18nmessageid import MessageFactory from zope.component.interfaces import ComponentLookupError @@ -87,15 +87,17 @@ def capitalizeCompoundGivenName(givenName) : def formatFullName(memberName, memberGivenName, memberId, nameBefore=1) : - memberFullName = '' + memberName = memberName.decode('utf-8') + memberGivenName = memberGivenName.decode('utf-8') + memberFullName = u'' if memberName and memberGivenName : if nameBefore : - memberFullName = memberName.capitalize() + ' ' + capitalizeCompoundGivenName(memberGivenName) + memberFullName = memberName.upper() + ' ' + capitalizeCompoundGivenName(memberGivenName) else : - memberFullName = capitalizeCompoundGivenName(memberGivenName) + ' ' + memberName.capitalize() + memberFullName = capitalizeCompoundGivenName(memberGivenName) + ' ' + memberName.upper() elif memberName and not memberGivenName : - memberFullName = memberName.capitalize() + memberFullName = memberName.upper() elif not memberName and memberGivenName : memberFullName = capitalizeCompoundGivenName(memberGivenName) @@ -103,7 +105,7 @@ def formatFullName(memberName, memberGivenName, memberId, nameBefore=1) : else : memberFullName = memberId - return memberFullName + return memberFullName.encode('utf-8') # from OFS.ObjectManager #63 bad_url_chars = re.compile(r'[^a-zA-Z0-9-_~,.$\(\)@]') @@ -195,15 +197,12 @@ security.declarePublic('translate') def translate(message, context): """ Translate i18n message. """ - # TODO : localisation. - #GTS = getGlobalTranslationService() if isinstance(message, Exception): try: message = message[0] except (TypeError, IndexError): pass - return message - return GTS.translate('plinn', message, context=context) + return i18ntranslate(message, domain='plinn', context=context.REQUEST) security.declarePublic('desacc') desacc = Utf8Utils.desacc