/usr/share/pyshared/translate/convert/odf2xliff.py is in translate-toolkit 1.10.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2004-2006 Zuza Software Foundation
#
# This file is part of translate.
#
# translate is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# translate is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
"""Convert OpenDocument (ODF) files to XLIFF localization files.
See: http://docs.translatehouse.org/projects/translate-toolkit/en/latest/commands/odf2xliff.html
for examples and usage instructions.
"""
from translate.storage import factory
from translate.misc.contextlib import contextmanager
from translate.misc.context import with_
from translate.storage import odf_io
def convertodf(inputfile, outputfile, templates, engine='toolkit'):
"""reads in stdin using fromfileclass, converts using convertorclass,
writes to stdout
"""
def translate_toolkit_implementation(store):
import cStringIO
import zipfile
from translate.storage.xml_extract import extract
from translate.storage import odf_shared
contents = odf_io.open_odf(inputfile)
for data in contents.values():
parse_state = extract.ParseState(odf_shared.no_translate_content_elements,
odf_shared.inline_elements)
extract.build_store(cStringIO.StringIO(data), store, parse_state)
def itools_implementation(store):
from itools.handlers import get_handler
from itools.gettext.po import encode_source
import itools.odf
filename = getattr(inputfile, 'name', 'unkown')
handler = get_handler(filename)
try:
get_units = handler.get_units
except AttributeError:
raise AttributeError('error: the file "%s" could not be processed' % filename)
# Make the XLIFF file
for source, context, line in get_units():
source = encode_source(source)
unit = store.UnitClass(source)
store.addunit(unit)
@contextmanager
def store_context():
store = factory.getobject(outputfile)
try:
store.setfilename(store.getfilenode('NoName'), inputfile.name)
except:
print "couldn't set origin filename"
yield store
store.save()
def with_block(store):
if engine == "toolkit":
translate_toolkit_implementation(store)
else:
itools_implementation(store)
# 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.
inputfile.close()
inputfile = file(inputfile.name, mode='rb')
with_(store_context(), with_block)
return True
# For formats see OpenDocument 1.2 draft 7 Appendix C
formats = {
"sxw": ("xlf", convertodf),
"odt": ("xlf", convertodf), # Text
"ods": ("xlf", convertodf), # Spreadsheet
"odp": ("xlf", convertodf), # Presentation
"odg": ("xlf", convertodf), # Drawing
"odc": ("xlf", convertodf), # Chart
"odf": ("xlf", convertodf), # Formula
"odi": ("xlf", convertodf), # Image
"odm": ("xlf", convertodf), # Master Document
"ott": ("xlf", convertodf), # Text template
"ots": ("xlf", convertodf), # Spreadsheet template
"otp": ("xlf", convertodf), # Presentation template
"otg": ("xlf", convertodf), # Drawing template
"otc": ("xlf", convertodf), # Chart template
"otf": ("xlf", convertodf), # Formula template
"oti": ("xlf", convertodf), # Image template
"oth": ("xlf", convertodf), # Web page template
}
def main(argv=None):
def add_options(parser):
parser.add_option("", "--engine", dest="engine", default="toolkit",
type="choice", choices=["toolkit", "itools"],
help="""Choose whether itools (--engine=itools) or the translate toolkit (--engine=toolkit)
should be used as the engine to convert an ODF file to an XLIFF file.""")
parser.passthrough = ['engine']
return parser
from translate.convert import convert
parser = convert.ConvertOptionParser(formats, description=__doc__)
add_options(parser)
parser.run(argv)
if __name__ == '__main__':
main()
|