3 Extract _("...") strings for translation and convert to Qt4 stringdefs so that
4 they can be picked up by Qt linguist.
6 from subprocess import Popen, PIPE
10 OUT_CPP="src/qt/bitcoinstrings.cpp"
15 Parse 'po' format produced by xgettext.
16 Return a list of (msgid,msgstr) tuples.
24 for line in text.split('\n'):
25 line = line.rstrip('\r')
26 if line.startswith('msgid '):
28 messages.append((msgid, msgstr))
34 elif line.startswith('msgstr '):
38 elif line.startswith('"'):
45 messages.append((msgid, msgstr))
49 files = glob.glob('src/*.cpp') + glob.glob('src/*.h')
51 # xgettext -n --keyword=_ $FILES
52 child = Popen(['xgettext','--output=-','-n','--keyword=_'] + files, stdout=PIPE)
53 (out, err) = child.communicate()
55 messages = parse_po(out)
57 f = open(OUT_CPP, 'w')
58 f.write("""#include <QtGlobal>
59 // Automatically generated by extract_strings.py
61 #define UNUSED __attribute__((unused))
66 f.write('static const char UNUSED *bitcoin_strings[] = {\n')
67 messages.sort(key=operator.itemgetter(0))
68 for (msgid, msgstr) in messages:
70 f.write('QT_TRANSLATE_NOOP("bitcoin-core", %s),\n' % ('\n'.join(msgid)))