Back to index

plone3  3.1.7
utranslate.py
Go to the documentation of this file.
00001 ## Script (Python) "utranslate (alias for translate)"
00002 ##bind container=container
00003 ##bind context=context
00004 ##bind namespace=
00005 ##bind script=script
00006 ##bind subpath=traverse_subpath
00007 ##parameters=msgid, mapping={}, default=None, domain='plone', target_language=None, escape_for_js=False
00008 
00009 # handle the possible "nothing" condition in folder_contents.pt ln 21 gracefully
00010 if msgid == None:
00011     return None
00012 
00013 from Products.CMFCore.utils import getToolByName
00014 
00015 # get tool
00016 tool = getToolByName(context, 'translation_service')
00017 
00018 # this returns type unicode 
00019 value = tool.utranslate(domain,
00020                         msgid,
00021                         mapping,
00022                         context=context,
00023                         target_language=target_language,
00024                         default=default)
00025 
00026 if not value and default is None:
00027     value = msgid
00028 
00029     for k, v in mapping.items():
00030         value = value.replace('${%s}' % k, v)
00031 
00032 if escape_for_js:
00033     value = value.replace("'", "\\'")
00034 
00035 return value
00036