예제 #1
0
def download_translation_file(translation, fmt=None):
    if fmt is not None:
        try:
            exporter = get_exporter(fmt)(translation=translation)
        except KeyError:
            raise Http404('File format not supported')
        exporter.add_units(translation)
        return exporter.get_response(
            '{{project}}-{0}-{{language}}.{{extension}}'.format(
                translation.subproject.slug))

    srcfilename = translation.get_filename()

    # Construct file name (do not use real filename as it is usually not
    # that useful)
    filename = '{0}-{1}-{2}.{3}'.format(translation.subproject.project.slug,
                                        translation.subproject.slug,
                                        translation.language.code,
                                        translation.store.extension)

    # Create response
    with open(srcfilename) as handle:
        response = HttpResponse(handle.read(),
                                content_type=translation.store.mimetype)

    # Fill in response headers
    response['Content-Disposition'] = 'attachment; filename={0}'.format(
        filename)

    return response
예제 #2
0
def download_translation_file(translation, fmt=None):
    if fmt is not None:
        try:
            exporter = get_exporter(fmt)(translation=translation)
        except KeyError:
            raise Http404('File format not supported')
        exporter.add_units(translation)
        return exporter.get_response(
            '{{project}}-{0}-{{language}}.{{extension}}'.format(
                translation.subproject.slug
            )
        )

    srcfilename = translation.get_filename()

    # Construct file name (do not use real filename as it is usually not
    # that useful)
    filename = '{0}-{1}-{2}.{3}'.format(
        translation.subproject.project.slug,
        translation.subproject.slug,
        translation.language.code,
        translation.store.extension
    )

    # Create response
    with open(srcfilename) as handle:
        response = HttpResponse(
            handle.read(),
            content_type=translation.store.mimetype
        )

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

    return response
예제 #3
0
def download_dictionary(request, project, lang):
    """Export dictionary into various formats."""
    prj = get_project(request, project)
    lang = get_object_or_404(Language, code=lang)

    # Parse parameters
    export_format = None
    if 'format' in request.GET:
        export_format = request.GET['format']
    if export_format not in ('csv', 'po', 'tbx', 'xliff'):
        export_format = 'csv'

    # Grab all words
    words = Dictionary.objects.filter(project=prj,
                                      language=lang).order_by(Lower('source'))

    # Translate toolkit based export
    exporter = get_exporter(export_format)(
        prj,
        lang,
        get_site_url(
            reverse('show_dictionary',
                    kwargs={
                        'project': prj.slug,
                        'lang': lang.code
                    })),
        fieldnames=('source', 'target'),
    )

    # Add words
    for word in words.iterator():
        exporter.add_dictionary(word)

    # Save to response
    return exporter.get_response('glossary-{project}-{language}.{extension}')
예제 #4
0
def download_translation_format(request, project, subproject, lang, fmt):
    obj = get_translation(request, project, subproject, lang)

    try:
        exporter = get_exporter(fmt)(obj.subproject.project, obj.language,
                                     get_site_url(obj.get_absolute_url()))
    except KeyError:
        raise Http404('File format not supported')

    for unit in obj.unit_set.iterator():
        exporter.add_unit(unit)

    # Save to response
    return exporter.get_response(
        '{{project}}-{0}-{{language}}.{{extension}}'.format(subproject))
예제 #5
0
def download_dictionary_ttkit(export_format, prj, lang, words):
    """Translate-toolkit builder for dictionary downloads."""
    exporter = get_exporter(export_format)(prj, lang,
                                           get_site_url(
                                               reverse('show_dictionary',
                                                       kwargs={
                                                           'project': prj.slug,
                                                           'lang': lang.code
                                                       })))

    # Add words
    for word in words.iterator():
        exporter.add_dictionary(word)

    # Save to response
    return exporter.get_response('glossary-{project}-{language}.{extension}')
예제 #6
0
def download_dictionary_ttkit(export_format, prj, lang, words):
    '''
    Translate-toolkit builder for dictionary downloads.
    '''
    exporter = get_exporter(export_format)(
        prj, lang,
        get_site_url(reverse(
            'show_dictionary',
            kwargs={'project': prj.slug, 'lang': lang.code}
        ))
    )

    # Add words
    for word in words.iterator():
        exporter.add_dictionary(word)

    # Save to response
    return exporter.get_response(
        'glossary-{project}-{language}.{extension}'
    )
예제 #7
0
def download_translation_format(request, project, subproject, lang, fmt):
    obj = get_translation(request, project, subproject, lang)

    try:
        exporter = get_exporter(fmt)(
            obj.subproject.project,
            obj.language,
            get_site_url(obj.get_absolute_url())
        )
    except KeyError:
        raise Http404('File format not supported')

    for unit in obj.unit_set.iterator():
        exporter.add_unit(unit)

    # Save to response
    return exporter.get_response(
        '{{project}}-{0}-{{language}}.{{extension}}'.format(
            subproject
        )
    )
예제 #8
0
파일: dictionary.py 프로젝트: saily/weblate
def download_dictionary(request, project, lang):
    """Export dictionary into various formats."""
    prj = get_project(request, project)
    lang = get_object_or_404(Language, code=lang)

    # Parse parameters
    export_format = None
    if 'format' in request.GET:
        export_format = request.GET['format']
    if export_format not in ('csv', 'po', 'tbx', 'xliff'):
        export_format = 'csv'

    # Grab all words
    words = Dictionary.objects.filter(
        project=prj,
        language=lang
    ).order_by('source')

    # Translate toolkit based export
    exporter = get_exporter(export_format)(
        prj, lang,
        get_site_url(reverse(
            'show_dictionary',
            kwargs={'project': prj.slug, 'lang': lang.code}
        )),
        fieldnames=('source', 'target'),
    )

    # Add words
    for word in words.iterator():
        exporter.add_dictionary(word)

    # Save to response
    return exporter.get_response(
        'glossary-{project}-{language}.{extension}'
    )