示例#1
0
def write_odf(xlf_data, template, output_file, dom_trees):
    def write_content_to_odf(output_zip, dom_trees):
        for filename, dom_tree in dom_trees.iteritems():
            output_zip.writestr(
                filename,
                etree.tostring(dom_tree,
                               encoding='UTF-8',
                               xml_declaration=True))

    # Since the convertoptionsparser will give us an open file, we risk that
    # it could have been opened in non-binary mode on Windows, and then we'll
    # have problems, so let's make sure we have what we want.
    template.close()
    template = file(template.name, mode='rb')
    template_zip = zipfile.ZipFile(template, 'r')
    output_file.close()
    output_file = file(output_file.name, mode='wb')
    output_zip = zipfile.ZipFile(output_file,
                                 'w',
                                 compression=zipfile.ZIP_DEFLATED)
    # Let's keep the XLIFF file out of the generated ODF for now. Note the
    # weird handling of the manifest since it can only be written to the ZIP
    # file once.
    #    output_zip = odf_io.copy_odf(template_zip, output_zip, dom_trees.keys() + ['META-INF/manifest.xml'])
    #    output_zip = odf_io.add_file(output_zip, template_zip.read('META-INF/manifest.xml'), 'translation.xlf', xlf_data)
    output_zip = odf_io.copy_odf(template_zip, output_zip, dom_trees.keys())
    write_content_to_odf(output_zip, dom_trees)
示例#2
0
def write_odf(xlf_data, template, output_file, dom_trees):
    def write_content_to_odf(output_zip, dom_trees):
        for filename, dom_tree in dom_trees.iteritems():
            output_zip.writestr(filename, etree.tostring(dom_tree, encoding='UTF-8', xml_declaration=True))

    # Since the convertoptionsparser will give us an open file, we risk that
    # it could have been opened in non-binary mode on Windows, and then we'll
    # have problems, so let's make sure we have what we want.
    template.close()
    template = file(template.name, mode='rb')
    template_zip = zipfile.ZipFile(template,  'r')
    output_file.close()
    output_file = file(output_file.name, mode='wb')
    output_zip   = zipfile.ZipFile(output_file, 'w', compression=zipfile.ZIP_DEFLATED)
    output_zip   = odf_io.copy_odf(template_zip, output_zip, dom_trees.keys() + ['META-INF/manifest.xml'])
    output_zip   = odf_io.add_file(output_zip, template_zip.read('META-INF/manifest.xml'), 'translation.xlf', xlf_data)
    write_content_to_odf(output_zip, dom_trees)
示例#3
0
def write_odf(template, output_file, dom_trees):
    """Write the translated ODF package.

    The resulting ODF package is a copy of the template ODF package, with the
    translatable files replaced by their translated versions.
    """
    template_zip = zipfile.ZipFile(template, "r")
    output_zip = zipfile.ZipFile(output_file, "w", compression=zipfile.ZIP_DEFLATED)

    # Copy the ODF package.
    output_zip = copy_odf(template_zip, output_zip, dom_trees.keys())

    # Overwrite the translated files to the ODF package.
    for filename, dom_tree in dom_trees.items():
        output_zip.writestr(
            filename, etree.tostring(dom_tree, encoding="UTF-8", xml_declaration=True)
        )
示例#4
0
def write_odf(template, output_file, dom_trees):
    """Write the translated ODF package.

    The resulting ODF package is a copy of the template ODF package, with the
    translatable files replaced by their translated versions.
    """
    template_zip = zipfile.ZipFile(template, 'r')
    output_zip = zipfile.ZipFile(output_file, 'w',
                                 compression=zipfile.ZIP_DEFLATED)

    # Copy the ODF package.
    output_zip = copy_odf(template_zip, output_zip, dom_trees.keys())

    # Overwrite the translated files to the ODF package.
    for filename, dom_tree in six.iteritems(dom_trees):
        output_zip.writestr(filename, etree.tostring(dom_tree,
                                                     encoding='UTF-8',
                                                     xml_declaration=True))
示例#5
0
def write_odf(xlf_data, template, output_file, dom_trees):
    def write_content_to_odf(output_zip, dom_trees):
        for filename, dom_tree in dom_trees.iteritems():
            output_zip.writestr(filename, etree.tostring(dom_tree, encoding="UTF-8", xml_declaration=True))

    # Since the convertoptionsparser will give us an open file, we risk that
    # it could have been opened in non-binary mode on Windows, and then we'll
    # have problems, so let's make sure we have what we want.
    template.close()
    template = file(template.name, mode="rb")
    template_zip = zipfile.ZipFile(template, "r")
    output_file.close()
    output_file = file(output_file.name, mode="wb")
    output_zip = zipfile.ZipFile(output_file, "w", compression=zipfile.ZIP_DEFLATED)
    # Let's keep the XLIFF file out of the generated ODF for now. Note the
    # weird handling of the manifest since it can only be written to the ZIP
    # file once.
    #    output_zip = odf_io.copy_odf(template_zip, output_zip, dom_trees.keys() + ['META-INF/manifest.xml'])
    #    output_zip = odf_io.add_file(output_zip, template_zip.read('META-INF/manifest.xml'), 'translation.xlf', xlf_data)
    output_zip = odf_io.copy_odf(template_zip, output_zip, dom_trees.keys())
    write_content_to_odf(output_zip, dom_trees)