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 (*.ui)")
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
)
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
)
30 po
= polib
.pofile(input)
34 keyid
= entry
.msgctxt
+ '|' + entry
.msgid
35 print >> output
, '#. ' + polib
.genKeyId(keyid
)
36 for i
, occurrence
in enumerate(entry
.occurrences
):
37 entry
.occurrences
[i
] = os
.path
.relpath(occurrence
[0], os
.environ
['SRCDIR']), occurrence
[1]
38 print >> output
, entry