本文整理汇总了Python中pylons.i18n.ungettext函数的典型用法代码示例。如果您正苦于以下问题:Python ungettext函数的具体用法?Python ungettext怎么用?Python ungettext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ungettext函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: localised_nice_date
def localised_nice_date(datetime_):
''' Returns a friendly localised unicode representation of a datetime. '''
now = datetime.datetime.now()
date_diff = now - datetime_
days = date_diff.days
if days < 1 and now > datetime_:
# less than one day
seconds = date_diff.seconds
if seconds < 3600:
# less than one hour
if seconds < 60:
return _('Just now')
else:
return ungettext('{mins} minute ago', '{mins} minutes ago',
seconds / 60).format(mins=seconds / 60)
else:
return ungettext('{hours} hour ago', '{hours} hours ago',
seconds / 3600).format(hours=seconds / 3600)
# more than one day
if days < 31:
return ungettext('{days} day ago', '{days} days ago',
days).format(days=days)
# actual date
month = datetime_.month
day = datetime_.day
year = datetime_.year
month_name = _MONTH_FUNCTIONS[month - 1]()
return _('{month} {day}, {year}').format(month=month_name, day=day,
year=year)
开发者ID:AdamJensen-dk,项目名称:ckan,代码行数:29,代码来源:formatters.py
示例2: when
def when(time):
"""Formats now() - time in human readable format."""
import datetime
from pylons.i18n import ungettext
difference = datetime.datetime.utcnow() - time
if datetime.timedelta(seconds=60) > difference:
num = difference.seconds
return ungettext("%(num)s second ago",
"%(num)s seconds ago",
num) % {'num': num}
elif datetime.timedelta(seconds=3600) > difference:
num = difference.seconds / 60
return ungettext("%(num)s minute ago",
"%(num)s minutes ago",
num) % {'num': num}
elif datetime.timedelta(1) > difference:
num = difference.seconds / 3600
return ungettext("%(num)s hour ago",
"%(num)s hours ago",
num) % {'num': num}
elif datetime.timedelta(5) > difference:
num = difference.days
return ungettext("%(num)s day ago",
"%(num)s days ago",
num) % {'num': num}
else:
return time.strftime("%Y-%m-%d")
开发者ID:nous-consulting,项目名称:ututi,代码行数:27,代码来源:helpers.py
示例3: _subject
def _subject(self, sections, events):
pages = files = 0
for section in sections:
for event in section['events']:
if event['type'] == 'page':
pages += 1
elif event['type'] == 'file':
files += 1
subject = _('Ututi news: %(changes)s')
file_changes = ungettext('%(file_count)d new file',
'%(file_count)d new files', files) % {
'file_count': files}
page_changes = ungettext('%(page_count)d new page',
'%(page_count)d new pages', pages) % {
'page_count': pages}
if pages and files:
subject = _('Ututi news: %(file_changes)s and %(page_changes)s')
subject = subject % {'file_changes': file_changes,
'page_changes': page_changes}
elif files:
subject = subject % {'changes': file_changes}
elif pages:
subject = subject % {'changes': page_changes}
else:
messages = len([event for event in events if event.category == 'moderation'])
moderation_changes = ungettext('%(message_count)d new message awaiting moderation',
'%(message_count)d new messages awaiting moderation', messages) % {
'message_count': messages}
subject = subject % {'changes': moderation_changes}
return subject
开发者ID:nous-consulting,项目名称:ututi,代码行数:33,代码来源:news.py
示例4: __getattr__
def __getattr__(self, attr):
if attr.startswith("N_"):
a = attr[2:]
rval = self.string_dict[a]
return lambda x: ungettext(rval[0], rval[1], x)
else:
rval = self.string_dict[attr]
n = 1 if attr == rval[0] else 5
return ungettext(rval[0], rval[1], n)
开发者ID:EeroHeikkinen,项目名称:ikaros,代码行数:9,代码来源:strings.py
示例5: popular
def popular(type_, number, min=1, title=None):
""" display a popular icon. """
if type_ == "views":
title = ungettext("{number} view", "{number} views", number)
elif type_ == "recent views":
title = ungettext("{number} recent view", "{number} recent views", number)
elif not title:
raise Exception("popular() did not recieve a valid type_ or title")
return snippet("snippets/popular.html", title=title, number=number, min=min)
开发者ID:Brackets,项目名称:ckan,代码行数:9,代码来源:helpers.py
示例6: popular
def popular(type_, number, min=1, title=None):
''' display a popular icon. '''
if type_ == 'views':
title = ungettext('{number} view', '{number} views', number)
elif type_ == 'recent views':
title = ungettext('{number} recent view', '{number} recent views', number)
elif not title:
raise Exception('popular() did not recieve a valid type_ or title')
return snippet('snippets/popular.html', title=title, number=number, min=min)
开发者ID:HHS,项目名称:ckan,代码行数:9,代码来源:helpers.py
示例7: merge_post
def merge_post(self):
primary_id = int(request.params.get('primary_id'))
primary = meta.Session.query(model.Person).get(primary_id)
log.debug("primary: %s" % primary)
primary_media = map(lambda x: x.medium, primary.persons_to_media)
log.debug("primary_media: %s" % primary_media)
person_ids = request.params.get('person_ids_str')
person_ids = person_ids.split(',')
person_ids = map(lambda x: int(x), person_ids)
person_ids.remove(primary_id)
log.debug("person_ids: %s" % person_ids)
remap_cnt = 0
for secondary_id in person_ids:
secondary = meta.Session.query(model.Person).get(secondary_id)
log.debug("secondary: %s" % secondary)
for item in secondary.persons_to_media:
if item.medium in primary_media:
log.debug("medium already exists: %s" % item.medium)
else:
log.debug("medium does not exists: %s" % item.medium)
#~ item.person_id = primary.id
#~ meta.Session.update(item)
record = model.PersonToMedia()
record.type_id = item.type_id
item.medium.persons_to_media.append(record)
primary.persons_to_media.append(record)
remap_cnt += 1
alias = model.PersonAlias()
alias.name = secondary.name
primary.aliases.append(alias)
meta.Session.delete(secondary)
meta.Session.commit()
#~ h.flash(_("Removed %(person_cnt)d, added %(media_cnt)d media") %\
#~ {'person_cnt':len(person_ids), 'media_cnt':remap_cnt})
h.flash(ungettext("Removed %d person",
"Removed %d persons",
len(person_ids)) % len(person_ids))
h.flash(ungettext("Added %(cnt)d medium to '%(person)s'",
"Added %(cnt)d media to '%(person)s'",
remap_cnt) % {'cnt':remap_cnt,
'person':primary.name})
return_to = request.params.get('return_to',
h.url_for(controller='person',
action='edit',
id=primary.id))
return redirect(str(return_to))
开发者ID:dummy3k,项目名称:medienverwaltung,代码行数:55,代码来源:person.py
示例8: __getattr__
def __getattr__(self, attr):
to_func = False
if attr.startswith("N_"):
attr = attr[2:]
to_func = True
attr = attr.replace("_", " ")
if to_func:
rval = self.string_dict[attr]
return lambda x: ungettext(rval[0], rval[1], x)
else:
rval = self.string_dict[attr]
n = 1 if attr == rval[0] else 5
return ungettext(rval[0], rval[1], n)
开发者ID:bodegard,项目名称:reddit,代码行数:14,代码来源:strings.py
示例9: _handle_personal_sms_credits
def _handle_personal_sms_credits(self, msg):
if msg.sender is None:
return _('Your phone number (+%s) is not registered in Ututi.') % msg.sender_phone_number
credit_count = int(config.get('fortumo.personal_sms_credits.credits', 50))
credit_price = float(config.get('fortumo.personal_sms_credits.price', 500)) / 100
msg.sender.purchase_sms_credits(credit_count)
msg.success = True
return ungettext(
'You have purchased %(count)d SMS credit for %(price).2f Lt;',
'You have purchased %(count)d SMS credits for %(price).2f Lt;',
credit_count) % dict(count=credit_count, price=credit_price) + \
ungettext(
' You now have %(count)d credit.',
' You now have %(count)d credits.',
msg.sender.sms_messages_remaining) % dict(count=msg.sender.sms_messages_remaining)
开发者ID:nous-consulting,项目名称:ututi,代码行数:15,代码来源:fortumo.py
示例10: create
def create(cls, link, campaigns):
transactions = get_transactions(link, campaigns)
live_campaigns = scheduled_campaigns_by_link(link)
user_is_sponsor = c.user_is_sponsor
r = []
for camp in campaigns:
transaction = transactions.get(camp._id)
campaign_id36 = camp._id36
start_date = camp.start_date.strftime("%m/%d/%Y")
end_date = camp.end_date.strftime("%m/%d/%Y")
ndays = (camp.end_date - camp.start_date).days
duration = strings.time_label % dict(num=ndays,
time=ungettext("day", "days", ndays))
bid = "%.2f" % camp.bid
sr = camp.sr_name
status = {'paid': bool(transaction),
'complete': False,
'free': camp.is_freebie(),
'pay_url': pay_url(link, camp),
'view_live_url': view_live_url(link, sr),
'sponsor': user_is_sponsor,
'live': camp._id in live_campaigns}
if transaction:
if transaction.is_void():
status['paid'] = False
status['free'] = False
elif transaction.is_charged():
status['complete'] = True
rc = cls(campaign_id36, start_date, end_date, duration, bid, sr,
status)
r.append(rc)
return r
开发者ID:caseypatrickdriscoll,项目名称:reddit,代码行数:33,代码来源:promote.py
示例11: get_links
def get_links(cls, event_id):
link_ids = cls._get_related_link_ids(event_id)
links = Link._byID(link_ids, data=True, return_dict=False)
links.sort(key=lambda L: L.num_comments, reverse=True)
sr_ids = set(L.sr_id for L in links)
subreddits = Subreddit._byID(sr_ids, data=True)
wrapped = []
for link in links:
w = Wrapped(link)
if w._spam or w._deleted:
continue
if not getattr(w, "allow_liveupdate", True):
continue
w.subreddit = subreddits[link.sr_id]
# ideally we'd check if the user can see the subreddit, but by
# doing this we keep everything user unspecific which makes caching
# easier.
if w.subreddit.type == "private":
continue
comment_label = ungettext("comment", "comments", link.num_comments)
w.comments_label = strings.number_label % dict(
num=link.num_comments, thing=comment_label)
wrapped.append(w)
return wrapped
开发者ID:binarycoder,项目名称:reddit-plugin-liveupdate,代码行数:32,代码来源:pages.py
示例12: _handle_group_message
def _handle_group_message(self, msg):
parts = msg.message_text.split(None, 1)
if len(parts) != 2:
return _('Invalid group message: %s') % msg.message_text
group_id, text = parts
if not msg.sender:
return _('The phone number %s is not associated with a Ututi user') % (msg.sender_phone_number)
group = Group.get(group_id)
if group is None:
return _('Invalid group: %s') % group_id
max_group_members = config.get('sms_max_group_members', 40)
if len(group.recipients_sms(sender=msg.sender)) > max_group_members:
return ungettext(
'More than %d recipient, cannot send message.',
'More than %d recipients, cannot send message.',
max_group_members) % max_group_members
# Send message.
msg = OutgoingGroupSMSMessage(sender=msg.sender, group=group,
message_text=text)
meta.Session.add(msg)
msg.send()
msg.success = True
return _('SMS message sent to group %s.') % group_id
开发者ID:nous-consulting,项目名称:ututi,代码行数:29,代码来源:fortumo.py
示例13: text_news
def text_news(self):
count = self.count_of_messages_in_queue()
text = ungettext('There is %(number_of_messages)d message in the moderation queue (%(moderation_queue_link)s)',
'There are %(number_of_messages)d messages in the moderation queue (%(moderation_queue_link)s)', count) % {
'number_of_messages': count,
'moderation_queue_link': self.context.url(controller='mailinglist', action='administration', qualified=True)}
return text
开发者ID:nous-consulting,项目名称:ututi,代码行数:7,代码来源:events.py
示例14: html_news
def html_news(self):
count = self.count_of_messages_in_queue()
text = ungettext('There is %(number_of_messages)d message waiting in the <a href="%(moderation_queue_link)s">moderation queue</a>',
'There are %(number_of_messages)d waiting in the <a href="%(moderation_queue_link)s">moderation queue</a>', count) % {
'number_of_messages': count,
'moderation_queue_link': self.context.url(controller='mailinglist', action='administration', qualified=True)}
return text
开发者ID:nous-consulting,项目名称:ututi,代码行数:7,代码来源:events.py
示例15: __init__
def __init__(self, link, campaign, transaction):
self.campaign_id36 = campaign._id36
self.start_date = campaign.start_date.strftime("%m/%d/%Y")
self.end_date = campaign.end_date.strftime("%m/%d/%Y")
ndays = (campaign.end_date - campaign.start_date).days
self.duration = strings.time_label % dict(num=ndays,
time=ungettext("day", "days", ndays))
self.bid = "%.2f" % campaign.bid
self.sr = campaign.sr_name
live = campaign_is_live(link, campaign._id)
self.status = dict(
paid=bool(transaction),
complete=False,
free=campaign.is_freebie(),
pay_url=pay_url(link, campaign),
view_live_url=view_live_url(link, campaign.sr_name),
sponsor=c.user_is_sponsor,
live=live,
)
if transaction:
if transaction.is_void():
self.status['paid'] = False
self.status['free'] = False
elif transaction.is_charged():
self.status['complete'] = True
开发者ID:MichaelScarnFBI,项目名称:reddit,代码行数:27,代码来源:promote.py
示例16: invite_friends_fb
def invite_friends_fb(self):
# handle facebook callback
ids = request.params.get('ids[]')
if ids:
ids = map(int, ids.split(','))
invited = make_facebook_invitations(ids, c.user, c.user.location)
meta.Session.commit()
if invited:
h.flash(ungettext('Invited %(num)d friend.',
'Invited %(num)d friends.',
len(invited)) % dict(num=len(invited)))
redirect(url(controller='profile', action='home'))
# render page
fb_user = facebook.get_user_from_cookie(request.cookies,
config['facebook.appid'], config['facebook.secret'])
c.has_facebook = fb_user is not None
if c.has_facebook:
try:
graph = facebook.GraphAPI(fb_user['access_token'])
friends = graph.get_object("me/friends")
friend_ids = [f['id'] for f in friends['data']]
friend_users = meta.Session.query(User)\
.filter(User.facebook_id.in_(friend_ids))\
.filter(User.location == c.user.location).all()
c.exclude_ids = ','.join(str(u.facebook_id) for u in friend_users)
except facebook.GraphAPIError:
c.has_facebook = False
return render('profile/invite_friends_fb.mako')
开发者ID:nous-consulting,项目名称:ututi,代码行数:31,代码来源:base.py
示例17: invite_fb
def invite_fb(self, group):
# Handle POST.
invited = request.params.get('ids[]')
if invited:
ids = invited.split(',')
for facebook_id in ids:
group.create_pending_fb_invitation(int(facebook_id), c.user)
make_facebook_invitations(ids, c.user, group.location)
meta.Session.commit()
h.flash(ungettext('Invited %(num)d friend.',
'Invited %(num)d friends.',
len(ids)) % dict(num=len(ids)))
redirect(c.group.url(action='members'))
# Render page.
fb_user = facebook.get_user_from_cookie(request.cookies,
config['facebook.appid'], config['facebook.secret'])
c.has_facebook = fb_user is not None
if c.has_facebook:
try:
graph = facebook.GraphAPI(fb_user['access_token'])
friends = graph.get_object("me/friends")
except facebook.GraphAPIError:
c.has_facebook = False
if not c.has_facebook:
# Ask to log on to facebook.
return render('group/invite.mako')
friend_ids = [f['id'] for f in friends['data']]
friend_users = meta.Session.query(User).filter(
User.facebook_id.in_(friend_ids)).all()
c.exclude_ids = ','.join(str(u.facebook_id) for u in friend_users
if c.group.is_member(u))
return render('group/invite.mako')
开发者ID:nous-consulting,项目名称:ututi,代码行数:34,代码来源:group.py
示例18: clear_persons
def clear_persons(self, id):
item = meta.find(model.Medium, id)
cnt = 0
for person2media in item.persons_to_media:
meta.Session.delete(person2media)
cnt += 1
meta.Session.commit()
h.flash(ungettext("removed %d person", "removed %d persons", cnt) % cnt)
return redirect(url(controller="medium", action="edit", id=id))
开发者ID:dummy3k,项目名称:medienverwaltung,代码行数:10,代码来源:amazon.py
示例19: ungettext
def ungettext(self, singular, plural, count):
"""
Traduit un message en tenant compte des pluriels.
Lisez la documentation du module C{gettext} pour plus d'information.
"""
orig_translation = super(VigiloRumTranslator, self).ugettext(
singular, plural, count)
if orig_translation != singular and orig_translation != plural:
return orig_translation
return i18n.ungettext(singular, plural, count)
开发者ID:vigilo,项目名称:turbogears,代码行数:10,代码来源:translator.py
示例20: comment_label
def comment_label(num_comments=None):
if not num_comments:
# generates "comment" the imperative verb
com_label = _("comment {verb}")
com_cls = "comments empty may-blank"
else:
# generates "XX comments" as a noun
com_label = ungettext("comment", "comments", num_comments)
com_label = strings.number_label % dict(num=num_comments, thing=com_label)
com_cls = "comments may-blank"
return com_label, com_cls
开发者ID:Robert77168,项目名称:reddit,代码行数:11,代码来源:template_helpers.py
注:本文中的pylons.i18n.ungettext函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论