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

Python helper.get_translation函数代码示例

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

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



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

示例1: reset_translation

def reset_translation(request, project, subproject, lang):
    obj = get_translation(request, project, subproject, lang)

    if obj.do_reset(request):
        messages.info(request, _('All repositories have been reset.'))

    return redirect(obj)
开发者ID:fluentglobe,项目名称:our,代码行数:7,代码来源:git.py


示例2: update_translation

def update_translation(request, project, subproject, lang):
    obj = get_translation(request, project, subproject, lang)

    if obj.do_update(request):
        messages.info(request, _('All repositories were updated.'))

    return HttpResponseRedirect(obj.get_absolute_url())
开发者ID:ChrisOelmueller,项目名称:weblate,代码行数:7,代码来源:git.py


示例3: update_lock

def update_lock(request, project, subproject, lang):
    obj = get_translation(request, project, subproject, lang)

    if not obj.is_user_locked(request):
        obj.update_lock_time()

    return HttpResponse('ok')
开发者ID:camilonova,项目名称:weblate,代码行数:7,代码来源:lock.py


示例4: reset_translation

def reset_translation(request, project, subproject, lang):
    obj = get_translation(request, project, subproject, lang)

    if obj.do_reset(request):
        messages.info(request, _('All repositories have been reset.'))

    return HttpResponseRedirect(obj.get_absolute_url())
开发者ID:ChrisOelmueller,项目名称:weblate,代码行数:7,代码来源:git.py


示例5: commit_translation

def commit_translation(request, project, subproject, lang):
    obj = get_translation(request, project, subproject, lang)
    obj.commit_pending(request)

    messages.info(request, _('All pending translations were committed.'))

    return HttpResponseRedirect(obj.get_absolute_url())
开发者ID:ChrisOelmueller,项目名称:weblate,代码行数:7,代码来源:git.py


示例6: update_translation

def update_translation(request, project, subproject, lang):
    obj = get_translation(request, project, subproject, lang)

    if obj.do_update(request):
        messages.info(request, _('All repositories were updated.'))

    return redirect(obj)
开发者ID:fluentglobe,项目名称:our,代码行数:7,代码来源:git.py


示例7: commit_translation

def commit_translation(request, project, subproject, lang):
    obj = get_translation(request, project, subproject, lang)
    obj.commit_pending(request)

    messages.info(request, _('All pending translations were committed.'))

    return redirect(obj)
开发者ID:fluentglobe,项目名称:our,代码行数:7,代码来源:git.py


示例8: auto_translation

def auto_translation(request, project, subproject, lang):
    translation = get_translation(request, project, subproject, lang)
    translation.commit_pending(request)
    autoform = AutoForm(translation, request.POST)
    change = None
    if not translation.subproject.locked and autoform.is_valid():
        if autoform.cleaned_data['inconsistent']:
            units = translation.unit_set.filter_type(
                'inconsistent', translation
            )
        elif autoform.cleaned_data['overwrite']:
            units = translation.unit_set.all()
        else:
            units = translation.unit_set.filter(translated=False)

        sources = Unit.objects.filter(
            translation__language=translation.language,
            translated=True
        )
        if autoform.cleaned_data['subproject'] == '':
            sources = sources.filter(
                translation__subproject__project=translation.subproject.project
            ).exclude(
                translation=translation
            )
        else:
            subprj = SubProject.objects.get(
                project=translation.subproject.project,
                slug=autoform.cleaned_data['subproject']
            )
            sources = sources.filter(translation__subproject=subprj)

        for unit in units.iterator():
            update = sources.filter(checksum=unit.checksum)
            if update.exists():
                # Get first entry
                update = update[0]
                # No save if translation is same
                if unit.fuzzy == update.fuzzy and unit.target == update.target:
                    continue
                # Copy translation
                unit.fuzzy = update.fuzzy
                unit.target = update.target
                # Create signle change object for whole merge
                if change is None:
                    change = Change.objects.create(
                        action=Change.ACTION_AUTO,
                        translation=unit.translation,
                        user=request.user,
                        author=request.user
                    )
                # Save unit to backend
                unit.save_backend(request, False, False)

        messages.info(request, _('Automatic translation completed.'))
    else:
        messages.error(request, _('Failed to process form!'))

    return redirect(translation)
开发者ID:fluentglobe,项目名称:our,代码行数:59,代码来源:edit.py


示例9: lock_translation

def lock_translation(request, project, subproject, lang):
    obj = get_translation(request, project, subproject, lang)

    if not obj.is_user_locked(request):
        obj.create_lock(request.user, True)
        messages.info(request, _('Translation is now locked for you.'))

    return HttpResponseRedirect(obj.get_absolute_url())
开发者ID:camilonova,项目名称:weblate,代码行数:8,代码来源:lock.py


示例10: unlock_translation

def unlock_translation(request, project, subproject, lang):
    obj = get_translation(request, project, subproject, lang)

    if not obj.is_user_locked(request):
        obj.create_lock(None)
        messages.info(request, _("Translation is now open for translation updates."))

    return HttpResponseRedirect(obj.get_absolute_url())
开发者ID:kasunchathuranga,项目名称:weblate,代码行数:8,代码来源:lock.py


示例11: unlock_translation

def unlock_translation(request, project, subproject, lang):
    obj = get_translation(request, project, subproject, lang)

    if not obj.is_user_locked(request):
        obj.create_lock(None)
        messages.info(
            request,
            _('Translation is now open for translation updates.')
        )

    return redirect(obj)
开发者ID:fluentglobe,项目名称:our,代码行数:11,代码来源:lock.py


示例12: show_translation

def show_translation(request, project, subproject, lang):
    obj = get_translation(request, project, subproject, lang)
    last_changes = Change.objects.filter(
        translation=obj
    ).order_by('-timestamp')[:10]

    # Check locks
    obj.is_locked(request)

    # How much is user allowed to configure upload?
    if request.user.has_perm('trans.author_translation'):
        form = ExtraUploadForm()
    elif request.user.has_perm('trans.overwrite_translation'):
        form = UploadForm()
    else:
        form = SimpleUploadForm()

    # Is user allowed to do automatic translation?
    if request.user.has_perm('trans.automatic_translation'):
        autoform = AutoForm(obj)
    else:
        autoform = None

    # Search form for everybody
    search_form = SearchForm()

    # Review form for logged in users
    if request.user.is_anonymous():
        review_form = None
    else:
        review_form = ReviewForm(
            initial={
                'date': datetime.date.today() - datetime.timedelta(days=31)
            }
        )

    return render_to_response('translation.html', RequestContext(request, {
        'object': obj,
        'form': form,
        'autoform': autoform,
        'search_form': search_form,
        'review_form': review_form,
        'last_changes': last_changes,
        'last_changes_rss': reverse(
            'rss-translation',
            kwargs={
                'lang': obj.language.code,
                'subproject': obj.subproject.slug,
                'project': obj.subproject.project.slug
            }
        ),
    }))
开发者ID:msoftware,项目名称:weblate,代码行数:52,代码来源:basic.py


示例13: download_language_pack

def download_language_pack(request, project, subproject, lang):
    obj = get_translation(request, project, subproject, lang)
    if not obj.supports_language_pack():
        raise Http404('Language pack download not supported')

    filename, mime = obj.store.get_language_pack_meta()

    # Create response
    response = HttpResponse(
        obj.store.get_language_pack(),
        content_type=mime
    )

    # Fill in response headers
    response['Content-Disposition'] = 'attachment; filename=%s' % filename

    return response
开发者ID:spc-12,项目名称:weblate,代码行数:17,代码来源:files.py


示例14: show_translation

def show_translation(request, project, subproject, lang):
    obj = get_translation(request, project, subproject, lang)
    last_changes = Change.objects.prefetch().filter(translation=obj).order_by("-timestamp")[:10]

    # Check locks
    obj.is_locked(request)

    # How much is user allowed to configure upload?
    if request.user.has_perm("trans.author_translation"):
        form = ExtraUploadForm()
    elif request.user.has_perm("trans.overwrite_translation"):
        form = UploadForm()
    else:
        form = SimpleUploadForm()

    # Is user allowed to do automatic translation?
    if request.user.has_perm("trans.automatic_translation"):
        autoform = AutoForm(obj)
    else:
        autoform = None

    # Search form for everybody
    search_form = SearchForm()

    # Review form for logged in users
    if request.user.is_anonymous():
        review_form = None
    else:
        review_form = ReviewForm(initial={"date": datetime.date.today() - datetime.timedelta(days=31)})

    return render_to_response(
        "translation.html",
        RequestContext(
            request,
            {
                "object": obj,
                "form": form,
                "autoform": autoform,
                "search_form": search_form,
                "review_form": review_form,
                "last_changes": last_changes,
                "last_changes_url": urlencode(obj.get_kwargs()),
                "last_changes_rss": reverse("rss-translation", kwargs=obj.get_kwargs()),
            },
        ),
    )
开发者ID:spc-12,项目名称:weblate,代码行数:46,代码来源:basic.py


示例15: show_translation

def show_translation(request, project, subproject, lang):
    obj = get_translation(request, project, subproject, lang)
    last_changes = Change.objects.prefetch().filter(
        translation=obj
    ).order_by('-timestamp')[:10]

    # Check locks
    obj.is_locked(request)

    # Get form
    form = get_upload_form(request)()

    # Is user allowed to do automatic translation?
    if request.user.has_perm('trans.automatic_translation'):
        autoform = AutoForm(obj)
    else:
        autoform = None

    # Search form for everybody
    search_form = SearchForm()

    # Review form for logged in users
    if request.user.is_anonymous():
        review_form = None
    else:
        review_form = ReviewForm(
            initial={
                'date': datetime.date.today() - datetime.timedelta(days=31)
            }
        )

    return render_to_response('translation.html', RequestContext(request, {
        'object': obj,
        'form': form,
        'autoform': autoform,
        'search_form': search_form,
        'review_form': review_form,
        'last_changes': last_changes,
        'last_changes_url': urlencode(obj.get_kwargs()),
        'last_changes_rss': reverse(
            'rss-translation',
            kwargs=obj.get_kwargs(),
        ),
    }))
开发者ID:fluentglobe,项目名称:our,代码行数:44,代码来源:basic.py


示例16: auto_translation

def auto_translation(request, project, subproject, lang):
    obj = get_translation(request, project, subproject, lang)
    obj.commit_pending(request)
    autoform = AutoForm(obj, request.POST)
    change = None
    if not obj.subproject.locked and autoform.is_valid():
        if autoform.cleaned_data["inconsistent"]:
            units = obj.unit_set.filter_type("inconsistent", obj)
        elif autoform.cleaned_data["overwrite"]:
            units = obj.unit_set.all()
        else:
            units = obj.unit_set.filter(translated=False)

        sources = Unit.objects.filter(translation__language=obj.language, translated=True)
        if autoform.cleaned_data["subproject"] == "":
            sources = sources.filter(translation__subproject__project=obj.subproject.project).exclude(translation=obj)
        else:
            subprj = SubProject.objects.get(project=obj.subproject.project, slug=autoform.cleaned_data["subproject"])
            sources = sources.filter(translation__subproject=subprj)

        for unit in units.iterator():
            update = sources.filter(checksum=unit.checksum)
            if update.exists():
                # Get first entry
                update = update[0]
                # No save if translation is same
                if unit.fuzzy == update.fuzzy and unit.target == update.target:
                    continue
                # Copy translation
                unit.fuzzy = update.fuzzy
                unit.target = update.target
                # Create signle change object for whole merge
                if change is None:
                    change = Change.objects.create(
                        action=Change.ACTION_AUTO, translation=unit.translation, user=request.user
                    )
                # Save unit to backend
                unit.save_backend(request, False, False)

        messages.info(request, _("Automatic translation completed."))
    else:
        messages.error(request, _("Failed to process form!"))

    return HttpResponseRedirect(obj.get_absolute_url())
开发者ID:xyzz,项目名称:weblate,代码行数:44,代码来源:edit.py


示例17: download_translation

def download_translation(request, project, subproject, lang):
    obj = get_translation(request, project, subproject, lang)

    srcfilename = obj.get_filename()

    # Construct file name (do not use real filename as it is usually not
    # that useful)
    filename = '%s-%s-%s.%s' % (project, subproject, lang, obj.store.extension)

    # Create response
    response = HttpResponse(
        file(srcfilename).read(),
        content_type=obj.store.mimetype
    )

    # Fill in response headers
    response['Content-Disposition'] = 'attachment; filename=%s' % filename

    return response
开发者ID:spc-12,项目名称:weblate,代码行数:19,代码来源:files.py


示例18: download_translation

def download_translation(request, project, subproject, lang):
    obj = get_translation(request, project, subproject, lang)

    # Retrieve ttkit store to get extension and mime type
    store = obj.get_store()
    srcfilename = obj.get_filename()

    if store.Mimetypes is None:
        # Properties files do not expose mimetype
        mime = 'text/plain'
    else:
        mime = store.Mimetypes[0]

    if store.Extensions is None:
        # Typo in translate-toolkit 1.9, see
        # https://github.com/translate/translate/pull/10
        if hasattr(store, 'Exensions'):
            ext = store.Exensions[0]
        else:
            ext = 'txt'
    else:
        ext = store.Extensions[0]

    # Construct file name (do not use real filename as it is usually not
    # that useful)
    filename = '%s-%s-%s.%s' % (project, subproject, lang, ext)

    # Django wrapper for sending file
    wrapper = FixedFileWrapper(file(srcfilename))

    response = HttpResponse(wrapper, mimetype=mime)

    # Fill in response headers
    response['Content-Disposition'] = 'attachment; filename=%s' % filename
    response['Content-Length'] = os.path.getsize(srcfilename)

    return response
开发者ID:camilonova,项目名称:weblate,代码行数:37,代码来源:files.py


示例19: get_object

 def get_object(self, request, project, subproject, lang):
     return get_translation(request, project, subproject, lang)
开发者ID:ChrisOelmueller,项目名称:weblate,代码行数:2,代码来源:feeds.py


示例20: translate

def translate(request, project, subproject, lang):
    '''
    Generic entry point for translating, suggesting and searching.
    '''
    obj = get_translation(request, project, subproject, lang)

    # Check locks
    project_locked, user_locked, own_lock = obj.is_locked(request, True)
    locked = project_locked or user_locked

    # Search results
    search_result = search(obj, request)

    # Handle redirects
    if isinstance(search_result, HttpResponse):
        return search_result

    # Get numer of results
    num_results = len(search_result['ids'])

    # Search offset
    try:
        offset = int(request.GET.get('offset', search_result.get('offset', 0)))
    except ValueError:
        offset = 0

    # Check boundaries
    if offset < 0 or offset >= num_results:
        messages.info(request, _('You have reached end of translating.'))
        # Delete search
        del request.session['search_%s' % search_result['search_id']]
        # Redirect to translation
        return HttpResponseRedirect(obj.get_absolute_url())

    # Some URLs we will most likely use
    base_unit_url = '%s?sid=%s&offset=' % (
        obj.get_translate_url(),
        search_result['search_id'],
    )
    this_unit_url = base_unit_url + str(offset)
    next_unit_url = base_unit_url + str(offset + 1)

    response = None

    # Any form submitted?
    if request.method == 'POST' and not project_locked:

        # Handle accepting/deleting suggestions
        if ('accept' not in request.POST
                and 'delete' not in request.POST
                and 'upvote' not in request.POST
                and 'downvote' not in request.POST):
            response = handle_translate(
                obj, request, user_locked, this_unit_url, next_unit_url
            )
        elif not locked:
            response = handle_suggestions(obj, request, this_unit_url)

    # Handle translation merging
    elif 'merge' in request.GET and not locked:
        response = handle_merge(obj, request, next_unit_url)

    # Handle reverting
    elif 'revert' in request.GET and not locked:
        response = handle_revert(obj, request, this_unit_url)

    # Pass possible redirect further
    if response is not None:
        return response

    # Grab actual unit
    try:
        unit = obj.unit_set.get(pk=search_result['ids'][offset])
    except Unit.DoesNotExist:
        # Can happen when using SID for other translation
        messages.error(request, _('Invalid search string!'))
        return HttpResponseRedirect(obj.get_absolute_url())

    # Show secondary languages for logged in users
    if request.user.is_authenticated():
        secondary = request.user.get_profile().get_secondary_units(unit)
        antispam = None
    else:
        secondary = None
        antispam = AntispamForm()

    # Prepare form
    form = TranslationForm(initial={
        'checksum': unit.checksum,
        'target': (unit.translation.language, unit.get_target_plurals()),
        'fuzzy': unit.fuzzy,
    })

    return render_to_response(
        'translate.html',
        RequestContext(
            request,
            {
                'this_unit_url': this_unit_url,
                'first_unit_url': base_unit_url + '0',
#.........这里部分代码省略.........
开发者ID:Marlinc,项目名称:weblate,代码行数:101,代码来源:edit.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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