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

Python tower.ngettext函数代码示例

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

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



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

示例1: summarize_validation

def summarize_validation(validation):
    """Readable summary of add-on validation results."""
    # L10n: first parameter is the number of errors
    errors = ngettext("{0} error", "{0} errors", validation.errors).format(validation.errors)
    # L10n: first parameter is the number of warnings
    warnings = ngettext("{0} warning", "{0} warnings", validation.warnings).format(validation.warnings)
    return "%s, %s" % (errors, warnings)
开发者ID:lauraxt,项目名称:zamboni,代码行数:7,代码来源:helpers.py


示例2: queue_tabnav

def queue_tabnav(context):
    """Returns tuple of tab navigation for the queue pages.

    Each tuple contains three elements: (tab_code, page_url, tab_text)
    """
    from .views import queue_counts
    counts = queue_counts()
    tabnav = [('nominated', 'queue_nominated',
               (ngettext('Full Review ({0})', 'Full Reviews ({0})',
                         counts['nominated'])
                .format(counts['nominated']))),
              ('pending', 'queue_pending',
               (ngettext('Pending Update ({0})', 'Pending Updates ({0})',
                         counts['pending'])
                .format(counts['pending']))),
              ('prelim', 'queue_prelim',
               (ngettext('Preliminary Review ({0})',
                         'Preliminary Reviews ({0})',
                         counts['prelim'])
                .format(counts['prelim']))),
              ('moderated', 'queue_moderated',
               (ngettext('Moderated Review ({0})', 'Moderated Reviews ({0})',
                         counts['moderated'])
                .format(counts['moderated'])))]

    if waffle.flag_is_active(context['request'], 'accept-webapps'):
        tabnav.append(('apps', 'queue_apps',
                       (ngettext('Apps ({0})', 'Apps ({0})', counts['apps'])
                        .format(counts['apps']))))
    return tabnav
开发者ID:chenba,项目名称:zamboni,代码行数:30,代码来源:helpers.py


示例3: clean_tags

    def clean_tags(self):
        target = [slugify(t, spaces=True)
                  for t in self.cleaned_data['tags'].split(',')]
        target = filter(None, target)

        min_len = amo.MIN_TAG_LENGTH
        max_tags = amo.MAX_TAGS
        total = len(target)

        blacklisted = []
        for tag in Tag.objects.filter(tag_text__in=target):
            if len(tag.tag_text) > 0 and tag.blacklisted:
                blacklisted.append(tag.tag_text)

        if blacklisted:
            # L10n: {0} is a single tag or a comma-separated list of tags.
            msg = ngettext('Invalid tag: {0}', 'Invalid tags: {0}',
                           len(blacklisted)).format(', '.join(blacklisted))
            raise forms.ValidationError(msg)

        if total > max_tags:
            num = total - max_tags
            msg = ngettext('You have {0} too many tags.',
                           'You have {0} too many tags.', num).format(num)
            raise forms.ValidationError(msg)

        if any(t for t in target if len(t) < amo.MIN_TAG_LENGTH):
            msg = ngettext("All tags must be at least {0} character.",
                           "All tags must be at least {0} characters.",
                           min_len).format(min_len)
            raise forms.ValidationError(msg)

        return target
开发者ID:exezaid,项目名称:zamboni,代码行数:33,代码来源:forms.py


示例4: queue_tabnav

def queue_tabnav(context):
    """Returns tuple of tab navigation for the queue pages.

    Each tuple contains three elements: (tab_code, page_url, tab_text)
    """
    from .views import queue_counts

    counts = queue_counts()
    tabnav = [('fast_track', 'queue_fast_track',
               (ngettext('Fast Track ({0})', 'Fast Track ({0})',
                         counts['fast_track'])
                .format(counts['fast_track']))),
              ('nominated', 'queue_nominated',
               (ngettext('Full Review ({0})', 'Full Reviews ({0})',
                         counts['nominated'])
                .format(counts['nominated']))),
              ('pending', 'queue_pending',
               (ngettext('Pending Update ({0})', 'Pending Updates ({0})',
                         counts['pending'])
                .format(counts['pending']))),
              ('prelim', 'queue_prelim',
               (ngettext('Preliminary Review ({0})',
                         'Preliminary Reviews ({0})',
                         counts['prelim'])
                .format(counts['prelim']))),
              ('moderated', 'queue_moderated',
               (ngettext('Moderated Review ({0})', 'Moderated Reviews ({0})',
                         counts['moderated'])
                .format(counts['moderated'])))]

    return tabnav
开发者ID:aditbiswas1,项目名称:olympia,代码行数:31,代码来源:helpers.py


示例5: render_days_since_created

 def render_days_since_created(self, row):
     if row.days_since_created == 0:
         # L10n: first argument is number of hours
         r = ngettext(u'{0} hour', u'{0} hours',
                         row.hours_since_created).format(
                                             row.hours_since_created)
     else:
         # L10n: first argument is number of days
         r = ngettext(u'{0} day', u'{0} days',
                      row.days_since_created).format(
                                             row.days_since_created)
     return jinja2.escape(r)
开发者ID:zuzelvp,项目名称:zamboni,代码行数:12,代码来源:helpers.py


示例6: clean_tags

def clean_tags(request, tags, max_tags=None):
    """
    Blocked tags are not allowed.
    Restricted tags can only be edited by Reviewers and Curators.
    """
    target = [slugify(t, spaces=True, lower=True) for t in tags.split(',')]
    target = set(filter(None, target))

    min_len = mkt.MIN_TAG_LENGTH
    max_len = Tag._meta.get_field('tag_text').max_length
    max_tags = max_tags or mkt.MAX_TAGS
    total = len(target)

    blocked = (Tag.objects.values_list('tag_text', flat=True)
               .filter(tag_text__in=target, blocked=True))
    if blocked:
        # L10n: {0} is a single tag or a comma-separated list of tags.
        msg = ngettext(u'Invalid tag: {0}', 'Invalid tags: {0}',
                       len(blocked)).format(', '.join(blocked))
        raise forms.ValidationError(msg)

    restricted = (Tag.objects.values_list('tag_text', flat=True)
                     .filter(tag_text__in=target, restricted=True))
    if restricted and not can_edit_restricted_tags(request):
        # L10n: {0} is a single tag or a comma-separated list of tags.
        msg = ngettext(u'"{0}" is a reserved tag and cannot be used.',
                       u'"{0}" are reserved tags and cannot be used.',
                       len(restricted)).format('", "'.join(restricted))
        raise forms.ValidationError(msg)
    else:
        # Admin's restricted tags don't count towards the limit.
        total = len(target - set(restricted))

    if total > max_tags:
        num = total - max_tags
        msg = ngettext(u'You have {0} too many tags.',
                       u'You have {0} too many tags.', num).format(num)
        raise forms.ValidationError(msg)

    if any(t for t in target if len(t) > max_len):
        raise forms.ValidationError(
            _(u'All tags must be %s characters '
              u'or less after invalid characters are removed.' % max_len))

    if any(t for t in target if len(t) < min_len):
        msg = ngettext(u'All tags must be at least {0} character.',
                       u'All tags must be at least {0} characters.',
                       min_len).format(min_len)
        raise forms.ValidationError(msg)

    return target
开发者ID:Witia1,项目名称:zamboni,代码行数:51,代码来源:utils.py


示例7: clean_tags

def clean_tags(request, tags):
    target = [slugify(t, spaces=True, lower=True) for t in tags.split(',')]
    target = set(filter(None, target))

    min_len = amo.MIN_TAG_LENGTH
    max_len = Tag._meta.get_field('tag_text').max_length
    max_tags = amo.MAX_TAGS
    total = len(target)

    blacklisted = (Tag.objects.values_list('tag_text', flat=True)
                      .filter(tag_text__in=target, blacklisted=True))
    if blacklisted:
        # L10n: {0} is a single tag or a comma-separated list of tags.
        msg = ngettext('Invalid tag: {0}', 'Invalid tags: {0}',
                       len(blacklisted)).format(', '.join(blacklisted))
        raise forms.ValidationError(msg)

    restricted = (Tag.objects.values_list('tag_text', flat=True)
                     .filter(tag_text__in=target, restricted=True))
    if not acl.action_allowed(request, 'Addons', 'Edit'):
        if restricted:
            # L10n: {0} is a single tag or a comma-separated list of tags.
            msg = ngettext('"{0}" is a reserved tag and cannot be used.',
                           '"{0}" are reserved tags and cannot be used.',
                           len(restricted)).format('", "'.join(restricted))
            raise forms.ValidationError(msg)
    else:
        # Admin's restricted tags don't count towards the limit.
        total = len(target - set(restricted))

    if total > max_tags:
        num = total - max_tags
        msg = ngettext('You have {0} too many tags.',
                       'You have {0} too many tags.', num).format(num)
        raise forms.ValidationError(msg)

    if any(t for t in target if len(t) > max_len):
        raise forms.ValidationError(
            _('All tags must be %s characters or less after invalid characters'
              ' are removed.' % max_len))

    if any(t for t in target if len(t) < min_len):
        msg = ngettext("All tags must be at least {0} character.",
                       "All tags must be at least {0} characters.",
                       min_len).format(min_len)
        raise forms.ValidationError(msg)

    return target
开发者ID:magopian,项目名称:olympia,代码行数:48,代码来源:forms.py


示例8: themes_commit

def themes_commit(request):
    reviewer = request.user.get_profile()
    ThemeReviewFormset = formset_factory(forms.ThemeReviewForm)
    formset = ThemeReviewFormset(request.POST)

    scores = []
    for form in formset:
        try:
            lock = ThemeLock.objects.filter(
                theme_id=form.data[form.prefix + '-theme'],
                reviewer=reviewer)
        except MultiValueDictKeyError:
            # Address off-by-one error caused by management form.
            continue
        if lock and form.is_valid():
            scores.append(form.save())

    # Success message.
    points = sum(scores)
    success = ngettext(
        # L10n: {0} is the number of reviews. {1} is the points just earned.
        # L10n: {2} is the total number of points the reviewer has overall.
        '{0} theme review successfully processed (+{1} points, {2} total).',
        '{0} theme reviews successfully processed (+{1} points, {2} total).',
        len(scores)).format(len(scores), points,
                            ReviewerScore.get_total(request.amo_user))
    amo.messages.success(request, success)

    if 'theme_redirect_url' in request.session:
        return redirect(request.session['theme_redirect_url'])
    else:
        return redirect(reverse('editors.themes.queue_themes'))
开发者ID:BavarianTomcat,项目名称:olympia,代码行数:32,代码来源:views_themes.py


示例9: clean_categories

    def clean_categories(self):
        if self.disabled:
            raise forms.ValidationError(
                _('Categories cannot be changed while your app is featured.'))

        categories = self.cleaned_data['categories']
        set_categories = set(categories.values_list('id', flat=True))

        # Supervisored categories don't count towards the max, so subtract
        # them out if there are any.
        supervisor_of = self.special_cats()
        if supervisor_of.exists():
            set_categories -= set(supervisor_of.values_list('id', flat=True))

        total = len(set_categories)
        max_cat = amo.MAX_CATEGORIES

        if total > max_cat:
            # L10n: {0} is the number of categories.
            raise forms.ValidationError(ngettext(
                'You can have only {0} category.',
                'You can have only {0} categories.',
                max_cat).format(max_cat))

        return categories
开发者ID:rtilder,项目名称:zamboni,代码行数:25,代码来源:forms.py


示例10: clean_categories

    def clean_categories(self):
        categories = self.cleaned_data['categories']
        total = categories.count()
        max_cat = amo.MAX_CATEGORIES

        if getattr(self, 'disabled', False) and total:
            if categories[0].type == amo.ADDON_WEBAPP:
                raise forms.ValidationError(loc('Categories cannot be changed '
                    'while your app is featured for this application.'))
            else:
                raise forms.ValidationError(_('Categories cannot be changed '
                    'while your add-on is featured for this application.'))
        if total > max_cat:
            # L10n: {0} is the number of categories.
            raise forms.ValidationError(ngettext(
                'You can have only {0} category.',
                'You can have only {0} categories.',
                max_cat).format(max_cat))

        has_misc = filter(lambda x: x.misc, categories)
        if has_misc and total > 1:
            raise forms.ValidationError(
                _('The miscellaneous category cannot be combined with '
                  'additional categories.'))

        return categories
开发者ID:beenishkhan,项目名称:zamboni,代码行数:26,代码来源:forms.py


示例11: queue_tabnav

def queue_tabnav(context):
    """Returns tuple of tab navigation for the queue pages.

    Each tuple contains three elements: (tab_code, page_url, tab_text)
    """
    from .views import queue_counts

    counts = queue_counts()
    tabnav = [
        (
            "fast_track",
            "queue_fast_track",
            (ngettext("Fast Track ({0})", "Fast Track ({0})", counts["fast_track"]).format(counts["fast_track"])),
        ),
        (
            "nominated",
            "queue_nominated",
            (ngettext("Full Review ({0})", "Full Reviews ({0})", counts["nominated"]).format(counts["nominated"])),
        ),
        (
            "pending",
            "queue_pending",
            (ngettext("Pending Update ({0})", "Pending Updates ({0})", counts["pending"]).format(counts["pending"])),
        ),
        (
            "prelim",
            "queue_prelim",
            (
                ngettext("Preliminary Review ({0})", "Preliminary Reviews ({0})", counts["prelim"]).format(
                    counts["prelim"]
                )
            ),
        ),
        (
            "moderated",
            "queue_moderated",
            (
                ngettext("Moderated Review ({0})", "Moderated Reviews ({0})", counts["moderated"]).format(
                    counts["moderated"]
                )
            ),
        ),
    ]

    return tabnav
开发者ID:abhiii5459,项目名称:olympia,代码行数:45,代码来源:helpers.py


示例12: queue_tabnav

def queue_tabnav(context):
    """Returns tuple of tab navigation for the queue pages.

    Each tuple contains three elements: (tab_code, page_url, tab_text)
    """
    counts = queue_counts()
    return [('apps', 'queue_pending',
             ngettext('Apps ({0})', 'Apps ({0})', counts['pending'])
             .format(counts['pending']))]
开发者ID:gkoberger,项目名称:zamboni,代码行数:9,代码来源:helpers.py


示例13: queue_tabnav

def queue_tabnav(context):
    """Returns tuple of tab navigation for the queue pages.

    Each tuple contains three elements: (tab_code, page_url, tab_text)
    """
    counts = context['queue_counts']
    unlisted_counts = context['unlisted_queue_counts']
    listed = not context.get('unlisted')

    if listed:
        tabnav = [('fast_track', 'queue_fast_track',
                   (ngettext('Fast Track ({0})',
                             'Fast Track ({0})',
                             counts['fast_track'])
                    .format(counts['fast_track']))),
                  ('nominated', 'queue_nominated',
                   (ngettext('Full Review ({0})',
                             'Full Reviews ({0})',
                             counts['nominated'])
                    .format(counts['nominated']))),
                  ('pending', 'queue_pending',
                   (ngettext('Pending Update ({0})',
                             'Pending Updates ({0})',
                             counts['pending'])
                    .format(counts['pending']))),
                  ('prelim', 'queue_prelim',
                   (ngettext('Preliminary Review ({0})',
                             'Preliminary Reviews ({0})',
                             counts['prelim'])
                    .format(counts['prelim']))),
                  ('moderated', 'queue_moderated',
                   (ngettext('Moderated Review ({0})',
                             'Moderated Reviews ({0})',
                             counts['moderated'])
                    .format(counts['moderated'])))]
    else:
        tabnav = [('nominated', 'unlisted_queue_nominated',
                   (ngettext('Unlisted Full Review ({0})',
                             'Unlisted Full Reviews ({0})',
                             unlisted_counts['nominated'])
                    .format(unlisted_counts['nominated']))),
                  ('pending', 'unlisted_queue_pending',
                   (ngettext('Unlisted Pending Update ({0})',
                             'Unlisted Pending Updates ({0})',
                             unlisted_counts['pending'])
                    .format(unlisted_counts['pending']))),
                  ('prelim', 'unlisted_queue_prelim',
                   (ngettext('Unlisted Preliminary Review ({0})',
                             'Unlisted Preliminary Reviews ({0})',
                             unlisted_counts['prelim'])
                    .format(unlisted_counts['prelim'])))]

    return tabnav
开发者ID:Nolski,项目名称:olympia,代码行数:53,代码来源:helpers.py


示例14: timesince

def timesince(t):
    """Show relative time deltas. > 7 days, fall back to babel_date."""
    diff = (datetime.datetime.now() - t)
    if diff.days > 7:
        return babel_date(t)
    elif diff.days > 0:
        return ngettext('{0} day ago', '{0} days ago',
                        diff.days).format(diff.days)
    else:
        minutes = diff.seconds / 60
        hours = minutes / 60
        if hours > 0:
            return ngettext('{0} hour ago', '{0} hours ago',
                            hours).format(hours)
        elif minutes > 0:
            return ngettext('{0} minute ago', '{0} minutes ago',
                            minutes).format(minutes)
        else:
            # L10n: This means an event that happened only a few seconds ago.
            return _('just now')
开发者ID:jlongster,项目名称:reporter,代码行数:20,代码来源:helpers.py


示例15: clean_categories

    def clean_categories(self):
        categories = self.cleaned_data['categories']
        max_cat = mkt.MAX_CATEGORIES

        if len(set(categories)) > max_cat:
            # L10n: {0} is the number of categories.
            raise forms.ValidationError(ngettext(
                'You can have only {0} category.',
                'You can have only {0} categories.',
                max_cat).format(max_cat))

        return categories
开发者ID:ujdhesa,项目名称:zamboni,代码行数:12,代码来源:forms.py


示例16: validate_categories

    def validate_categories(self, categories):
        set_categories = set(categories)
        total = len(set_categories)
        max_cat = mkt.MAX_CATEGORIES

        if total > max_cat:
            # L10n: {0} is the number of categories.
            raise serializers.ValidationError(ngettext(
                'You can have only {0} category.',
                'You can have only {0} categories.',
                max_cat).format(max_cat))

        return categories
开发者ID:waseem18,项目名称:zamboni,代码行数:13,代码来源:serializers.py


示例17: validate_categories

    def validate_categories(self, attrs, source):
        if not attrs.get('categories'):
            raise serializers.ValidationError('This field is required.')
        set_categories = set(attrs[source])
        total = len(set_categories)
        max_cat = amo.MAX_CATEGORIES

        if total > max_cat:
            # L10n: {0} is the number of categories.
            raise serializers.ValidationError(ngettext(
                'You can have only {0} category.',
                'You can have only {0} categories.',
                max_cat).format(max_cat))
        return attrs
开发者ID:aricha,项目名称:zamboni,代码行数:14,代码来源:api.py


示例18: clean_categories

    def clean_categories(self):
        categories = self.cleaned_data["categories"]
        set_categories = set(categories)
        total = len(set_categories)
        max_cat = mkt.MAX_CATEGORIES

        if total > max_cat:
            # L10n: {0} is the number of categories.
            raise forms.ValidationError(
                ngettext("You can have only {0} category.", "You can have only {0} categories.", max_cat).format(
                    max_cat
                )
            )

        return categories
开发者ID:Hitechverma,项目名称:zamboni,代码行数:15,代码来源:forms.py


示例19: clean_categories

    def clean_categories(self):
        categories = self.cleaned_data['categories']
        set_categories = set(categories.values_list('id', flat=True))

        total = len(set_categories)
        max_cat = amo.MAX_CATEGORIES

        if total > max_cat:
            # L10n: {0} is the number of categories.
            raise forms.ValidationError(ngettext(
                'You can have only {0} category.',
                'You can have only {0} categories.',
                max_cat).format(max_cat))

        return categories
开发者ID:amitdash,项目名称:zamboni,代码行数:15,代码来源:forms.py


示例20: clean_categories

    def clean_categories(self):
        categories = self.cleaned_data['categories']
        total = categories.count()
        max_cat = amo.MAX_CATEGORIES

        if self.disabled:
            raise forms.ValidationError(
                _('Categories cannot be changed while your app is featured.'))

        if total > max_cat:
            # L10n: {0} is the number of categories.
            raise forms.ValidationError(ngettext(
                'You can have only {0} category.',
                'You can have only {0} categories.',
                max_cat).format(max_cat))

        return categories
开发者ID:lauraxt,项目名称:zamboni,代码行数:17,代码来源:forms.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python tower.strip_whitespace函数代码示例发布时间:2022-05-27
下一篇:
Python tower.activate函数代码示例发布时间: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