本文整理汇总了Python中zope.i18n.translate函数的典型用法代码示例。如果您正苦于以下问题:Python translate函数的具体用法?Python translate怎么用?Python translate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了translate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createCommentRule
def createCommentRule(self):
context = self.context
subject = translate(_('notify_subj_comments',
default=u'[${room_title}] New comment has been created',
mapping={"room_title": context.Title().decode('utf-8')}),
context=context.REQUEST,
target_language=self.language)
message = translate(_('notify_msg_comments',
default=u'A new comment has been added by ${user} to document ${parent_title}.\n'
u'\n'
u'${text}\n'
u'\n'
u'You can click on the following link to see the comment:\n'
u'${url}'),
context=context.REQUEST,
target_language=self.language)
rule_title = translate(_('notify_title_comments',
default=u'[${room_title}] notify for new comments',
mapping={"room_title": context.Title().decode('utf-8')}),
context=context.REQUEST,
target_language=self.language)
rule_description = translate(_('notify_description_comments',
default=u'All users inside the comments notification group of the room '
u'will be mailed when new comments are added'),
context=context.REQUEST,
target_language=self.language)
room = self._getParentRoom(context)
self.createRule(context, room, rule_id="%s-comments" % context.getId(), rule_title=rule_title,
rule_description=rule_description, rule_event=IObjectAddedEvent,
subject=subject, message=message, for_types=('Discussion Item',), area_id="comments")
示例2: comment_transform_message
def comment_transform_message(self):
"""Returns the description that shows up above the comment text,
dependent on the text_transform setting and the comment moderation
workflow in the discussion control panel.
"""
context = aq_inner(self.context)
registry = queryUtility(IRegistry)
settings = registry.forInterface(IDiscussionSettings, check=False)
# text transform setting
if settings.text_transform == "text/x-web-intelligent":
message = translate(Message(COMMENT_DESCRIPTION_INTELLIGENT_TEXT),
context=self.request)
elif settings.text_transform == "text/x-web-markdown":
message = translate(Message(COMMENT_DESCRIPTION_MARKDOWN),
context=self.request)
else:
message = translate(Message(COMMENT_DESCRIPTION_PLAIN_TEXT),
context=self.request)
# comment workflow
wftool = getToolByName(context, "portal_workflow", None)
workflow_chain = wftool.getChainForPortalType('Discussion Item')
if workflow_chain:
comment_workflow = workflow_chain[0]
comment_workflow = wftool[comment_workflow]
# check if the current workflow implements a pending state. If this
# is true comments are moderated
if 'pending' in comment_workflow.states:
message = message + " " + \
translate(Message(COMMENT_DESCRIPTION_MODERATION_ENABLED),
context=self.request)
return message
示例3: sendNotificationToMinistry
def sendNotificationToMinistry(date):
"""
send a notification to the ministry stating
all questions that are approaching the deadline
"""
text = translate("notification_email_to_ministry_question_pending_response",
target_language="en",
domain="bungeni",
default="Questions pending responses.")
ministries = _getAllMinistries(date)
for ministry in ministries:
questions = _getQuestionsPendingResponse(date, ministry)
text = translate("notification_email_to_ministry_question_pending_response",
target_language="en",
domain="bungeni",
default="Questions assigned to the ministry pending responses.")
if questions:
text = "%s\n%s: \n" % (text, ministry.full_name) + \
"\n".join([ question.subject for question in questions ])
emails = [ utils.formatted_user_email(minister)
for minister in dbutils.get_ministers(ministry) ]
msg = MIMEText(text)
msg["Subject"] = "Questions pending response"
msg["From"] = prefs.getClerksOfficeEmail()
msg["To"] = " ,".join(emails)
print msg
# !+SENDMAIL(ah,18-03-2010)
#Mail sending is commented out
dispatch(msg)
示例4: Title
def Title(self):
"""The title of the comment.
"""
if self.title:
return self.title
if not self.author_name:
author_name = translate(
Message(_(
u"label_anonymous",
default=u"Anonymous"
))
)
else:
author_name = self.author_name
# Fetch the content object (the parent of the comment is the
# conversation, the parent of the conversation is the content object).
content = aq_base(self.__parent__.__parent__)
title = translate(
Message(COMMENT_TITLE,
mapping={'author_name': safe_unicode(author_name),
'content': safe_unicode(content.Title())}))
return title
示例5: notify_moderator
def notify_moderator(obj, event):
"""Tell the moderator when a comment needs attention.
This method sends an email to the moderator if comment moderation a new
comment has been added that needs to be approved.
The moderator_notification setting has to be enabled in the discussion
control panel.
Configure the moderator e-mail address in the discussion control panel.
If no moderator is configured but moderator notifications are turned on,
the site admin email (from the mail control panel) will be used.
"""
# Check if moderator notification is enabled
registry = queryUtility(IRegistry)
settings = registry.forInterface(IDiscussionSettings, check=False)
if not settings.moderator_notification_enabled:
return
# Get informations that are necessary to send an email
mail_host = getToolByName(obj, 'MailHost')
portal_url = getToolByName(obj, 'portal_url')
portal = portal_url.getPortalObject()
sender = portal.getProperty('email_from_address')
if settings.moderator_email:
mto = settings.moderator_email
else:
mto = sender
# Check if a sender address is available
if not sender:
return
conversation = aq_parent(obj)
content_object = aq_parent(conversation)
# Compose email
subject = translate(_(u"A comment has been posted."), context=obj.REQUEST)
message = translate(Message(MAIL_NOTIFICATION_MESSAGE_MODERATOR,
mapping={
'title': safe_unicode(content_object.title),
'link': content_object.absolute_url() + '/view#' + obj.id,
'text': obj.text,
'link_approve': obj.absolute_url() + '/@@moderate-publish-comment',
'link_delete': obj.absolute_url() + '/@@moderate-delete-comment',
}),
context=obj.REQUEST)
# Send email
try:
mail_host.send(message, mto, sender, subject, charset='utf-8')
except SMTPException, e:
logger.error('SMTP exception (%s) while trying to send an ' +
'email notification to the comment moderator ' +
'(from %s to %s, message: %s)',
e,
sender,
mto,
message)
示例6: update
def update(self):
base_url = self.context.absolute_url()
base_vocabulary = '%s/@@getStorageVocabulary' % base_url
push_state_url = '%s/storage_contents{path}' % base_url
options = {
'vocabularyUrl': base_vocabulary,
'pushStateUrl': push_state_url,
'traverseView': True,
# TODO verify that get_url result in a valid location dir.
'traverseSubpath': self.get_current_path(),
'indexOptionsUrl': '%s/@@qsOptions' % base_url,
'contextInfoUrl': '%s/@@sc-contextInfo' % base_url,
'attributes': attributes,
'activeColumns': ['ModificationDate', 'getObjSize'],
'activeColumnsCookie': 'activeStorageColumns',
'availableColumns': {
'id': translate(_('ID'), context=self.request),
'ModificationDate': translate(_('Last modified'), context=self.request), # noqa
'getObjSize': translate(_('Object Size'), context=self.request), # noqa
},
'upload': False,
'rearrange': False,
'buttons': self.get_actions(),
'menuGenerator': 'repodonostorage-url/js/actionmenu',
'tableRowItemAction': {
# switch off the default navigation js method
'other': None,
},
'collectionConstructor': 'repodonostorage-url/js/collection',
}
self.options = json.dumps(options)
示例7: render
def render(self):
widget_id = self.request.get("widget_id")
if widget_id:
setHeader = self.request.response.setHeader
setHeader("Content-Type", "text/javascript")
upload_utility = getUtility(IUpload)
url = upload_utility.upload_url()
# XXX: Workaround for translating the JS strings
# XXX: We need to get the lang from the request, instead of like this.
upload_error = _(u"Error uploading file, please try again or use a diferent file")
upload_error = translate(upload_error, domain="openmultimedia.reporter", target_language="es")
upload_success = _(u"File uploaded correctly")
upload_success = translate(upload_success, domain="openmultimedia.reporter", target_language="es")
already_uploaded = _(u"Your file was already uploaded, no need to do it again.")
already_uploaded = translate(already_uploaded, domain="openmultimedia.reporter", target_language="es")
return self.js_template_input % dict(
id=widget_id,
id_uploader=widget_id + "-uploader",
upload_url=url,
upload_error=upload_error,
upload_success=upload_success,
already_uploaded=already_uploaded,
)
示例8: send_email
def send_email(self, userid):
""" Send email to nominated address """
registry = getUtility(IRegistry)
mail_settings = registry.forInterface(IMailSchema, prefix='plone')
mTo = self.getSurveyNotificationEmail()
mFrom = mail_settings.email_from_address
mSubj = translate(_(
'[${survey_title}] New survey submitted',
mapping={'survey_title': self.Title()}),
context=self.REQUEST)
message = []
message.append(translate(_(
'Survey ${survey_title}',
mapping={'survey_title': self.Title()}),
context=self.REQUEST))
message.append(translate(_(
'has been completed by user: ${userid}',
mapping={'userid': userid}),
context=self.REQUEST))
message.append(self.absolute_url() +
'/@@Products.PloneSurvey.survey_view_results')
mMsg = '\n\n'.join(message)
try:
self.MailHost.send(mMsg.encode('utf-8'), mTo, mFrom, mSubj)
except ConflictError:
raise
except:
# XXX too many things can go wrong
pass
示例9: update
def update(self):
super(DigestIcon, self).update()
self.anonymous = self.portal_state.anonymous()
if self.anonymous:
return
user_id = api.user.get_current().getId()
utility = get_tool()
storage, recursive = utility.get_subscription(user_id, self.context)
if not storage:
self.icon = 'maildigest.png'
self.title = _('folder_digesticon_title',
default=u"Subscribe to recurring digest of activity in this folder")
else:
self.icon = storage.icon
if recursive:
self.title = _('title_digesticon_recursives',
default=u"You have subscribed to ${delay} digest on this folder and all its subfolders",
mapping={'delay': translate(storage.label, context=self.request).lower()})
else:
self.title = _('title_digesticon',
default=u"You have subscribed to ${delay} digest on this folder",
mapping={'delay': translate(storage.label, context=self.request).lower()})
self.form_url = "%s/digest-subscribe" % self.context.absolute_url()
示例10: page_title
def page_title(self):
'''
Get the page title. If we are in the portal_factory we want use the
"Add $FTI_TITLE" form (see #12117).
NOTE: other implementative options can be:
- to use "Untitled" instead of "Add" or
- to check the isTemporary method of the edit view instead of the
creation_flag
'''
if (hasattr(aq_base(self.context), 'isTemporary') and
self.context.isTemporary()):
# if we are in the portal_factory we want the page title to be
# "Add fti title"
portal_types = getToolByName(self.context, 'portal_types')
fti = portal_types.getTypeInfo(self.context)
return translate('heading_add_item',
domain='plone',
mapping={'itemtype': fti.Title()},
context=self.request,
default='New ${itemtype}')
if IAddForm.providedBy(self.view):
portal_types = getToolByName(self.context, 'portal_types')
fti = portal_types.getTypeInfo(self.view.portal_type)
return translate('heading_add_item',
domain='plone',
mapping={'itemtype': fti.Title()},
context=self.request,
default='New ${itemtype}')
title = getattr(self.view, 'title', None)
if not title:
context_state = getMultiAdapter((self.context, self.request),
name=u'plone_context_state')
title = context_state.object_title()
return escape(safe_unicode(title))
示例11: translate
def translate(self, msgid, *args, **kwargs):
"""Return localized string for given msgid"""
# XXX: It seems that **kwargs does not yet work with Robot Framework
# remote library interface and that's why we need to unpack the
# keyword arguments from positional args list.
mapping = {}
for arg in args:
name, value = arg.split('=', 1)
kwargs[name] = value
for key, value in kwargs.items():
if not key in ('target_language', 'domain', 'default'):
mapping[key] = value
if kwargs.get('target_language'):
return translate(
msgid, target_langauge=kwargs.get('target_language'),
domain=kwargs.get('domain') or 'plone',
default=kwargs.get('default') or msgid, mapping=mapping)
else:
# XXX: Should self.REQUEST be replaced with
# zope.globalrequest.getRequest()?
request = getRequest()
return translate(
msgid, context=request,
domain=kwargs.get('domain') or 'plone',
default=kwargs.get('default') or msgid, mapping=mapping)
示例12: __call__
def __call__(self):
form = self.request.form
context = aq_inner(self.context)
status = IStatusMessage(self.request)
if not self.can_edit_response:
msg = _(u"You are not allowed to edit responses.")
msg = translate(msg, 'Poi', context=self.request)
status.addStatusMessage(msg, type='error')
else:
response_id = form.get('response_id', None)
if response_id is None:
msg = _(u"No response selected for saving.")
msg = translate(msg, 'Poi', context=self.request)
status.addStatusMessage(msg, type='error')
else:
response = self.folder[response_id]
response_text = form.get('response', u'')
response.text = response_text
# Remove cached rendered response.
response.rendered_text = None
msg = _(u"Changes saved to response id ${response_id}.",
mapping=dict(response_id=response_id))
msg = translate(msg, 'Poi', context=self.request)
status.addStatusMessage(msg, type='info')
# Fire event. We put the context in the descriptions
# so event handlers can use this fully acquisition
# wrapped object to do their thing. Feels like
# cheating, but it gets the job done. Arguably we
# could turn the two arguments around and signal that
# the issue has changed, with the response in the
# event descriptions.
modified(response, context)
self.request.response.redirect(context.absolute_url())
示例13: reminder_options
def reminder_options(self):
options = []
reminder_option = TaskReminder().get_reminder(self.context)
options.append({
'option_type': 'no-reminder',
'option_title': translate(_('no_reminder', default='No reminder'),
context=self.request),
'sort_order': -1,
'selected': reminder_option is None,
'showSpinner': False,
})
for option in TASK_REMINDER_OPTIONS.values():
selected = option.option_type == reminder_option.option_type if \
reminder_option else None
options.append({
'option_type': option.option_type,
'sort_order': option.sort_order,
'option_title': translate(
option.option_title, context=self.request),
'selected': selected,
'showSpinner': False,
})
return options
示例14: getBandoState
def getBandoState(self):
"""
return corretc bando state
"""
scadenza_bando = getattr(self.context, 'scadenza_bando', None)
chiusura_procedimento_bando = getattr(
self.context, 'chiusura_procedimento_bando', None
)
state = ('open', translate(_(u'Open'), context=self.request))
if scadenza_bando and scadenza_bando < datetime.now():
if chiusura_procedimento_bando and (
chiusura_procedimento_bando < datetime.now().date()
):
state = ('closed', translate(
_(u'Closed'), context=self.request)
)
else:
state = ('inProgress', translate(
_(u'In progress'), context=self.request)
)
elif chiusura_procedimento_bando and (
chiusura_procedimento_bando < datetime.now().date()
):
state = ('closed', translate(
_(u'Closed'), context=self.request)
)
return state
示例15: items
def items(self):
items = []
for system in self.unit_systems:
dimensions = interfaces.UNITS.get(system, None)
if not dimensions:
continue
units = []
available_units = dimensions.get(self.unit_dimension, [])
if self.level_max is not None:
level_max = self.level_max + 1
else:
level_max = None
available_units = available_units[self.level_min:level_max]
for unit in available_units:
abbr, label_short, label, info = unit
subtext = translate(label, context=self.request)
if info:
info = translate(info, context=self.request)
subtext = subtext + ' (%s)' % info
units.append({
'id': abbr,
'value': abbr,
'content': label_short,
'subtext': subtext,
'selected': self.isSelected(abbr),
})
item = {}
item['title'] = interfaces.LABELS.get(system)
item['member'] = units
items.append(item)
return items