• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python tower.ungettext函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tower.ungettext函数的典型用法代码示例。如果您正苦于以下问题:Python ungettext函数的具体用法?Python ungettext怎么用?Python ungettext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了ungettext函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: date_diff

def date_diff(timestamp, to=None):
    if not timestamp:
        return ""

    compare_with = to or datetime.date.today()
    delta = timestamp - compare_with

    if delta.days == 0:
        return u"today"
    elif delta.days == -1:
        return u"yesterday"
    elif delta.days == 1:
        return u"tomorrow"

    chunks = (
        (365.0, lambda n: ungettext("year", "years", n)),
        (30.0, lambda n: ungettext("month", "months", n)),
        (7.0, lambda n: ungettext("week", "weeks", n)),
        (1.0, lambda n: ungettext("day", "days", n)),
    )

    for i, (chunk, name) in enumerate(chunks):
        if abs(delta.days) >= chunk:
            count = abs(round(delta.days / chunk, 0))
            break

    date_str = ugettext("%(number)d %(type)s") % {"number": count, "type": name(count)}

    if delta.days > 0:
        return "in " + date_str
    else:
        return date_str + " ago"
开发者ID:fwenzel,项目名称:mdn,代码行数:32,代码来源:helpers.py


示例2: date_diff

def date_diff(timestamp, to=None):
    if not timestamp:
        return ""

    compare_with = to or datetime.date.today()
    delta = timestamp - compare_with

    if delta.days == 0:
        return u"today"
    elif delta.days == -1:
        return u"yesterday"
    elif delta.days == 1:
        return u"tomorrow"

    chunks = (
        (365.0, lambda n: ungettext('year', 'years', n)),
        (30.0, lambda n: ungettext('month', 'months', n)),
        (7.0, lambda n: ungettext('week', 'weeks', n)),
        (1.0, lambda n: ungettext('day', 'days', n)),
    )

    for i, (chunk, name) in enumerate(chunks):
        if abs(delta.days) >= chunk:
            count = abs(round(delta.days / chunk, 0))
            break

    date_str = (ugettext('%(number)d %(type)s') %
                        {'number': count, 'type': name(count)})

    if delta.days > 0:
        return "in " + date_str
    else:
        return date_str + " ago"
开发者ID:g1angel,项目名称:kuma,代码行数:33,代码来源:helpers.py


示例3: get_locked_legend_alternate

def get_locked_legend_alternate(count, level):
    if level == 1:
        return FIRST_CHALLENGE
    
    # L10n: Legend associated to a locked challenge. Example: "Complete 4 more challenges in Level 3 to unlock."
    msg = ungettext('Complete %(count)d more challenge in Level %(level)d to unlock.',
                    'Complete %(count)d more challenges in Level %(level)d to unlock.', count)

    return msg % {'count': count, 'level': level}
开发者ID:mozilla,项目名称:spark,代码行数:9,代码来源:utils.py


示例4: timesince

def timesince(d, now=None):
    """Take two datetime objects and return the time between d and now as a
    nicely formatted string, e.g. "10 minutes". If d is None or occurs after
    now, return ''.

    Units used are years, months, weeks, days, hours, and minutes. Seconds and
    microseconds are ignored. Just one unit is displayed. For example,
    "2 weeks" and "1 year" are possible outputs, but "2 weeks, 3 days" and "1
    year, 5 months" are not.

    Adapted from django.utils.timesince to have better i18n (not assuming
    commas as list separators and including "ago" so order of words isn't
    assumed), show only one time unit, and include seconds.

    """
    if d is None:
        return u''
    chunks = [
        (60 * 60 * 24 * 365, lambda n: ungettext('%(number)d year ago',
                                                 '%(number)d years ago', n)),
        (60 * 60 * 24 * 30, lambda n: ungettext('%(number)d month ago',
                                                '%(number)d months ago', n)),
        (60 * 60 * 24 * 7, lambda n: ungettext('%(number)d week ago',
                                               '%(number)d weeks ago', n)),
        (60 * 60 * 24, lambda n: ungettext('%(number)d day ago',
                                           '%(number)d days ago', n)),
        (60 * 60, lambda n: ungettext('%(number)d hour ago',
                                      '%(number)d hours ago', n)),
        (60, lambda n: ungettext('%(number)d minute ago',
                                 '%(number)d minutes ago', n)),
        (1, lambda n: ungettext('%(number)d second ago',
                                 '%(number)d seconds ago', n))]
    if not now:
        if d.tzinfo:
            now = datetime.datetime.now(LocalTimezone(d))
        else:
            now = datetime.datetime.now()

    # Ignore microsecond part of 'd' since we removed it from 'now'
    delta = now - (d - datetime.timedelta(0, 0, d.microsecond))
    since = delta.days * 24 * 60 * 60 + delta.seconds
    if since <= 0:
        # d is in the future compared to now, stop processing.
        return u''
    for i, (seconds, name) in enumerate(chunks):
        count = since // seconds
        if count != 0:
            break
    return name(count) % {'number': count}
开发者ID:g1angel,项目名称:kuma,代码行数:49,代码来源:helpers.py


示例5: send_pending_membership_emails

def send_pending_membership_emails():
    """
    For each curated group that has pending memberships that the curators have
    not yet been emailed about, send to all the curators an email with the count
    of all pending memberships and a link to view and manage the requests.
    """
    Group = get_model('groups', 'Group')
    GroupMembership = get_model('groups', 'GroupMembership')

    # Curated groups that have pending membership requests
    groups = Group.objects.exclude(curators__isnull=True)
    groups = groups.filter(groupmembership__status=GroupMembership.PENDING).distinct()

    for group in groups:
        # what's the max pk of pending memberships?
        pending_memberships = group.groupmembership_set.filter(status=GroupMembership.PENDING)
        max_pk = pending_memberships.aggregate(max_pk=Max('pk'))['max_pk']
        # Only send reminder if there are newer requests than we'd previously reminded about
        if max_pk > group.max_reminder:
            # TODO: Switch locale to curator's preferred language so translation will occur
            # Using English for now
            tower.activate('en-us')

            count = pending_memberships.count()
            subject = tower.ungettext(
                '%(count)d outstanding request to join Mozillians group "%(name)s"',
                '%(count)d outstanding requests to join Mozillians group "%(name)s"',
                count
            ) % {
                'count': count,
                'name': group.name
            }
            body = render_to_string('groups/email/memberships_pending.txt', {
                'group': group,
                'count': count,
            })

            send_mail(subject, body, settings.FROM_NOREPLY,
                      [profile.user.email for profile in group.curators.all()],
                      fail_silently=False)

            group.max_reminder = max_pk
            group.save()
开发者ID:GVRGowtham,项目名称:mozillians,代码行数:43,代码来源:tasks.py


示例6: delete

def delete(request, template, msgid=None, msgtype='inbox'):
    if msgid:
        msgids = [msgid]
    else:
        try:
            msgids = [int(m) for m in request.POST.getlist('id')]
        except ValueError:
            return HttpResponseBadRequest()

    if msgtype == 'inbox':
        messages = InboxMessage.objects.filter(pk__in=msgids, to=request.user)
    else:
        messages = OutboxMessage.objects.filter(pk__in=msgids,
                                                sender=request.user)

    if request.method == 'POST' and 'confirmed' in request.POST:
        if messages.count() != len(msgids):
            contrib_messages.add_message(request, contrib_messages.ERROR,
                                         _("Messages didn't add up. Try again."))
        else:
            messages.delete()
            msg = ungettext(u'The message was deleted!',
                            u'The messages were deleted!',
                            len(msgids))
            contrib_messages.add_message(request, contrib_messages.SUCCESS,
                                         msg)

        if request.is_ajax():
            return HttpResponse(json.dumps({'message': m} for m in messages))

        return HttpResponseRedirect(reverse('messages.{t}'.format(t=msgtype)))

    if msgtype == 'outbox':
        for message in messages:
            _add_recipients(message)

    return render(request, template, {
        'msgs': messages, 'msgid': msgid, 'msgtype': msgtype})
开发者ID:MarkSchmidty,项目名称:kitsune,代码行数:38,代码来源:views.py


示例7: get_locked_legend

def get_locked_legend(count, level):
    # L10n: Legend associated to a locked challenge. Example: "You must complete at least 1 challenge in Level 1 to unlock this level."
    msg = ungettext('You must complete at least %(count)d challenge in Level %(level)d to unlock this level.',
                    'You must complete at least %(count)d challenges in Level %(level)d to unlock this level.', count)

    return msg % {'count': count, 'level': level}
开发者ID:mozilla,项目名称:spark,代码行数:6,代码来源:utils.py


示例8: get_locked_legend

def get_locked_legend(count, level):
    # L10n: Legend associated to a locked challenge. Example: "Complete 4 more challenges in level 3 to unlock."
    msg = ungettext('Complete %(count)d more challenge in level %(level)d to unlock.',
                    'Complete %(count)d more challenges in level %(level)d to unlock.', count)
    
    return msg % {'count': count, 'level': level}
开发者ID:ryansnyder,项目名称:spark,代码行数:6,代码来源:challenges.py



注:本文中的tower.ungettext函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tower_cli.get_resource函数代码示例发布时间:2022-05-27
下一篇:
Python tower.strip_whitespace函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap