예제 #1
0
def make_navbar_path_dict(request, path_links=None):
    def make_admin(request):
        if check_permission('admin', request):
            return {
                'href':
                dispatch.translation_project_admin(
                    request.translation_project),
                'text':
                _('Admin')
            }
        else:
            return None

    language = request.translation_project.language
    project = request.translation_project.project
    return {
        'admin': make_admin(request),
        'language': {
            'href': dispatch.open_language(request, language.code),
            'text': tr_lang(language.fullname)
        },
        'project': {
            'href':
            dispatch.open_translation_project(request, language.code,
                                              project.code),
            'text':
            project.fullname
        },
        'pathlinks': path_links
    }
예제 #2
0
def browse(request, language):
    user_tps = language.get_children_for_user(request.user)
    items = (make_project_item(tp) for tp in user_tps)

    table_fields = ['name', 'progress', 'total', 'need-translation',
                    'suggestions', 'critical', 'last-updated', 'activity']

    ctx = get_browser_context(request)
    ctx.update({
        'language': {
          'code': language.code,
          'name': tr_lang(language.fullname),
        },
        'table': {
            'id': 'language',
            'fields': table_fields,
            'headings': get_table_headings(table_fields),
            'items': items,
        },
        'stats': jsonify(request.resource_obj.get_stats_for_user(request.user)),

        'browser_extends': 'languages/base.html',
    })

    response = render(request, 'browser/index.html', ctx)
    response.set_cookie('pootle-language', language.code)

    return response
예제 #3
0
def language_index(request, language_code):
    language = get_object_or_404(Language, code=language_code)
    request.permissions = get_matching_permissions(get_profile(request.user), language.directory)

    if not check_permission("view", request):
        raise PermissionDenied

    projects = language.translationproject_set.order_by('project__fullname')
    projectcount = len(projects)
    items = (make_project_item(translate_project) for translate_project in projects.iterator())

    totals = language.getquickstats()
    average = nice_percentage(totals['translatedsourcewords'] * 100.0 / max(totals['totalsourcewords'], 1))
    topstats = gentopstats_language(language)

    templatevars = {
        'language': {
          'code': language.code,
          'name': tr_lang(language.fullname),
          'stats': ungettext('%(projects)d project, %(average)d%% translated',
                             '%(projects)d projects, %(average)d%% translated',
                             projectcount, {"projects": projectcount, "average": average}),
        },
        'feed_path': '%s/' % language.code,
        'projects': items,
        'statsheadings': get_stats_headings(),
        'topstats': topstats,
        'instancetitle': pagelayout.get_title(),
        }
    return render_to_response("language/language_index.html", templatevars, context_instance=RequestContext(request))
예제 #4
0
파일: views.py 프로젝트: Chipcius/pootle
def make_language_item(translation_project):
    href = translation_project.get_absolute_url()
    href_all = translation_project.get_translate_url()
    href_todo = translation_project.get_translate_url(state='incomplete')

    project_stats = get_raw_stats(translation_project)

    tooltip_dict = {
        'percentage': project_stats['translated']['percentage']
    }

    info = {
        'project': translation_project.project.code,
        'code': translation_project.language.code,
        'href': href,
        'href_all': href_all,
        'href_todo': href_todo,
        'title': tr_lang(translation_project.language.fullname),
        'stats': project_stats,
        'lastactivity': get_last_action(translation_project),
        'tags': translation_project.tag_like_objects,
        'pk': translation_project.pk,
        'tooltip': _('%(percentage)d%% complete', tooltip_dict),
    }

    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
예제 #5
0
파일: views.py 프로젝트: shackra/pootle
def overview(request, language):
    translation_projects = language.children \
                                   .order_by('project__fullname')
    user_tps = filter(lambda x: x.is_accessible_by(request.user),
                      translation_projects)
    items = (make_project_item(tp) for tp in user_tps)

    table_fields = [
        'name', 'progress', 'total', 'need-translation', 'suggestions',
        'critical', 'last-updated', 'activity'
    ]
    table = {
        'id': 'language',
        'fields': table_fields,
        'headings': get_table_headings(table_fields),
        'items': items,
    }

    ctx = get_overview_context(request)
    ctx.update({
        'language': {
            'code': language.code,
            'name': tr_lang(language.fullname),
        },
        'table': table,
        'stats': jsonify(request.resource_obj.get_stats()),
        'browser_extends': 'languages/base.html',
    })

    response = render(request, 'browser/overview.html', ctx)
    response.set_cookie('pootle-language', language.code)

    return response
예제 #6
0
def make_language_item(request, source_language, translation_project):
    href = '/wikitrans/%s/%s/' % (
        translation_project.language.code, translation_project.project.code)
    projectstats = add_percentages(translation_project.getquickstats())
    mt_request_form = TranslationRequestForm(
        translation_project,
        initial={'translation_project': translation_project})
    info = {
        'project_id': translation_project.id,
        'mt_request_form': mt_request_form,
        'code': translation_project.language.code,
        'href': href,
        'title': tr_lang(translation_project.language.fullname),
        'data': projectstats,
        'lastactivity': get_last_action(translation_project),
        'tooltip': _('%(percentage)d%% complete',
                     {'percentage': projectstats['translatedpercentage']}),
        # 'translator_form': MachineTranslatorSelectorForm(
        #     source_language, translation_project.language)
        'translators': MachineTranslator.get_eligible_translators(
            source_language, translation_project.language)
    }
    errors = projectstats.get('errors', 0)
    if errors:
        info['errortooltip'] = ungettext(
            'Error reading %d file', 'Error reading %d files', errors, errors)
    info.update(stats_descriptions(projectstats))
    return info
예제 #7
0
파일: views.py 프로젝트: synasius/pootle
def make_language_item(request, translation_project):
    href = translation_project.get_absolute_url()
    href_all = translation_project.get_translate_url()
    href_todo = translation_project.get_translate_url(state='incomplete')

    project_stats = get_raw_stats(translation_project)

    tooltip_dict = {'percentage': project_stats['translated']['percentage']}

    info = {
        'project': translation_project.project.code,
        'code': translation_project.language.code,
        'href': href,
        'href_all': href_all,
        'href_todo': href_todo,
        'title': tr_lang(translation_project.language.fullname),
        'stats': project_stats,
        'lastactivity': get_last_action(translation_project),
        'tags': translation_project.tags.all().order_by('name'),
        'pk': translation_project.pk,
        'tooltip': _('%(percentage)d%% complete', tooltip_dict),
    }

    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
예제 #8
0
def browse(request, language):
    user_tps = language.get_children_for_user(request.user)
    items = (make_project_item(tp) for tp in user_tps)

    table_fields = [
        'name', 'progress', 'total', 'need-translation', 'suggestions',
        'critical', 'last-updated', 'activity'
    ]

    ctx = get_browser_context(request)
    ctx.update({
        'language': {
            'code': language.code,
            'name': tr_lang(language.fullname),
        },
        'table': {
            'id': 'language',
            'fields': table_fields,
            'headings': get_table_headings(table_fields),
            'items': items,
        },
        'stats':
        jsonify(request.resource_obj.get_stats_for_user(request.user)),
        'browser_extends':
        'languages/base.html',
    })

    response = render(request, 'browser/index.html', ctx)
    response.set_cookie('pootle-language', language.code)

    return response
예제 #9
0
def make_language_item(request, translation_project):
    href = '/%s/%s/' % (translation_project.language.code,
                        translation_project.project.code)
    projectstats = add_percentages(translation_project.getquickstats())
    info = {
        'code':
        translation_project.language.code,
        'href':
        href,
        'title':
        tr_lang(translation_project.language.fullname),
        'data':
        projectstats,
        'lastactivity':
        get_last_action(translation_project),
        'tooltip':
        _('%(percentage)d%% complete',
          {'percentage': projectstats['translatedpercentage']}),
    }
    errors = projectstats.get('errors', 0)
    if errors:
        info['errortooltip'] = ungettext('Error reading %d file',
                                         'Error reading %d files', errors,
                                         errors)
    info.update(stats_descriptions(projectstats))
    return info
예제 #10
0
def overview(request, language):
    translation_projects = language.children \
                                   .order_by('project__fullname')
    user_tps = filter(lambda x: x.is_accessible_by(request.user),
                      translation_projects)
    items = (make_project_item(tp) for tp in user_tps)

    table_fields = ['name', 'progress', 'total', 'need-translation',
                    'suggestions', 'critical', 'last-updated', 'activity']
    table = {
        'id': 'language',
        'fields': table_fields,
        'headings': get_table_headings(table_fields),
        'items': items,
    }

    ctx = get_overview_context(request)
    ctx.update({
        'language': {
          'code': language.code,
          'name': tr_lang(language.fullname),
        },
        'table': table,
        'stats': jsonify(request.resource_obj.get_stats()),

        'browser_extends': 'languages/base.html',
    })

    response = render(request, 'browser/overview.html', ctx)
    response.set_cookie('pootle-language', language.code)

    return response
예제 #11
0
파일: views.py 프로젝트: DronRathore/pootle
def make_language_item(request, translation_project):
    href = '/%s/%s/' % (translation_project.language.code,
                        translation_project.project.code)
    href_all = dispatch.translate(translation_project)
    href_todo = dispatch.translate(translation_project, state='incomplete')

    project_stats = get_raw_stats(translation_project)

    tooltip_dict = {
        'percentage': project_stats['translated']['percentage']
    }

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

    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
예제 #12
0
    def cached_dict(self, locale_code='en-us', show_all=False):
        """Retrieves a sorted list of live language codes and names.

        By default only returns live languages for enabled projects, but it can
        also return live languages for disabled projects if specified.

        :param locale_code: the UI locale for which language full names need to
            be localized.
        :param show_all: tells whether to return all live languages (both for
            disabled and enabled projects) or only live languages for enabled
            projects.
        :return: an `OrderedDict`
        """
        key_prefix = 'all_cached_dict' if show_all else 'cached_dict'
        key = make_method_key(self, key_prefix, locale_code)
        languages = cache.get(key, None)
        if languages is None:
            qs = self.get_all_queryset() if show_all else self.get_queryset()
            languages = OrderedDict(
                sorted([(lang[0], tr_lang(lang[1]))
                        for lang in qs.values_list('code', 'fullname')],
                       cmp=locale.strcoll,
                       key=lambda x: x[1]))
            cache.set(key, languages, CACHE_TIMEOUT)

        return languages
예제 #13
0
파일: views.py 프로젝트: julen/pootle
def language_index(request, language_code):
    language = get_object_or_404(Language, code=language_code)
    request.permissions = get_matching_permissions(get_profile(request.user), language.directory)

    if not check_permission("view", request):
        raise PermissionDenied

    projects = language.translationproject_set.order_by('project__fullname')
    projectcount = len(projects)
    items = (make_project_item(translate_project) for translate_project in projects.iterator())

    totals = language.getquickstats()
    average = nice_percentage(totals['translatedsourcewords'] * 100.0 / max(totals['totalsourcewords'], 1))
    topstats = gentopstats_language(language)

    templatevars = {
        'language': {
          'code': language.code,
          'name': tr_lang(language.fullname),
          'description': language.description,
          'stats': ungettext('%(projects)d project, %(average)d%% translated',
                             '%(projects)d projects, %(average)d%% translated',
                             projectcount, {"projects": projectcount, "average": average}),
        },
        'feed_path': '%s/' % language.code,
        'description': language.description,
        'projects': items,
        'statsheadings': get_stats_headings(),
        'topstats': topstats,
        }
    if check_permission('administrate', request):
        from pootle_language.forms import DescriptionForm
        templatevars['form'] = DescriptionForm(instance=language)

    return render_to_response("language/language_index.html", templatevars, context_instance=RequestContext(request))
예제 #14
0
def test_language_display_name(english):
    english.fullname = ""
    english.save()

    # as fullname is not set - this should default to the pycountry name
    assert (
        english.name
        == get_language_iso_fullname(english.code))

    # lets give english a custom name in db
    english.fullname = "English (bristol twang)"
    english.save()

    # as we are translating to server lang, we use lang.fullname
    # and not the one from pycountry/iso translation
    assert (
        english.name
        == english.fullname)

    with translation.override("fr"):
        # now request lang has changed (and != server lang)
        # so we get the translated name
        assert (
            english.name
            == site_languages.get().capitalize(
                tr_lang(get_language_iso_fullname(english.code))))

    with translation.override("en-GB"):
        # as request lang is also a dialect of english
        # it uses the lang.fullname
        assert (
            english.name
            == english.fullname)
예제 #15
0
파일: models.py 프로젝트: phlax/pootle
    def cached_dict(self, locale_code='en-us', show_all=False):
        """Retrieves a sorted list of live language codes and names.

        By default only returns live languages for enabled projects, but it can
        also return live languages for disabled projects if specified.

        :param locale_code: the UI locale for which language full names need to
            be localized.
        :param show_all: tells whether to return all live languages (both for
            disabled and enabled projects) or only live languages for enabled
            projects.
        :return: an `OrderedDict`
        """
        key_prefix = 'all_cached_dict' if show_all else 'cached_dict'
        key = make_method_key(self, key_prefix, locale_code)
        languages = cache.get(key, None)
        if languages is None:
            qs = self.get_all_queryset() if show_all else self.get_queryset()
            languages = OrderedDict(
                sorted([(lang[0], tr_lang(lang[1]))
                        for lang in qs.values_list('code', 'fullname')],
                       cmp=locale.strcoll,
                       key=lambda x: x[1])
            )
            cache.set(key, languages, settings.POOTLE_CACHE_TIMEOUT)

        return languages
예제 #16
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
예제 #17
0
파일: views.py 프로젝트: julen/pootle
def directory_to_title(directory):
    """figures out if directory refers to a Language or
    TranslationProject and returns appropriate string for use in
    titles"""

    if directory.is_language():
        trans_vars = {"language": tr_lang(directory.language.fullname)}
        return _("News for %(language)s", trans_vars)
    elif directory.is_project():
        return _("News for %(project)s", {"project": directory.project.fullname})
    elif directory.is_translationproject():
        trans_vars = {
            "language": tr_lang(directory.translationproject.language.fullname),
            "project": directory.translationproject.project.fullname,
        }
        return _("News for the %(project)s project in %(language)s", trans_vars)
    return _("News for %(path)s", {"path": directory.pootle_path})
예제 #18
0
def make_navbar_path_dict(request, path_links=None):
    language = request.translation_project.language
    project = request.translation_project.project
    return {
        'language':  {'href': dispatch.open_language(language.code),
                      'text': tr_lang(language.fullname)},
        'project':   {'href': dispatch.open_translation_project(language.code, project.code),
                      'text': project.fullname},
        'pathlinks': path_links}
예제 #19
0
def directory_to_title(directory):
    """Figures out if directory refers to a Language or TranslationProject and
    returns appropriate string for use in titles."""

    if directory.is_language():
        trans_vars = {
            'language': tr_lang(directory.language.fullname),
            }
        return _('News for %(language)s', trans_vars)
    elif directory.is_project():
        return _('News for %(project)s', {'project': directory.project.fullname})
    elif directory.is_translationproject():
        trans_vars = {
            'language': tr_lang(directory.translationproject.language.fullname),
            'project': directory.translationproject.project.fullname,
            }
        return _('News for the %(project)s project in %(language)s', trans_vars)
    return _('News for %(path)s',
             {'path': directory.pootle_path})
예제 #20
0
def directory_to_title(directory):
    """Figures out if directory refers to a Language or TranslationProject and
    returns appropriate string for use in titles.
    """
    if directory.is_language():
        trans_vars = {
            'language': tr_lang(directory.language.fullname),
        }
        return _('News for %(language)s', trans_vars)
    elif directory.is_project():
        trans_vars = {
            'project': directory.project.fullname,
        }
        return _('News for %(project)s', trans_vars)
    elif directory.is_translationproject():
        trans_vars = {
            'language': tr_lang(directory.translationproject.language.fullname),
            'project': directory.translationproject.project.fullname,
        }
        return _('News for the %(project)s project in %(language)s', trans_vars)
    return _('News for %(path)s', {'path': directory.pootle_path})
예제 #21
0
 def localised_languages(self, langs):
     matches = False
     if self.request_lang:
         server_code = language_code.get()(settings.LANGUAGE_CODE)
         request_code = language_code.get()(self.request_lang)
         matches = server_code.matches(request_code)
     if matches:
         trans_func = lambda code, name: name
     else:
         trans_func = lambda code, name: self.capitalize(
             tr_lang(get_language_iso_fullname(code) or name))
     return {code: trans_func(code, name) for code, name in langs}
예제 #22
0
def overview(request, language):
    can_edit = check_permission('administrate', request)

    projects = language.translationproject_set.order_by('project__fullname')
    projectcount = len(projects)
    items = (make_project_item(translate_project)
             for translate_project in projects.iterator())

    totals = language.getquickstats()
    average = nice_percentage(totals['translatedsourcewords'] * 100.0 /
                              max(totals['totalsourcewords'], 1))
    topstats = gentopstats_language(language)

    table_fields = [
        'name', 'progress', 'total', 'need-translation', 'activity'
    ]
    table = {
        'id': 'language',
        'proportional': False,
        'fields': table_fields,
        'headings': get_table_headings(table_fields),
        'items': items,
    }

    templatevars = {
        'language': {
            'code':
            language.code,
            'name':
            tr_lang(language.fullname),
            'description':
            language.description,
            'summary':
            ungettext('%(projects)d project, %(average)d%% translated',
                      '%(projects)d projects, %(average)d%% translated',
                      projectcount, {
                          "projects": projectcount,
                          "average": average
                      }),
        },
        'feed_path': '%s/' % language.code,
        'topstats': topstats,
        'can_edit': can_edit,
        'table': table,
    }

    if can_edit:
        from pootle_language.forms import DescriptionForm
        templatevars['form'] = DescriptionForm(instance=language)

    return render_to_response("language/overview.html",
                              templatevars,
                              context_instance=RequestContext(request))
예제 #23
0
파일: views.py 프로젝트: avivian/pootle
def language_index(request, language_code):
    language = get_object_or_404(Language, code=language_code)
    request.permissions = get_matching_permissions(get_profile(request.user),
                                                   language.directory)

    if not check_permission("view", request):
        raise PermissionDenied

    can_edit = check_permission('administrate', request)

    projects = language.translationproject_set.order_by('project__fullname')
    projectcount = len(projects)
    items = (make_project_item(translate_project) for translate_project in projects.iterator())

    totals = language.getquickstats()
    average = nice_percentage(totals['translatedsourcewords'] * 100.0 / max(totals['totalsourcewords'], 1))
    topstats = gentopstats_language(language)

    table_fields = ['name', 'progress', 'total', 'need-translation', 'activity']
    table = {
        'id': 'language',
        'proportional': False,
        'fields': table_fields,
        'headings': get_table_headings(table_fields),
        'items': items,
    }

    templatevars = {
        'language': {
          'code': language.code,
          'name': tr_lang(language.fullname),
          'description_html': language.description_html,
          'summary': ungettext('%(projects)d project, %(average)d%% translated',
                               '%(projects)d projects, %(average)d%% translated',
                               projectcount, {
                                   "projects": projectcount,
                                   "average": average}),
        },
        'feed_path': '%s/' % language.code,
        'topstats': topstats,
        'can_edit': can_edit,
        'table': table,
    }

    if can_edit:
        from pootle_language.forms import DescriptionForm
        templatevars['form'] = DescriptionForm(instance=language)

    return render_to_response("language/language_index.html", templatevars,
                              context_instance=RequestContext(request))
예제 #24
0
파일: navbar_dict.py 프로젝트: notz/pootle
def make_navbar_path_dict(request, path_links=None):
    language = request.translation_project.language
    project = request.translation_project.project
    return {
        'language': {
            'href': dispatch.open_language(language.code),
            'text': tr_lang(language.fullname)
        },
        'project': {
            'href': dispatch.open_translation_project(language.code,
                                                      project.code),
            'text': project.fullname
        },
        'pathlinks': path_links
    }
예제 #25
0
파일: models.py 프로젝트: yiyibooks/pootle
 def name(self):
     """localised ISO name for the language or fullname
     if request lang == server lang, and fullname is set. Uses code
     as the ultimate fallback
     """
     site_langs = site_languages.get()
     server_code = language_code.get()(settings.LANGUAGE_CODE)
     request_code = language_code.get()(translation.get_language())
     use_db_name = (not translation.get_language() or
                    (self.fullname and server_code.matches(request_code)))
     if use_db_name:
         return self.fullname
     iso_name = get_language_iso_fullname(self.code) or self.fullname
     return (site_langs.capitalize(tr_lang(iso_name))
             if iso_name else self.code)
예제 #26
0
파일: views.py 프로젝트: pszabolcs89/pootle
def overview(request, language):
    can_edit = check_permission("administrate", request)

    translation_projects = language.get_children().order_by("project__fullname")
    user_tps = filter(lambda x: x.is_accessible_by(request.user), translation_projects)
    items = (make_project_item(tp) for tp in user_tps)

    table_fields = [
        "name",
        "progress",
        "total",
        "need-translation",
        "suggestions",
        "critical",
        "last-updated",
        "activity",
    ]
    table = {"id": "language", "fields": table_fields, "headings": get_table_headings(table_fields), "items": items}

    ctx = get_overview_context(request)
    ctx.update(
        {
            "language": {
                "code": language.code,
                "name": tr_lang(language.fullname),
                "description": language.description,
            },
            "feed_path": "%s/" % language.code,
            "can_edit": can_edit,
            "table": table,
            "browser_extends": "languages/base.html",
        }
    )

    if can_edit:
        from pootle_language.forms import DescriptionForm

        ctx.update(
            {
                "form": DescriptionForm(instance=language),
                "form_action": reverse("pootle-language-admin-settings", args=[language.code]),
            }
        )

    response = render_to_response("browser/overview.html", ctx, context_instance=RequestContext(request))
    response.set_cookie("pootle-language", language.code)

    return response
예제 #27
0
파일: views.py 프로젝트: qdinar/pootle
def overview(request, language):
    can_edit = check_permission('administrate', request)

    translation_projects = language.translationproject_set \
                                   .order_by('project__fullname')
    user_tps = filter(lambda x: x.is_accessible_by(request.user),
                      translation_projects)
    tp_count = len(user_tps)
    items = (make_project_item(tp) for tp in user_tps)

    topstats = gentopstats_language(language)

    table_fields = ['name', 'progress', 'total', 'need-translation', 'activity']
    table = {
        'id': 'language',
        'proportional': False,
        'fields': table_fields,
        'headings': get_table_headings(table_fields),
        'items': items,
    }

    templatevars = {
        'resource_obj': request.resource_obj,
        'language': {
          'code': language.code,
          'name': tr_lang(language.fullname),
          'description': language.description,
          'summary': ungettext('%(projects)d project',
                               '%(projects)d projects',
                               tp_count, {"projects": tp_count}),
        },
        'feed_path': '%s/' % language.code,
        'topstats': topstats,
        'can_edit': can_edit,
        'table': table,
    }

    if can_edit:
        from pootle_language.forms import DescriptionForm
        templatevars.update({
            'form': DescriptionForm(instance=language),
            'form_action': reverse('pootle-language-admin-settings',
                                   args=[language.code]),
        })

    return render_to_response("languages/overview.html", templatevars,
                              context_instance=RequestContext(request))
예제 #28
0
def overview(request, language):
    can_edit = check_permission('administrate', request)

    translation_projects = language.get_children() \
                                   .order_by('project__fullname')
    user_tps = filter(lambda x: x.is_accessible_by(request.user),
                      translation_projects)
    items = (make_project_item(tp) for tp in user_tps)

    table_fields = [
        'name', 'progress', 'total', 'need-translation', 'suggestions',
        'critical', 'last-updated', 'activity'
    ]
    table = {
        'id': 'language',
        'fields': table_fields,
        'headings': get_table_headings(table_fields),
        'items': items,
    }

    ctx = get_overview_context(request)
    ctx.update({
        'language': {
            'code': language.code,
            'name': tr_lang(language.fullname),
            'description': language.description,
        },
        'feed_path': '%s/' % language.code,
        'can_edit': can_edit,
        'table': table,
        'browser_extends': 'languages/base.html',
        'browser_body_id': 'languageoverview',
    })

    if can_edit:
        from pootle_language.forms import DescriptionForm
        ctx.update({
            'form':
            DescriptionForm(instance=language),
            'form_action':
            reverse('pootle-language-admin-settings', args=[language.code]),
        })

    return render_to_response("browser/overview.html",
                              ctx,
                              context_instance=RequestContext(request))
예제 #29
0
def make_language_item(request, translation_project):
    href = '/%s/%s/' % (translation_project.language.code, translation_project.project.code)
    projectstats = add_percentages(translation_project.getquickstats())
    info = {
        'code': translation_project.language.code,
        'href': href,
        'title': tr_lang(translation_project.language.fullname),
        'data': projectstats,
        'lastactivity': get_last_action(translation_project),
        'tooltip': _('%(percentage)d%% complete',
                     {'percentage': projectstats['translatedpercentage']}),
    }
    errors = projectstats.get('errors', 0)
    if errors:
        info['errortooltip'] = ungettext('Error reading %d file', 'Error reading %d files', errors, errors)
    info.update(stats_descriptions(projectstats))
    return info
예제 #30
0
파일: utils.py 프로젝트: arky/pootle
 def localised_languages(self, langs):
     matches = False
     if self.request_lang:
         server_code = language_code.get()(settings.LANGUAGE_CODE)
         request_code = language_code.get()(self.request_lang)
         matches = server_code.matches(request_code)
     if matches:
         trans_func = lambda code, name: name
     else:
         trans_func = lambda code, name: self.capitalize(
             tr_lang(
                 get_language_iso_fullname(code)
                 or name))
     return {
         code: trans_func(code, name)
         for code, name
         in langs}
예제 #31
0
def make_navbar_path_dict(request, path_links=None):
    def make_admin(request):
        if check_permission('admin', request):
            return {'href': dispatch.translation_project_admin(request.translation_project),
                    'text': _('Admin')}
        else:
            return None

    language     = request.translation_project.language
    project      = request.translation_project.project
    return {
        'admin':     make_admin(request),
        'language':  {'href': dispatch.open_language(request, language.code),
                      'text': tr_lang(language.fullname)},
        'project':   {'href': dispatch.open_translation_project(request, language.code, project.code),
                      'text': project.fullname},
        'pathlinks': path_links }
예제 #32
0
def overview(request, language):
    can_edit = check_permission("administrate", request)

    translation_projects = language.translationproject_set.order_by("project__fullname")
    user_tps = filter(lambda x: x.is_accessible_by(request.user), translation_projects)
    tp_count = len(user_tps)
    items = (make_project_item(tp) for tp in user_tps)

    totals = language.getquickstats()
    average = nice_percentage(totals["translatedsourcewords"], totals["totalsourcewords"])
    topstats = gentopstats_language(language)

    table_fields = ["name", "progress", "total", "need-translation", "activity"]
    table = {
        "id": "language",
        "proportional": False,
        "fields": table_fields,
        "headings": get_table_headings(table_fields),
        "items": items,
    }

    templatevars = {
        "language": {
            "code": language.code,
            "name": tr_lang(language.fullname),
            "description": language.description,
            "summary": ungettext(
                "%(projects)d project, %(average)d%% translated",
                "%(projects)d projects, %(average)d%% translated",
                tp_count,
                {"projects": tp_count, "average": average},
            ),
        },
        "feed_path": "%s/" % language.code,
        "topstats": topstats,
        "can_edit": can_edit,
        "table": table,
    }

    if can_edit:
        from pootle_language.forms import DescriptionForm

        templatevars["form"] = DescriptionForm(instance=language)

    return render_to_response("language/overview.html", templatevars, context_instance=RequestContext(request))
예제 #33
0
파일: views.py 프로젝트: JMassapina/pootle
def make_language_item(translation_project):
    href = translation_project.get_absolute_url()
    href_all = translation_project.get_translate_url()
    href_todo = translation_project.get_translate_url(state='incomplete')

    info = {
        'project': translation_project.project.code,
        'code': translation_project.code,
        'href': href,
        'href_all': href_all,
        'href_todo': href_todo,
        'title': tr_lang(translation_project.language.fullname),
        'lastactivity': get_last_action(translation_project),
        'tags': translation_project.tag_like_objects,
        'pk': translation_project.pk,
    }

    return info
예제 #34
0
파일: views.py 프로젝트: qdinar/pootle
    def _make_lang_item(tp):
        href = tp.get_absolute_url()
        href_all = tp.get_translate_url()
        href_todo = tp.get_translate_url(state="incomplete")

        info = {
            "project": tp.project.code,
            "code": tp.code,
            "href": href,
            "href_all": href_all,
            "href_todo": href_todo,
            "title": tr_lang(tp.language.fullname),
            "lastactivity": get_last_action(tp),
            "tags": tp.tag_like_objects,
            "pk": tp.pk,
        }

        return info
예제 #35
0
    def cached_dict(self, locale_code='en-us'):
        """Retrieves a sorted list of live language codes and names.

        :param locale_code: the UI locale for which language full names need to
            be localized.
        :return: an `OrderedDict`
        """
        key = make_method_key(self, 'cached_dict', locale_code)
        languages = cache.get(key, None)
        if languages is None:
            languages = OrderedDict(
                sorted([(lang[0], tr_lang(lang[1]))
                        for lang in self.values_list('code', 'fullname')],
                       cmp=locale.strcoll,
                       key=lambda x: x[1]))
            cache.set(key, languages, settings.POOTLE_CACHE_TIMEOUT)

        return languages
예제 #36
0
파일: views.py 프로젝트: JMassapina/pootle
def make_language_item(translation_project):
    href = translation_project.get_absolute_url()
    href_all = translation_project.get_translate_url()
    href_todo = translation_project.get_translate_url(state='incomplete')

    info = {
        'project': translation_project.project.code,
        'code': translation_project.code,
        'href': href,
        'href_all': href_all,
        'href_todo': href_todo,
        'title': tr_lang(translation_project.language.fullname),
        'lastactivity': get_last_action(translation_project),
        'tags': translation_project.tag_like_objects,
        'pk': translation_project.pk,
    }

    return info
예제 #37
0
파일: views.py 프로젝트: AmesianX/pootle
def overview(request, language):
    can_edit = check_permission('administrate', request)

    translation_projects = language.get_children() \
                                   .order_by('project__fullname')
    user_tps = filter(lambda x: x.is_accessible_by(request.user),
                      translation_projects)
    items = (make_project_item(tp) for tp in user_tps)

    table_fields = ['name', 'progress', 'total', 'need-translation',
                    'suggestions', 'critical', 'last-updated', 'activity']
    table = {
        'id': 'language',
        'fields': table_fields,
        'headings': get_table_headings(table_fields),
        'items': items,
    }

    ctx = get_overview_context(request)
    ctx.update({
        'language': {
          'code': language.code,
          'name': tr_lang(language.fullname),
          'description': language.description,
        },
        'feed_path': '%s/' % language.code,
        'can_edit': can_edit,
        'table': table,

        'browser_extends': 'languages/base.html',
    })

    if can_edit:
        from pootle_language.forms import DescriptionForm
        ctx.update({
            'form': DescriptionForm(instance=language),
            'form_action': reverse('pootle-language-admin-settings',
                                   args=[language.code]),
        })

    response = render(request, "browser/overview.html", ctx)
    response.set_cookie('pootle-language', language.code)

    return response
예제 #38
0
파일: views.py 프로젝트: JMassapina/pootle
def overview(request, language):
    can_edit = check_permission("administrate", request)

    translation_projects = language.translationproject_set.order_by("project__fullname")
    user_tps = filter(lambda x: x.is_accessible_by(request.user), translation_projects)
    tp_count = len(user_tps)
    items = (make_project_item(tp) for tp in user_tps)

    topstats = gentopstats_language(language)

    table_fields = ["name", "progress", "total", "need-translation", "activity"]
    table = {
        "id": "language",
        "proportional": False,
        "fields": table_fields,
        "headings": get_table_headings(table_fields),
        "items": items,
    }

    templatevars = {
        "resource_obj": request.resource_obj,
        "language": {
            "code": language.code,
            "name": tr_lang(language.fullname),
            "description": language.description,
            "summary": ungettext("%(projects)d project", "%(projects)d projects", tp_count, {"projects": tp_count}),
        },
        "feed_path": "%s/" % language.code,
        "topstats": topstats,
        "can_edit": can_edit,
        "table": table,
    }

    if can_edit:
        from pootle_language.forms import DescriptionForm

        templatevars.update(
            {
                "form": DescriptionForm(instance=language),
                "form_action": reverse("pootle-language-admin-settings", args=[language.code]),
            }
        )

    return render_to_response("languages/overview.html", templatevars, context_instance=RequestContext(request))
예제 #39
0
파일: models.py 프로젝트: SweetLion/pootle
    def cached_dict(self, locale_code='en-us'):
        """Retrieves a sorted list of live language codes and names.

        :param locale_code: the UI locale for which language full names need to
            be localized.
        :return: an `OrderedDict`
        """
        key = make_method_key(self, 'cached_dict', locale_code)
        languages = cache.get(key, None)
        if languages is None:
            languages = OrderedDict(
                sorted([(lang[0], tr_lang(lang[1]))
                        for lang in self.values_list('code', 'fullname')],
                        cmp=locale.strcoll,
                        key=lambda x: x[1])
            )
            cache.set(key, languages, settings.OBJECT_CACHE_TIMEOUT)

        return languages
예제 #40
0
파일: views.py 프로젝트: atassumer/pootle
    def _make_lang_item(tp):
        href = tp.get_absolute_url()
        href_all = tp.get_translate_url()
        href_todo = tp.get_translate_url(state="incomplete")
        href_sugg = tp.get_translate_url(state='suggestions')

        info = {
            'project': tp.project.code,
            'code': tp.code,
            'href': href,
            'href_all': href_all,
            'href_todo': href_todo,
            'href_sugg': href_sugg,
            'icon': 'language',
            'title': tr_lang(tp.language.fullname),
            'lastactivity': get_last_action(tp),
            'tags': tp.tag_like_objects,
            'pk': tp.pk,
        }

        return info
예제 #41
0
def make_language_item(request, source_language, translation_project):
    href = '/%s/%s/' % (translation_project.language.code,
                        translation_project.project.code)
    projectstats = add_percentages(translation_project.getquickstats())
    mt_request_form = TranslationRequestForm(
        translation_project,
        initial={'translation_project': translation_project})
    info = {
        'project_id':
        translation_project.id,
        'mt_request_form':
        mt_request_form,
        'code':
        translation_project.language.code,
        'href':
        href,
        'title':
        tr_lang(translation_project.language.fullname),
        'data':
        projectstats,
        'lastactivity':
        get_last_action(translation_project),
        'tooltip':
        _('%(percentage)d%% complete',
          {'percentage': projectstats['translatedpercentage']}),
        #'translator_form': MachineTranslatorSelectorForm(source_language, translation_project.language)
        'translators':
        MachineTranslator.get_eligible_translators(
            source_language, translation_project.language)
    }
    errors = projectstats.get('errors', 0)
    if errors:
        info['errortooltip'] = ungettext('Error reading %d file',
                                         'Error reading %d files', errors,
                                         errors)
    info.update(stats_descriptions(projectstats))
    return info
예제 #42
0
파일: results.py 프로젝트: sshyran/zing
 def language_name(self):
     return tr_lang(self.unit["store__translation_project__language__fullname"])
예제 #43
0
파일: models.py 프로젝트: fourks/pootle
 def name(self):
     """Localized fullname for the language."""
     return tr_lang(self.fullname)
예제 #44
0
 def localname(self):
     """localized fullname"""
     return tr_lang(self.fullname)
예제 #45
0
 def localname(self):
     """localized fullname"""
     return tr_lang(self.fullname)
예제 #46
0
파일: views.py 프로젝트: ainslied/pootle
 def language(self):
     return {
         'code': self.object.code,
         'name': tr_lang(self.object.fullname)}
예제 #47
0
def view(request):
    """Render a nested list like this::

        contributors = [
          ('french', [
            ('Hackaraus', ['Auser Name', 'username2', ...]),
            ('Project 2', ['username1', 'usernameX', ...]),
            ...
            ]),
          ('spanish', [
            ('Project 1', ['User 1', 'User2', ...]),
            ('Project 2', ['User 1', 'UserX', ...]),
            ...
            ]),
        ]
    """

    exclude_project_names = getattr(
        settings,
        'CONTRIBUTORS_EXCLUDED_PROJECT_NAMES',
        []
    )
    excluded_names = set(getattr(
        settings,
        'CONTRIBUTORS_EXCLUDED_NAMES',
        []
    ))

    user_names = {}  # user id -> name
    _skip_users = set()
    for user in (User.objects.all()
                 .values('id', 'first_name', 'last_name', 'username')):
        if excluded_names:
            names = [user[e] for e in ['username', 'first_name', 'last_name']]
            if set(names) & excluded_names:
                _skip_users.add(user['id'])
                continue
        name = ('%s %s' % (user['first_name'], user['last_name'])).strip()
        if not name:
            name = user['username']
        user_names[user['id']] = name

    language_names = {}  # language id -> name
    for language in Language.objects.all().values('id', 'fullname'):
        language_names[language['id']] = tr_lang(language['fullname'])

    project_names = {}  # project id -> name
    for project in (Project.objects
                    .exclude(fullname__in=exclude_project_names)
                    .values('id', 'fullname')):
        project_names[project['id']] = project['fullname']

    # map users to projects per language across:
    # submitters, suggesters and reviewers
    languages = {}
    tp_to_lang_id = {}
    tp_to_proj_id = {}

    # prepare a map of TranslationProject IDs to
    # language and project to save queries for later
    for tp in (TranslationProject.objects.all()
               .values('id', 'language_id', 'project_id')):
        tp_to_lang_id[tp['id']] = tp['language_id']
        tp_to_proj_id[tp['id']] = tp['project_id']

    for model, user_key in ((Submission, 'submitter_id'),
                            (Suggestion, 'suggester_id'),
                            (Suggestion, 'reviewer_id')):
        for item in (model.objects.all()
                     .values('translation_project_id', user_key)
                     .distinct()):
            lang_id = tp_to_lang_id[item['translation_project_id']]
            proj_id = tp_to_proj_id[item['translation_project_id']]
            user_id = item[user_key]
            if not user_id:  # bad paste on_delete cascades
                continue
            if lang_id not in languages:
                languages[lang_id] = {}
            if proj_id not in languages[lang_id]:
                languages[lang_id][proj_id] = set()
            languages[lang_id][proj_id].add(user_id)

    # finally, turn this massive dict into a list of lists of lists
    # to be used in the template to loop over.
    # also change from IDs to real names
    contributors = []
    for lang_id, projectsmap in languages.items():
        language = language_names[lang_id]
        projects = []
        users = None
        for proj_id, user_ids in projectsmap.items():
            usersset = [user_names[x] for x in user_ids
                                      if x not in _skip_users]
            users = sorted(usersset, lambda x, y: cmp(x.lower(), y.lower()))
            try:
                projectname = project_names[proj_id]
            except KeyError:
                # some legacy broken project or excluded
                continue
            if users:
                projects.append((projectname, users))
        if projects:
            contributors.append((language, projects))
    contributors.sort()

    ctx = {
        'contributors': contributors,
    }

    return render(request, 'about/contributors.html', ctx)
예제 #48
0
파일: models.py 프로젝트: JMassapina/pootle
 def name(self):
     """Localized fullname for the language."""
     return tr_lang(self.fullname)
예제 #49
0
파일: views.py 프로젝트: pavels/pootle
 def language(self):
     return {"code": self.object.code, "name": tr_lang(self.object.fullname)}
예제 #50
0
파일: views.py 프로젝트: sjhale/pootle
 def language(self):
     return {
         'code': self.object.code,
         'name': tr_lang(self.object.fullname)
     }
예제 #51
0
파일: views.py 프로젝트: oioudina/zing
 def language(self):
     return {"code": self.object.code, "name": tr_lang(self.object.fullname)}