This file is indexed.

/usr/share/pyshared/translate/convert/po2tmx.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2005, 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 Gettext PO localization files to a TMX (Translation Memory eXchange) file.

See: http://docs.translatehouse.org/projects/translate-toolkit/en/latest/commands/po2tmx.html
for examples and usage instructions.
"""

import os

from translate.storage import po
from translate.storage import tmx
from translate.convert import convert
from translate.misc import wStringIO


class po2tmx:

    def convertfile(self, inputfile, sourcelanguage='en', targetlanguage=None):
        """converts a .po file to TMX file"""
        # TODO: This seems to not be used... remove it
        inputstore = inputfile
        for inunit in inputstore.units:
            if inunit.isheader() or inunit.isblank() or not inunit.istranslated() or inunit.isfuzzy():
                continue
            source = inunit.source
            translation = inunit.target
            # TODO place source location in comments
            tmxfile.addtranslation(source, sourcelanguage, translation, targetlanguage)
        return str(tmxfile)

    def convertfiles(self, inputfile, tmxfile, sourcelanguage='en', targetlanguage=None):
        """converts a .po file (possibly many) to TMX file"""
        inputstore = po.pofile(inputfile)
        for inunit in inputstore.units:
            if inunit.isheader() or inunit.isblank() or not inunit.istranslated() or inunit.isfuzzy():
                continue
            source = inunit.source
            translation = inunit.target
            # TODO place source location in comments
            tmxfile.addtranslation(source, sourcelanguage, translation, targetlanguage)


def convertpo(inputfile, outputfile, templatefile, sourcelanguage='en', targetlanguage=None):
    """reads in stdin using fromfileclass, converts using convertorclass, writes to stdout"""
    convertor = po2tmx()
    convertor.convertfiles(inputfile, outputfile.tmxfile, sourcelanguage, targetlanguage)
    return 1


class tmxmultifile:

    def __init__(self, filename, mode=None):
        """initialises tmxmultifile from a seekable inputfile or writable outputfile"""
        self.filename = filename
        if mode is None:
            if os.path.exists(filename):
                mode = 'r'
            else:
                mode = 'w'
        self.mode = mode
#        self.multifilestyle = multifilestyle
        self.multifilename = os.path.splitext(filename)[0]
#        self.multifile = open(filename, mode)
        self.tmxfile = tmx.tmxfile()

    def openoutputfile(self, subfile):
        """returns a pseudo-file object for the given subfile"""

        def onclose(contents):
            pass
        outputfile = wStringIO.CatchStringOutput(onclose)
        outputfile.filename = subfile
        outputfile.tmxfile = self.tmxfile
        return outputfile


class TmxOptionParser(convert.ArchiveConvertOptionParser):

    def recursiveprocess(self, options):
        if not options.targetlanguage:
            raise ValueError("You must specify the target language")
        super(TmxOptionParser, self).recursiveprocess(options)
        self.output = open(options.output, 'w')
        options.outputarchive.tmxfile.setsourcelanguage(options.sourcelanguage)
        self.output.write(str(options.outputarchive.tmxfile))
        self.output.close()


def main(argv=None):
    formats = {"po": ("tmx", convertpo), ("po", "tmx"): ("tmx", convertpo)}
    archiveformats = {(None, "output"): tmxmultifile, (None, "template"): tmxmultifile}
    parser = TmxOptionParser(formats, usepots=False, usetemplates=False, description=__doc__, archiveformats=archiveformats)
    parser.add_option("-l", "--language", dest="targetlanguage", default=None,
            help="set target language code (e.g. af-ZA) [required]", metavar="LANG")
    parser.add_option("", "--source-language", dest="sourcelanguage", default='en',
            help="set source language code (default: en)", metavar="LANG")
    parser.passthrough.append("sourcelanguage")
    parser.passthrough.append("targetlanguage")
    parser.run(argv)


if __name__ == '__main__':
    main()