Example #1
0
def make_generic_item(request, path_obj, action, include_suggestions=False,
                      terminology=False):
    """Template variables for each row in the table.

    make_directory_item() and make_store_item() will add onto these variables."""
    try:
        stats = get_raw_stats(path_obj, include_suggestions)
        info = {
            'href': action,
            'href_todo': dispatch.translate(path_obj, state='incomplete'),
            'href_sugg': dispatch.translate(path_obj, state='suggestions'),
            'stats': stats,
            'tooltip': _('%(percentage)d%% complete' %
                         {'percentage': stats['translated']['percentage']}),
            'title': path_obj.name,
            'summary': get_item_stats(request, stats, path_obj, terminology),
        }

        errors = stats.get('errors', 0)
        if errors:
            info['errortooltip'] = ungettext('Error reading %d file', 'Error reading %d files', errors, errors)

        info.update(stats_descriptions(stats))
    except IOError, e:
        info = {
            'href': action,
            'title': path_obj.name,
            'errortooltip': e.strerror,
            'data': {'errors': 1},
            }
Example #2
0
def make_generic_item(request, path_obj, action, include_suggestions=False,
                      terminology=False):
    """Template variables for each row in the table.

    make_directory_item() and make_store_item() will add onto these variables."""
    try:
        stats = get_raw_stats(path_obj, include_suggestions)
        quick_stats = add_percentages(path_obj.getquickstats())
        info = {
            'href': action,
            'href_todo': dispatch.translate(path_obj, state='incomplete'),
            'href_sugg': dispatch.translate(path_obj, state='suggestions'),
            'stats': stats,
            'tooltip': _('%(percentage)d%% complete' %
                         {'percentage': stats['translated']['percentage']}),
            'title': path_obj.name,
            'summary': get_item_stats(request, quick_stats, path_obj, terminology),
        }

        errors = stats.get('errors', 0)
        if errors:
            info['errortooltip'] = ungettext('Error reading %d file', 'Error reading %d files', errors, errors)

        info.update(stats_descriptions(stats))
    except IOError, e:
        info = {
            'href': action,
            'title': path_obj.name,
            'errortooltip': e.strerror,
            'data': {'errors': 1},
            }
Example #3
0
def get_translation_stats(path_obj, path_stats):
    """Returns a list of statistics for ``path_obj`` ready to be displayed.

    :param path_obj: A :cls:`pootle_app.models.directory.Directory` or
                     :cls:`pootle_store.models.Store` object.
    :param path_stats: A dictionary of raw stats, as returned by
                       :func:`pootle_misc.stats.get_raw_stats`.
    """
    stats = []

    if path_stats['total']['units'] > 0:
        stats.append({
            'title': _("Total"),
            'words': _('<a href="%(url)s">%(num)d words</a>') % \
                {'url': dispatch.translate(path_obj),
                 'num': path_stats['total']['words']},
            'percentage': _("%(num)d%%") % \
                {'num': path_stats['total']['percentage']},
            'units': _("(%(num)d units)") % \
                {'num': path_stats['total']['units']}
        })

    if path_stats['translated']['units'] > 0:
        stats.append({
            'title': _("Translated"),
            'words': _('<a href="%(url)s">%(num)d words</a>') % \
                {'url': dispatch.translate(path_obj, state='translated'),
                 'num': path_stats['translated']['words']},
            'percentage': _("%(num)d%%") % \
                {'num': path_stats['translated']['percentage']},
            'units': _("(%(num)d units)") % \
                {'num': path_stats['translated']['units']}
        })

    if path_stats['fuzzy']['units'] > 0:
        stats.append({
            'title': _("Fuzzy"),
            'words': _('<a href="%(url)s">%(num)d words</a>') % \
                {'url': dispatch.translate(path_obj, state='fuzzy'),
                 'num': path_stats['fuzzy']['words']},
            'percentage': _("%(num)d%%") % \
                {'num': path_stats['fuzzy']['percentage']},
            'units': _("(%(num)d units)") % \
                {'num': path_stats['fuzzy']['units']}
        })

    if path_stats['untranslated']['units'] > 0:
        stats.append({
            'title': _("Untranslated"),
            'words': _('<a href="%(url)s">%(num)d words</a>') % \
                {'url': dispatch.translate(path_obj, state='untranslated'),
                 'num': path_stats['untranslated']['words']},
            'percentage': _("%(num)d%%") % \
                {'num': path_stats['untranslated']['percentage']},
            'units': _("(%(num)d units)") % \
                {'num': path_stats['untranslated']['units']}
        })

    return stats
Example #4
0
def get_translation_stats(path_obj, path_stats):
    """Returns a list of statistics for ``path_obj`` ready to be displayed.

    :param path_obj: A :cls:`pootle_app.models.directory.Directory` or
                     :cls:`pootle_store.models.Store` object.
    :param path_stats: A dictionary of raw stats, as returned by
                       :func:`pootle_misc.stats.get_raw_stats`.
    """
    stats = []

    if path_stats['total']['units'] > 0:
        stats.append({
            'title': _("Total"),
            'words': _('<a href="%(url)s">%(num)d words</a>') % \
                {'url': dispatch.translate(path_obj),
                 'num': path_stats['total']['words']},
            'percentage': _("%(num)d%%") % \
                {'num': path_stats['total']['percentage']},
            'units': _("(%(num)d units)") % \
                {'num': path_stats['total']['units']}
        })

    if path_stats['translated']['units'] > 0:
        stats.append({
            'title': _("Translated"),
            'words': _('<a href="%(url)s">%(num)d words</a>') % \
                {'url': dispatch.translate(path_obj, state='translated'),
                 'num': path_stats['translated']['words']},
            'percentage': _("%(num)d%%") % \
                {'num': path_stats['translated']['percentage']},
            'units': _("(%(num)d units)") % \
                {'num': path_stats['translated']['units']}
        })

    if path_stats['fuzzy']['units'] > 0:
        stats.append({
            'title': _("Fuzzy"),
            'words': _('<a href="%(url)s">%(num)d words</a>') % \
                {'url': dispatch.translate(path_obj, state='fuzzy'),
                 'num': path_stats['fuzzy']['words']},
            'percentage': _("%(num)d%%") % \
                {'num': path_stats['fuzzy']['percentage']},
            'units': _("(%(num)d units)") % \
                {'num': path_stats['fuzzy']['units']}
        })

    if path_stats['untranslated']['units'] > 0:
        stats.append({
            'title': _("Untranslated"),
            'words': _('<a href="%(url)s">%(num)d words</a>') % \
                {'url': dispatch.translate(path_obj, state='untranslated'),
                 'num': path_stats['untranslated']['words']},
            'percentage': _("%(num)d%%") % \
                {'num': path_stats['untranslated']['percentage']},
            'units': _("(%(num)d units)") % \
                {'num': path_stats['untranslated']['units']}
        })

    return stats
Example #5
0
def get_path_summary(path_obj, path_stats):
    """Returns a list of sentences to be displayed for each ``path_obj``."""
    summary = []

    if path_obj.is_dir:
        summary.append(
            ungettext("This folder has %(num)d word, %(percentage)d%% of "
                "which is translated",
                "This folder has %(num)d words, %(percentage)d%% of "
                "which are translated",
                path_stats['total']['words']) % {
                    'num': path_stats['total']['words'],
                    'percentage': path_stats['translated']['percentage']
                }
        )
    else:
        summary.append(
            ungettext("This file has %(num)d word, %(percentage)d%% of "
                "which is translated",
                "This file has %(num)d words, %(percentage)d%% of "
                "which are translated",
                path_stats['total']['words']) % {
                    'num': path_stats['total']['words'],
                    'percentage': path_stats['translated']['percentage']
                }
        )

    if path_stats['untranslated']['words'] > 0 or path_stats['fuzzy']['words'] > 0:
        num_words = path_stats['untranslated']['words'] + path_stats['fuzzy']['words']
        summary.append(
            ungettext('<a class="path-incomplete" href="%(url)s">%(num)d '
               'word needs translation</a>',
               '<a class="path-incomplete" href="%(url)s">%(num)d words '
               'need translation</a>',
               num_words) % {
                   'num': num_words,
                   'url': dispatch.translate(path_obj, state='incomplete')
               }
        )

    if path_stats['suggestions'] > 0:
        summary.append(
            ungettext('<a class="path-incomplete" href="%(url)s">%(num)d '
               'suggestion</a> needs review',
               '<a class="path-incomplete" href="%(url)s">%(num)d '
               'suggestions</a> need review',
               path_stats['suggestions']) % {
                   'num': path_stats['suggestions'],
                   'url': dispatch.translate(path_obj, state='suggestions')
               }
        )

    return summary
Example #6
0
def make_store_item(request, store, links_required=None):
    action = dispatch.translate(request, store.pootle_path)
    show_checks = links_required == 'review'
    item = make_generic_item(request, store, action, show_checks)
    if links_required == 'translate':
        item['actions'] = store_translate_links(request, store)
    elif links_required == 'review':
        item['actions'] = store_review_links(request, store)
    else:
        item['actions'] = []
    item['href_todo'] = dispatch.translate(request,
                                           store.pootle_path,
                                           unitstates=['fuzzy,untranslated'])
    item.update({'icon': 'page', 'isfile': True})
    return item
Example #7
0
def make_store_item(request, store, links_required=None, terminology=False):
    action = dispatch.translate(store)
    show_checks = links_required == 'review'
    item = make_generic_item(request, store, action, show_checks, terminology)
    if links_required == 'translate':
        item['actions'] = store_translate_links(request, store)
    elif links_required == 'review':
        item['actions'] = store_review_links(request, store)
    else:
        item['actions'] = []
    item['href_todo'] = dispatch.translate(store, state='incomplete')
    item.update({
            'icon': 'page',
            'isfile': True})
    return item
Example #8
0
def getcheckdetails(request, path_obj):
    """return a list of strings describing the results of
    checks"""
    checklinks = []
    try:
        property_stats = path_obj.getcompletestats()
        quick_stats = path_obj.getquickstats()
        total = quick_stats['total']
        keys = property_stats.keys()
        keys.sort()
        for checkname in keys:
            checkcount = property_stats[checkname]
            if total and checkcount:
                stats = ungettext(
                    '%(checks)d string (%(checkspercent)d%%) failed',
                    '%(checks)d strings (%(checkspercent)d%%) failed',
                    checkcount,
                    {"checks": checkcount,
                     "checkspercent": (checkcount * 100) / total})
                checklink = {
                    'href': dispatch.translate(
                        request, path_obj.pootle_path,
                        matchnames=[checkname]),
                    'text': checkname,
                    'stats': stats}
                checklinks += [checklink]
    except IOError:
        pass
    return checklinks
Example #9
0
def make_language_item(request, translation_project):
    href = '/%s/%s/' % (translation_project.language.code,
                        translation_project.project.code)
    href_todo = dispatch.translate(translation_project, state='incomplete')

    project_stats = get_raw_stats(translation_project)

    info = {
        'code': translation_project.language.code,
        'href': href,
        'href_todo': href_todo,
        'title': tr_lang(translation_project.language.fullname),
        'stats': project_stats,
        'lastactivity': get_last_action(translation_project),
        'tooltip': _('%(percentage)d%% complete',
                     {'percentage': project_stats['translated']['percentage']}),
    }

    errors = project_stats.get('errors', 0)

    if errors:
        info['errortooltip'] = ungettext('Error reading %d file', 'Error reading %d files', errors, errors)

    info.update(stats_descriptions(project_stats))

    return info
Example #10
0
def getcheckdetails(request, path_obj):
    """return a list of strings describing the results of
    checks"""
    checklinks = []
    try:
        property_stats = path_obj.getcompletestats()
        quick_stats = path_obj.getquickstats()
        total = quick_stats['total']
        keys = property_stats.keys()
        keys.sort()
        for checkname in keys:
            checkcount = property_stats[checkname]
            if total and checkcount:
                stats = ungettext(
                    '%(checks)d string (%(checkspercent)d%%) failed',
                    '%(checks)d strings (%(checkspercent)d%%) failed',
                    checkcount, {
                        "checks": checkcount,
                        "checkspercent": (checkcount * 100) / total
                    })
                checklink = {
                    'href':
                    dispatch.translate(request,
                                       path_obj.pootle_path,
                                       matchnames=[checkname]),
                    'text':
                    checkname,
                    'stats':
                    stats
                }
                checklinks += [checklink]
    except IOError:
        pass
    return checklinks
Example #11
0
def make_project_item(translation_project):
    project = translation_project.project
    href = translation_project.pootle_path
    href_todo = dispatch.translate(translation_project, state='incomplete')

    project_stats = get_raw_stats(translation_project)

    info = {
        'code': project.code,
        'href': href,
        'href_todo': href_todo,
        'title': project.fullname,
        'description_html': project.description_html,
        'stats': project_stats,
        'lastactivity': get_last_action(translation_project),
        'isproject': True,
        'tooltip': _('%(percentage)d%% complete',
                     {'percentage': project_stats['translated']['percentage']}),
    }

    errors = project_stats.get('errors', 0)

    if errors:
        info['errortooltip'] = ungettext('Error reading %d file',
                                         'Error reading %d files',
                                         errors, errors)

    info.update(stats_descriptions(project_stats))

    return info
Example #12
0
def make_language_item(request, translation_project):
    href = '/%s/%s/' % (translation_project.language.code,
                        translation_project.project.code)
    href_todo = dispatch.translate(translation_project, state='incomplete')

    project_stats = get_raw_stats(translation_project)

    info = {
        'code':
        translation_project.language.code,
        'href':
        href,
        'href_todo':
        href_todo,
        'title':
        tr_lang(translation_project.language.fullname),
        'stats':
        project_stats,
        'lastactivity':
        get_last_action(translation_project),
        'tooltip':
        _('%(percentage)d%% complete',
          {'percentage': project_stats['translated']['percentage']}),
    }

    errors = project_stats.get('errors', 0)

    if errors:
        info['errortooltip'] = ungettext('Error reading %d file',
                                         'Error reading %d files', errors,
                                         errors)

    info.update(stats_descriptions(project_stats))

    return info
def make_store_item(request, store, links_required=None):
    action = dispatch.translate(request, store.pootle_path)
    show_checks = links_required == 'review'
    item = make_generic_item(request, store, action, show_checks)
    if links_required == 'translate':
        item['actions'] = store_translate_links(request, store)
    elif links_required == 'review':
        item['actions'] = store_review_links(request, store)
    else:
        item['actions'] = []
    item['href_todo'] = dispatch.translate(request, store.pootle_path,
                                        unitstates=['fuzzy,untranslated'])
    item.update({
            'icon': 'page',
            'isfile': True})
    return item
Example #14
0
def translate_all_link(request, path_obj):
    #FIXME: what permissions to check for here?
    return {
        'href': dispatch.translate(request,
                                   path_obj.pootle_path,
                                   matchnames=[]),
        'text': _('Translate All')
    }
Example #15
0
def make_store_item(request, store, include_suggestions=False,
                    terminology=False):
    action = dispatch.translate(store)
    item = make_generic_item(request, store, action, include_suggestions,
                             terminology)
    item.update({
            'icon': 'page',
            'isfile': True})
    return item
def quick_link(request, path_obj):
    try:
        if path_obj.getquickstats()['translated'] < path_obj.getquickstats()['total']:
            if check_permission('translate', request):
                text = _('Quick Translate')
            else:
                text = _('View Untranslated')
            return {
                    'href': dispatch.translate(request, path_obj.pootle_path, unitstates=['fuzzy', 'untranslated']),
                    'text': text }
    except IOError:
        pass
def review_link(request, path_obj):
    try:
        if path_obj.has_suggestions():
            if check_permission('translate', request):
                text = _('Review Suggestions')
            else:
                text = _('View Suggestions')
            return { 
                    'href': dispatch.translate(request, path_obj.pootle_path, matchnames=['hassuggestion']),
                    'text': text }
    except IOError:
        pass
Example #18
0
def get_quality_check_failures(path_obj, path_stats, include_url=True):
    """Returns a list of the failed checks sorted by their importance.

    :param path_obj: An object which has the ``getcompletestats`` method.
    :param path_stats: A dictionary of raw stats, as returned by
                       :func:`pootle_misc.stats.get_raw_stats`.
    :param include_url: Whether to include URLs in the returning result
                        or not.
    """
    checks = []

    try:
        property_stats = path_obj.getcompletestats()
        total = path_stats['total']['units']
        keys = property_stats.keys()
        keys.sort(reverse=True)

        for i, category in enumerate(keys):
            checks.append({
                'checks': []
            })

            if category != Category.NO_CATEGORY:
                checks[i].update({
                    'name': category,
                    'display_name': unicode(category_names[category]),
                })

            cat_keys = property_stats[category].keys()
            cat_keys.sort()

            for checkname in cat_keys:
                checkcount = property_stats[category][checkname]

                if total and checkcount:
                    check_display = unicode(check_names.get(checkname,
                                                            checkname))
                    check = {
                        'name': checkname,
                        'display_name': check_display,
                        'count': checkcount
                    }

                    if include_url:
                        check['url'] = dispatch.translate(path_obj,
                                                          check=checkname)

                    checks[i]['checks'].append(check)
    except IOError:
        pass

    return checks
Example #19
0
def get_quality_check_failures(path_obj, path_stats, include_url=True):
    """Returns a list of the failed checks sorted by their importance.

    :param path_obj: An object which has the ``getcompletestats`` method.
    :param path_stats: A dictionary of raw stats, as returned by
                       :func:`pootle_misc.stats.get_raw_stats`.
    :param include_url: Whether to include URLs in the returning result
                        or not.
    """
    checks = []

    try:
        property_stats = path_obj.getcompletestats()
        total = path_stats['total']['units']
        keys = property_stats.keys()
        keys.sort(reverse=True)

        for i, category in enumerate(keys):
            checks.append({'checks': []})

            if category != Category.NO_CATEGORY:
                checks[i].update({
                    'name':
                    category,
                    'display_name':
                    unicode(category_names[category]),
                })

            cat_keys = property_stats[category].keys()
            cat_keys.sort()

            for checkname in cat_keys:
                checkcount = property_stats[category][checkname]

                if total and checkcount:
                    check_display = unicode(
                        check_names.get(checkname, checkname))
                    check = {
                        'name': checkname,
                        'display_name': check_display,
                        'count': checkcount
                    }

                    if include_url:
                        check['url'] = dispatch.translate(path_obj,
                                                          check=checkname)

                    checks[i]['checks'].append(check)
    except IOError:
        pass

    return checks
Example #20
0
def quick_link(request, path_obj):
    try:
        if path_obj.getquickstats()['translated'] < path_obj.getquickstats()['total']:
            if check_permission('translate', request):
                text = _('Quick Translate')
            else:
                text = _('View Untranslated')
            return {
                    'class': 'translate',
                    'href': dispatch.translate(path_obj, state='incomplete'),
                    'text': text}
    except IOError:
        pass
Example #21
0
def get_translation_stats(directory, dir_stats):
    """Returns a list of statistics ready to be displayed."""

    stats = [
        {'title': _("Total"),
         'words': _('<a href="%(url)s">%(num)d words</a>') % \
            {'url': dispatch.translate(directory),
             'num': dir_stats['total']['words']},
         'percentage': _("%(num)d%%") % \
            {'num': dir_stats['total']['percentage']},
         'units': _("(%(num)d units)") % \
            {'num': dir_stats['total']['units']} },
        {'title': _("Translated"),
         'words': _('<a href="%(url)s">%(num)d words</a>') % \
            {'url': dispatch.translate(directory, state='translated'),
             'num': dir_stats['translated']['words']},
         'percentage': _("%(num)d%%") % \
            {'num': dir_stats['translated']['percentage']},
         'units': _("(%(num)d units)") % \
            {'num': dir_stats['translated']['units']} },
        {'title': _("Fuzzy"),
         'words': _('<a href="%(url)s">%(num)d words</a>') % \
            {'url': dispatch.translate(directory, state='fuzzy'),
             'num': dir_stats['fuzzy']['words']},
         'percentage': _("%(num)d%%") % \
            {'num': dir_stats['fuzzy']['percentage']},
         'units': _("(%(num)d units)") % \
            {'num': dir_stats['fuzzy']['units']} },
        {'title': _("Untranslated"),
         'words': _('<a href="%(url)s">%(num)d words</a>') % \
            {'url': dispatch.translate(directory, state='incomplete'),
             'num': dir_stats['untranslated']['words']},
         'percentage': _("%(num)d%%") % \
            {'num': dir_stats['untranslated']['percentage']},
         'units': _("(%(num)d units)") % \
            {'num': dir_stats['untranslated']['units']} }
    ]

    return stats
Example #22
0
def review_link(request, path_obj):
    try:
        if path_obj.has_suggestions():
            if check_permission('translate', request):
                text = _('Review Suggestions')
            else:
                text = _('View Suggestions')
            return {
                    'class': 'translate',
                    'href': dispatch.translate(path_obj, suggestions=True),
                    'text': text}
    except IOError:
        pass
Example #23
0
def get_translation_stats(directory, dir_stats):
    """Returns a list of statistics ready to be displayed."""

    stats = [
        {'title': _("Total"),
         'words': _('<a href="%(url)s">%(num)d words</a>' % \
            {'url': dispatch.translate(directory),
             'num': dir_stats['total']['words']}),
         'percentage': _("%(num)d%%" % \
            {'num': dir_stats['total']['percentage']}),
         'units': _("(%(num)d units)" % \
            {'num': dir_stats['total']['units']}) },
        {'title': _("Translated"),
         'words': _('<a href="%(url)s">%(num)d words</a>' % \
            {'url': dispatch.translate(directory, state='translated'),
             'num': dir_stats['translated']['words']}),
         'percentage': _("%(num)d%%" % \
            {'num': dir_stats['translated']['percentage']}),
         'units': _("(%(num)d units)" % \
            {'num': dir_stats['translated']['units']}) },
        {'title': _("Fuzzy"),
         'words': _('<a href="%(url)s">%(num)d words</a>' % \
            {'url': dispatch.translate(directory, state='fuzzy'),
             'num': dir_stats['fuzzy']['words']}),
         'percentage': _("%(num)d%%" % \
            {'num': dir_stats['fuzzy']['percentage']}),
         'units': _("(%(num)d units)" % \
            {'num': dir_stats['fuzzy']['units']}) },
        {'title': _("Untranslated"),
         'words': _('<a href="%(url)s">%(num)d words</a>' % \
            {'url': dispatch.translate(directory, state='incomplete'),
             'num': dir_stats['untranslated']['words']}),
         'percentage': _("%(num)d%%" % \
            {'num': dir_stats['untranslated']['percentage']}),
         'units': _("(%(num)d units)" % \
            {'num': dir_stats['untranslated']['units']}) }
    ]

    return stats
Example #24
0
def make_generic_item(request, path_obj, action, include_suggestions=False, terminology=False):
    """Template variables for each row in the table.

    make_directory_item() and make_store_item() will add onto these variables."""
    try:
        stats = get_raw_stats(path_obj, include_suggestions)
        info = {
            "href": action,
            "href_todo": dispatch.translate(path_obj, state="incomplete"),
            "href_sugg": dispatch.translate(path_obj, state="suggestions"),
            "stats": stats,
            "tooltip": _("%(percentage)d%% complete", {"percentage": stats["translated"]["percentage"]}),
            "title": path_obj.name,
            "summary": get_item_stats(request, stats, path_obj, terminology),
        }

        errors = stats.get("errors", 0)
        if errors:
            info["errortooltip"] = ungettext("Error reading %d file", "Error reading %d files", errors, errors)

        info.update(stats_descriptions(stats))
    except IOError, e:
        info = {"href": action, "title": path_obj.name, "errortooltip": e.strerror, "data": {"errors": 1}}
Example #25
0
def get_quality_check_failures(path_obj, dir_stats, include_url=True):
    """Returns a list of the failed checks sorted by their importance.

    :param path_obj: An object which has the ``getcompletestats`` method.
    :param dir_stats: A dictionary of raw stats, as returned by
                      :func:`pootle_misc.stats.get_raw_stats`.
    :param include_url: Whether to include URLs in the returning result
                        or not.
    """
    checks = []
    category_map = {
        Category.CRITICAL: _("Critical"),
        Category.FUNCTIONAL: _("Functional"),
        Category.COSMETIC: _("Cosmetic"),
        Category.EXTRACTION: _("Extraction"),
        Category.NO_CATEGORY: _("No category"),
    }

    try:
        property_stats = path_obj.getcompletestats()
        total = dir_stats['total']['units']
        keys = property_stats.keys()
        keys.sort(reverse=True)

        for i, category in enumerate(keys):
            if category != Category.NO_CATEGORY:
                checks.append({'category': category,
                               'category_display': category_map[category],
                               'checks': []})

            cat_keys = property_stats[category].keys()
            cat_keys.sort()

            for checkname in cat_keys:
                checkcount = property_stats[category][checkname]

                if total and checkcount:
                    check = {'name': checkname,
                             'count': checkcount}

                    if include_url:
                        check['url'] = dispatch.translate(path_obj,
                                                          check=checkname)

                    checks[i]['checks'].append(check)
    except IOError:
        pass

    return checks
Example #26
0
 def make_stats_dict(title, state):
     return {
         'title': title,
         'words': ungettext('<a href="%(url)s">%(num)d word</a>',
                            '<a href="%(url)s">%(num)d words</a>',
                            path_stats['untranslated']['words'],
                            {'url': dispatch.translate(path_obj,
                                                       state=state),
                             'num': path_stats[state]['words']}),
         'percentage': _("%(num)d%%",
                         {'num': path_stats[state]['percentage']}),
         'units': ungettext("(%(num)d string)",
                            "(%(num)d strings)",
                            path_stats[state]['units'],
                            {'num': path_stats[state]['units']})
     }
Example #27
0
def review_link(request, path_obj):
    try:
        if path_obj.has_suggestions():
            if check_permission('translate', request):
                text = _('Review Suggestions')
            else:
                text = _('View Suggestions')
            return {
                'href':
                dispatch.translate(request,
                                   path_obj.pootle_path,
                                   matchnames=['hassuggestion']),
                'text':
                text
            }
    except IOError:
        pass
Example #28
0
def quick_link(request, path_obj):
    try:
        if path_obj.getquickstats()['translated'] < path_obj.getquickstats(
        )['total']:
            if check_permission('translate', request):
                text = _('Quick Translate')
            else:
                text = _('View Untranslated')
            return {
                'href':
                dispatch.translate(request,
                                   path_obj.pootle_path,
                                   unitstates=['fuzzy', 'untranslated']),
                'text':
                text
            }
    except IOError:
        pass
Example #29
0
def get_quality_check_failures(path_obj, dir_stats):
    """Returns a list of the failed checks sorted by their importance.
    """
    checks = []
    category_map = {
        Category.CRITICAL: _("Critical"),
        Category.FUNCTIONAL: _("Functional"),
        Category.COSMETIC: _("Cosmetic"),
        Category.EXTRACTION: _("Extraction"),
        Category.NO_CATEGORY: _("No category"),
    }

    try:
        property_stats = path_obj.getcompletestats()
        total = dir_stats['total']['units']
        keys = property_stats.keys()
        keys.sort(reverse=True)

        for i, category in enumerate(keys):
            if category != Category.NO_CATEGORY:
                checks.append({
                    'category': category,
                    'category_display': category_map[category],
                    'checks': []
                })

            cat_keys = property_stats[category].keys()
            cat_keys.sort()

            for checkname in cat_keys:
                checkcount = property_stats[category][checkname]

                if total and checkcount:
                    check = {
                        'url': dispatch.translate(path_obj, check=checkname),
                        'name': checkname,
                        'count': checkcount
                    }
                    checks[i]['checks'].append(check)
    except IOError:
        pass

    return checks
Example #30
0
def get_directory_summary(directory, dir_stats):
    """Returns a list of sentences to be displayed for each directory."""
    summary = [
        _n("This folder has %(num)d word, %(percentage)d%% of which is "
           "translated",
           "This folder has %(num)d words, %(percentage)d%% of which are "
           "translated",
           dir_stats['total']['words'],
           {'num': dir_stats['total']['words'],
            'percentage': dir_stats['translated']['percentage']}),
        _n('<a class="directory-incomplete" href="%(url)s">%(num)d word '
           'needs translation</a>',
           '<a class="directory-incomplete" href="%(url)s">%(num)d words '
           'need translation</a>',
           dir_stats['untranslated']['words'],
           {'num': dir_stats['untranslated']['words'],
            'url': dispatch.translate(directory, state='incomplete')}),
    ]

    return summary
Example #31
0
def get_quality_check_failures(path_obj, dir_stats):
    """Returns a list of the failed checks sorted by their importance.
    """
    checks = []
    category_map = {
        Category.CRITICAL: _("Critical"),
        Category.FUNCTIONAL: _("Functional"),
        Category.COSMETIC: _("Cosmetic"),
        Category.EXTRACTION: _("Extraction"),
        Category.NO_CATEGORY: _("No category"),
    }

    try:
        property_stats = path_obj.getcompletestats()
        total = dir_stats['total']['units']
        keys = property_stats.keys()
        keys.sort(reverse=True)

        for i, category in enumerate(keys):
            if category != Category.NO_CATEGORY:
                checks.append({'category': category,
                               'category_display': category_map[category],
                               'checks': []})

            cat_keys = property_stats[category].keys()
            cat_keys.sort()

            for checkname in cat_keys:
                checkcount = property_stats[category][checkname]

                if total and checkcount:
                    check = {'url': dispatch.translate(path_obj,
                                                       check=checkname),
                             'name': checkname,
                             'count': checkcount}
                    checks[i]['checks'].append(check)
    except IOError:
        pass

    return checks
Example #32
0
File: views.py Project: notz/pootle
def make_project_item(translation_project):
    project = translation_project.project
    href = translation_project.pootle_path
    href_todo = dispatch.translate(translation_project, state='incomplete')

    project_stats = get_raw_stats(translation_project)

    info = {
        'code':
        project.code,
        'href':
        href,
        'href_todo':
        href_todo,
        'title':
        project.fullname,
        'description_html':
        project.description_html,
        'stats':
        project_stats,
        'lastactivity':
        get_last_action(translation_project),
        'isproject':
        True,
        'tooltip':
        _('%(percentage)d%% complete',
          {'percentage': project_stats['translated']['percentage']}),
    }

    errors = project_stats.get('errors', 0)

    if errors:
        info['errortooltip'] = ungettext('Error reading %d file',
                                         'Error reading %d files', errors,
                                         errors)

    info.update(stats_descriptions(project_stats))

    return info
Example #33
0
def get_directory_summary(directory, dir_stats):
    """Returns a list of sentences to be displayed for each directory."""
    summary = [
        _n(
            "This folder has %(num)d word, %(percentage)d%% of which is "
            "translated",
            "This folder has %(num)d words, %(percentage)d%% of which are "
            "translated", dir_stats['total']['words'], {
                'num': dir_stats['total']['words'],
                'percentage': dir_stats['translated']['percentage']
            }),
        _n(
            '<a class="directory-incomplete" href="%(url)s">%(num)d word '
            'needs translation</a>',
            '<a class="directory-incomplete" href="%(url)s">%(num)d words '
            'need translation</a>', dir_stats['untranslated']['words'], {
                'num': dir_stats['untranslated']['words'],
                'url': dispatch.translate(directory, state='incomplete')
            }),
    ]

    return summary
Example #34
0
def translate_all_link(request, path_obj):
    #FIXME: what permissions to check for here?
    return {
        'href': dispatch.translate(
            request, path_obj.pootle_path, matchnames=[]),
        'text': _('Translate All')}
Example #35
0
def get_path_summary(path_obj, path_stats):
    """Returns a list of sentences to be displayed for each ``path_obj``."""
    summary = []
    incomplete = []
    suggestions = []

    if path_obj.is_dir:
        summary.append(
            ungettext(
                "This folder has %(num)d word, %(percentage)d%% of "
                "which is translated.",
                "This folder has %(num)d words, %(percentage)d%% of "
                "which are translated.", path_stats['total']['words']) % {
                    'num': path_stats['total']['words'],
                    'percentage': path_stats['translated']['percentage']
                })
    else:
        summary.append(
            ungettext(
                "This file has %(num)d word, %(percentage)d%% of "
                "which is translated.",
                "This file has %(num)d words, %(percentage)d%% of "
                "which are translated.", path_stats['total']['words']) % {
                    'num': path_stats['total']['words'],
                    'percentage': path_stats['translated']['percentage']
                })

    tp = path_obj.translation_project
    project = tp.project
    language = tp.language

    # Build URL for getting more summary information for the current path
    url_args = [language.code, project.code, path_obj.path]
    url_path_summary_more = reverse('tp.path_summary_more', args=url_args)

    summary.append(u''.join([
        ' <a id="js-path-summary" data-target="js-path-summary-more" '
        'href="%s">' % url_path_summary_more,
        force_unicode(_(u'Expand details')), '</a>'
    ]))

    incomplete.append(
        u'<a class="path-incomplete" href="%(url)s">' %
        {'url': dispatch.translate(path_obj, state='incomplete')})

    if path_stats['untranslated']['words'] > 0 or path_stats['fuzzy'][
            'words'] > 0:
        num_words = path_stats['untranslated']['words'] + path_stats['fuzzy'][
            'words']
        incomplete.append(
            ungettext(u'Continue translation (%(num)d word left)',
                      u'Continue translation (%(num)d words left)', num_words)
            % {
                'num': num_words,
            })
    else:
        incomplete.append(force_unicode(_('Translation is complete')))

    incomplete.append(u'</a>')

    if path_stats['suggestions'] > 0:
        suggestions.append(
            u'<a class="path-incomplete" href="%(url)s">' %
            {'url': dispatch.translate(path_obj, state='suggestions')})
        suggestions.append(
            ungettext(u'Review suggestion (%(num)d left)',
                      u'Review suggestions (%(num)d left)',
                      path_stats['suggestions']) % {
                          'num': path_stats['suggestions'],
                      })
        suggestions.append(u'</a>')

    return [u''.join(summary), u''.join(incomplete), u''.join(suggestions)]
Example #36
0
def translate_all_link(request, path_obj):
    #FIXME: what permissions to check for here?
    return {
        'class': 'translate',
        'href': dispatch.translate(path_obj),
        'text': _('Translate All')}
Example #37
0
def get_path_summary(path_obj, path_stats):
    """Returns a list of sentences to be displayed for each ``path_obj``."""
    summary = []
    incomplete = []
    suggestions = []

    if path_obj.is_dir:
        summary.append(
            ungettext("This folder has %(num)d word, %(percentage)d%% of "
                "which is translated.",
                "This folder has %(num)d words, %(percentage)d%% of "
                "which are translated.",
                path_stats['total']['words']) % {
                    'num': path_stats['total']['words'],
                    'percentage': path_stats['translated']['percentage']
                }
        )
    else:
        summary.append(
            ungettext("This file has %(num)d word, %(percentage)d%% of "
                "which is translated.",
                "This file has %(num)d words, %(percentage)d%% of "
                "which are translated.",
                path_stats['total']['words']) % {
                    'num': path_stats['total']['words'],
                    'percentage': path_stats['translated']['percentage']
                }
        )

    tp = path_obj.translation_project
    project = tp.project
    language = tp.language

    # Build URL for getting more summary information for the current path
    url_args = [language.code, project.code, path_obj.path]
    url_path_summary_more = reverse('tp.path_summary_more', args=url_args)

    summary.append(u''.join([
        ' <a id="js-path-summary" data-target="js-path-summary-more" '
        'href="%s">' % url_path_summary_more,
        force_unicode(_(u'Expand details')),
        '</a>'
    ]))


    if path_stats['untranslated']['words'] > 0 or path_stats['fuzzy']['words'] > 0:
        num_words = path_stats['untranslated']['words'] + path_stats['fuzzy']['words']
        incomplete.extend([
            u'<a class="path-incomplete" href="%(url)s">' % {
                    'url': dispatch.translate(path_obj, state='incomplete')
                },
            ungettext(u'Continue translation (%(num)d word left)',
                      u'Continue translation (%(num)d words left)',
                      num_words) % {
                          'num': num_words,
                      },
        ])
    else:
        incomplete.extend([
            u'<a class="path-incomplete" href="%(url)s">' % {
                    'url': dispatch.translate(path_obj, state='all')
                },
            force_unicode(_('Translation is complete')),
        ])

    incomplete.append(u'</a>')


    if path_stats['suggestions'] > 0:
        suggestions.append(u'<a class="path-incomplete" href="%(url)s">' % {
            'url': dispatch.translate(path_obj, state='suggestions')
        })
        suggestions.append(
            ungettext(u'Review suggestion (%(num)d left)',
                      u'Review suggestions (%(num)d left)',
                      path_stats['suggestions']) % {
                          'num': path_stats['suggestions'],
                      }
        )
        suggestions.append(u'</a>')

    return [u''.join(summary), u''.join(incomplete), u''.join(suggestions)]