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
9 OUT_CPP="src/qt/bitcoinstrings.cpp"
14 Parse 'po' format produced by xgettext.
15 Return a list of (msgid,msgstr) tuples.
23 for line in text.split('\n'):
24 line = line.rstrip('\r')
25 if line.startswith('msgid '):
27 messages.append((msgid, msgstr))
33 elif line.startswith('msgstr '):
37 elif line.startswith('"'):
44 messages.append((msgid, msgstr))
48 files = glob.glob('src/*.cpp') + glob.glob('src/*.h')
50 # xgettext -n --keyword=_ $FILES
51 child = Popen(['xgettext','--output=-','-n','--keyword=_'] + files, stdout=PIPE)
52 (out, err) = child.communicate()
54 messages = parse_po(out)
56 f = open(OUT_CPP, 'w')
57 f.write("""#include <QtGlobal>
58 // Automatically generated by extract_strings.py
60 #define UNUSED __attribute__((unused))
65 f.write('static const char UNUSED *bitcoin_strings[] = {')
66 for (msgid, msgstr) in messages:
68 f.write('QT_TRANSLATE_NOOP("bitcoin-core", %s),\n' % ('\n'.join(msgid)))