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
8 OUT_CPP="src/qt/bitcoinstrings.cpp"
13 Parse 'po' format produced by xgettext.
14 Return a list of (msgid,msgstr) tuples.
22 for line in text.split('\n'):
23 line = line.rstrip('\r')
24 if line.startswith('msgid '):
26 messages.append((msgid, msgstr))
32 elif line.startswith('msgstr '):
36 elif line.startswith('"'):
43 messages.append((msgid, msgstr))
47 files = ['src/base58.h', 'src/bignum.h', 'src/db.cpp', 'src/db.h', 'src/headers.h', 'src/init.cpp', 'src/init.h', 'src/irc.cpp', 'src/irc.h', 'src/key.h', 'src/main.cpp', 'src/main.h', 'src/net.cpp', 'src/net.h', 'src/noui.h', 'src/script.cpp', 'src/script.h', 'src/serialize.h', 'src/strlcpy.h', 'src/uint256.h', 'src/util.cpp', 'src/util.h']
49 # xgettext -n --keyword=_ $FILES
50 child = Popen(['xgettext','--output=-','-n','--keyword=_'] + files, stdout=PIPE)
51 (out, err) = child.communicate()
53 messages = parse_po(out)
55 f = open(OUT_CPP, 'w')
56 f.write("""#include <QtGlobal>
57 // Automatically generated by extract_strings.py
59 #define UNUSED __attribute__((unused))
64 f.write('static const char UNUSED *bitcoin_strings[] = {')
65 for (msgid, msgstr) in messages:
67 f.write('QT_TRANSLATE_NOOP("bitcoin-core", %s),\n' % ('\n'.join(msgid)))