This file is indexed.

/usr/share/pyshared/translate/convert/po2rc.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2002-2006,2008-2009 Zuza Software Foundation
#
# This file is part of the Translate Toolkit.
#
# This program 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.
#
# This program 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 back to Windows Resource (.rc) files.

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

from translate.storage import po
from translate.storage import rc


class rerc:

    def __init__(self, templatefile, charset="utf-8", lang=None, sublang=None):
        self.templatefile = templatefile
        self.templatestore = rc.rcfile(templatefile, encoding=charset)
        self.inputdict = {}
        self.charset = charset
        self.lang = lang
        self.sublang = sublang

    def convertstore(self, inputstore, includefuzzy=False):
        self.makestoredict(inputstore, includefuzzy)
        outputblocks = []
        for block in self.templatestore.blocks:
            outputblocks.append(self.convertblock(block))
        if self.charset == "utf-8":
            outputblocks.insert(0, "#pragma code_page(65001)\n")
            outputblocks.append("#pragma code_page(default)")
        return outputblocks

    def makestoredict(self, store, includefuzzy=False):
        """ make a dictionary of the translations"""
        for unit in store.units:
            if includefuzzy or not unit.isfuzzy():
                for location in unit.getlocations():
                    rcstring = unit.target
                    if len(rcstring.strip()) == 0:
                        rcstring = unit.source
                    self.inputdict[location] = rc.escape_to_rc(rcstring).encode(self.charset)

    def convertblock(self, block):
        newblock = block
        if isinstance(newblock, unicode):
            newblock = newblock.encode('utf-8')
        if newblock.startswith("LANGUAGE"):
            return "LANGUAGE %s, %s" % (self.lang, self.sublang)
        for unit in self.templatestore.units:
            location = unit.getlocations()[0]
            if location in self.inputdict:
                if self.inputdict[location] != unit.match.groupdict()['value']:
                    newmatch = unit.match.group().replace(unit.match.groupdict()['value'],
                                                          self.inputdict[location])
                    newblock = newblock.replace(unit.match.group(), newmatch)
        if isinstance(newblock, unicode):
            newblock = newblock.encode(self.charset)
        return newblock


def convertrc(inputfile, outputfile, templatefile, includefuzzy=False,
              charset=None, lang=None, sublang=None):
    inputstore = po.pofile(inputfile)
    if not lang:
        raise ValueError("must specify a target language")
    if templatefile is None:
        raise ValueError("must have template file for rc files")
        # convertor = po2rc()
    else:
        convertor = rerc(templatefile, charset, lang, sublang)
    outputrclines = convertor.convertstore(inputstore, includefuzzy)
    outputfile.writelines(outputrclines)
    return 1


def main(argv=None):
    # handle command line options
    from translate.convert import convert
    formats = {("po", "rc"): ("rc", convertrc)}
    parser = convert.ConvertOptionParser(formats, usetemplates=True,
                                         description=__doc__)
    defaultcharset = "utf-8"
    parser.add_option("", "--charset", dest="charset", default=defaultcharset,
        help="charset to use to decode the RC files (default: %s)" % defaultcharset,
        metavar="CHARSET")
    parser.add_option("-l", "--lang", dest="lang", default=None,
        help="LANG entry", metavar="LANG")
    defaultsublang = "SUBLANG_DEFAULT"
    parser.add_option("", "--sublang", dest="sublang", default=defaultsublang,
        help="SUBLANG entry (default: %s)" % defaultsublang, metavar="SUBLANG")
    parser.passthrough.append("charset")
    parser.passthrough.append("lang")
    parser.passthrough.append("sublang")
    parser.add_fuzzy_option()
    parser.run(argv)

if __name__ == '__main__':
    main()