/usr/share/doc/debiandoc-sgml/examples/msgtranslated is in debiandoc-sgml 1.2.28-1.
This file is owned by root:root, with mode 0o755.
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 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: set sts=4 expandtab:
import sys, os, re, string, getopt
progname = "msgtranslated"
version = "1.2.1"
cmdname = os.path.basename(sys.argv[0])
USAGE = """
%s - extract only translated PO contents
Copyright (C) 2011 Osamu Aoki, GPL2+, version: %s
Usage: %s [options] <FOO.xx.po >FOO-out.xx.po
Supported options:
-h Display this help message.
This works better on a PO file processed with:
$ msgcat --no-wrap FOO.xx.po | sponge FOO.xx.po
"""%(cmdname, version, cmdname)
def main():
global verbosemode
try:
opts, args = getopt.getopt(sys.argv[1:], "h")
except getopt.GetoptError, err:
print >>sys.stderr, "Wrong option ..."
print >>sys.stderr, USAGE
sys.exit(1)
for o, a in opts:
if o == "-h":
print >>sys.stderr, USAGE
sys.exit(0)
else:
assert False, "unhandled option"
process_po()
def process_po():
i = 0 # line index
ii = i # line index updated for each PO set
mode = 0
# mode = 0 for pre
# mode = 1 for id
# mode = 2 for str
buff = ['', '', '']
for l in sys.stdin.readlines():
i += 1
if mode == 0:
if l[0:-1] == '':
pass
elif l[0:1] == '#':
buff[mode] += l
elif l[0:5] == 'msgid':
# start msgid mode
mode = 1
buff[mode] = l
else:
assert False, "E: %i, mode %i"%(ii, mode)
elif mode == 1:
if l[0:1] == '"':
buff[mode] = buff[mode][:-2] + l[1:]
elif l[0:6] == 'msgstr':
# start msgstr mode
mode = 2
buff[mode] = l
else:
assert False, "E: %i, mode %i"%(ii, mode)
elif mode == 2:
if l[0:1] == '"':
buff[mode] = buff[mode][:-2] + l[1:]
elif l[0:-1] == '':
# end msgstr mode
# now ready to process a set of PO data
po_write(ii, buff)
# start again
buff = ['', '', '']
mode = 0
ii = i
else:
assert False, "E: %i, mode %i"%(ii, mode)
else:
assert False, "E: %i, mode %i"%(ii, mode)
# output at EOF
po_write(ii, buff)
def po_write(ii, buff):
# msgid != msgstr
if buff[1][5:] != buff[2][6:]:
sys.stdout.write(buff[0])
sys.stdout.write(buff[1])
sys.stdout.write(buff[2])
print
elif buff[1][7:8] == "$" or buff[1][7:8] == " ":
# huristics: msgid "$..." or msgid " ..."
sys.stdout.write(buff[0])
sys.stdout.write(buff[1])
sys.stdout.write(buff[2])
print
else:
sys.stdout.write(buff[0])
sys.stdout.write(buff[1])
sys.stdout.write("msgstr \"\"\n")
print
if __name__ == '__main__':
main()
|