8 from subprocess import check_output, Popen, PIPE
11 myopts, args = getopt.getopt(sys.argv[1:], "i:o:")
12 except getopt.GetoptError as e:
13 print(" Syntax: hrcex -i FileIn -o FileOut")
14 print(" FileIn: Source files (*.hrc)")
15 print(" FileOut: Destination file (*.*)")
24 with open(ofile, "a") as output:
25 xgettext = Popen(["xgettext", "-C", "--add-comments", "--keyword=NC_:1c,2", "--keyword=NNC_:1c,2,3", "--from-code=UTF-8", "--no-wrap", ifile, "-o", "-"], stdout=PIPE, encoding="UTF-8")
26 # while overall format is c++, all of the strings use custom placeholders and don't follow c-format
27 # esp. plain percent sign never is escaped explicitly
28 input = check_output(['sed', '-e', '/^#, c-format$/d'], stdin=xgettext.stdout, encoding="UTF-8")
30 xgettext.stdout.close()
31 po = polib.pofile(input)
33 print("", file=output)
35 keyid = entry.msgctxt + '|' + entry.msgid
36 print('#. ' + polib.genKeyId(keyid), file=output)
37 for i, occurrence in enumerate(entry.occurrences):
38 entry.occurrences[i] = os.path.relpath(occurrence[0], os.environ['SRCDIR']), occurrence[1]
39 print(entry, file=output)