2017-12-12 20:47:24 +01:00
|
|
|
#!/usr/bin/env python3
|
2018-01-02 18:12:05 +01:00
|
|
|
# Copyright (c) 2012-2017 The Bitcoin Core developers
|
2016-09-11 23:32:22 +02:00
|
|
|
# Distributed under the MIT software license, see the accompanying
|
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2011-06-13 19:24:53 +02:00
|
|
|
'''
|
2016-03-20 18:51:52 +01:00
|
|
|
Extract _("...") strings for translation and convert to Qt stringdefs so that
|
2011-06-13 19:24:53 +02:00
|
|
|
they can be picked up by Qt linguist.
|
|
|
|
'''
|
|
|
|
from subprocess import Popen, PIPE
|
2012-06-13 18:17:28 +02:00
|
|
|
import operator
|
2013-09-14 17:48:27 +02:00
|
|
|
import os
|
2014-07-03 07:31:50 +02:00
|
|
|
import sys
|
2011-06-13 19:24:53 +02:00
|
|
|
|
2014-07-03 07:31:50 +02:00
|
|
|
OUT_CPP="qt/bitcoinstrings.cpp"
|
2011-06-13 19:24:53 +02:00
|
|
|
EMPTY=['""']
|
|
|
|
|
|
|
|
def parse_po(text):
|
|
|
|
"""
|
|
|
|
Parse 'po' format produced by xgettext.
|
|
|
|
Return a list of (msgid,msgstr) tuples.
|
|
|
|
"""
|
|
|
|
messages = []
|
|
|
|
msgid = []
|
|
|
|
msgstr = []
|
|
|
|
in_msgid = False
|
|
|
|
in_msgstr = False
|
|
|
|
|
|
|
|
for line in text.split('\n'):
|
|
|
|
line = line.rstrip('\r')
|
|
|
|
if line.startswith('msgid '):
|
|
|
|
if in_msgstr:
|
|
|
|
messages.append((msgid, msgstr))
|
|
|
|
in_msgstr = False
|
|
|
|
# message start
|
|
|
|
in_msgid = True
|
2016-05-24 02:43:01 +02:00
|
|
|
|
2011-06-13 19:24:53 +02:00
|
|
|
msgid = [line[6:]]
|
|
|
|
elif line.startswith('msgstr '):
|
|
|
|
in_msgid = False
|
|
|
|
in_msgstr = True
|
|
|
|
msgstr = [line[7:]]
|
|
|
|
elif line.startswith('"'):
|
|
|
|
if in_msgid:
|
|
|
|
msgid.append(line)
|
|
|
|
if in_msgstr:
|
|
|
|
msgstr.append(line)
|
|
|
|
|
|
|
|
if in_msgstr:
|
|
|
|
messages.append((msgid, msgstr))
|
|
|
|
|
|
|
|
return messages
|
|
|
|
|
2014-07-03 07:31:50 +02:00
|
|
|
files = sys.argv[1:]
|
2011-06-13 19:24:53 +02:00
|
|
|
|
|
|
|
# xgettext -n --keyword=_ $FILES
|
2013-09-19 14:59:45 +02:00
|
|
|
XGETTEXT=os.getenv('XGETTEXT', 'xgettext')
|
2016-03-20 18:51:52 +01:00
|
|
|
if not XGETTEXT:
|
|
|
|
print('Cannot extract strings: xgettext utility is not installed or not configured.',file=sys.stderr)
|
|
|
|
print('Please install package "gettext" and re-run \'./configure\'.',file=sys.stderr)
|
2017-07-09 22:57:02 +02:00
|
|
|
sys.exit(1)
|
2013-09-14 17:48:27 +02:00
|
|
|
child = Popen([XGETTEXT,'--output=-','-n','--keyword=_'] + files, stdout=PIPE)
|
2011-06-13 19:24:53 +02:00
|
|
|
(out, err) = child.communicate()
|
|
|
|
|
2016-03-20 18:51:52 +01:00
|
|
|
messages = parse_po(out.decode('utf-8'))
|
2011-06-13 19:24:53 +02:00
|
|
|
|
2018-06-12 17:49:20 +02:00
|
|
|
f = open(OUT_CPP, 'w', encoding="utf8")
|
2013-04-13 07:13:08 +02:00
|
|
|
f.write("""
|
|
|
|
|
|
|
|
#include <QtGlobal>
|
|
|
|
|
2016-05-24 02:43:01 +02:00
|
|
|
// Automatically generated by extract_strings_qt.py
|
2012-04-15 12:53:14 +02:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#define UNUSED __attribute__((unused))
|
|
|
|
#else
|
|
|
|
#define UNUSED
|
|
|
|
#endif
|
|
|
|
""")
|
2012-06-13 18:17:28 +02:00
|
|
|
f.write('static const char UNUSED *bitcoin_strings[] = {\n')
|
2015-12-09 11:53:12 +01:00
|
|
|
f.write('QT_TRANSLATE_NOOP("bitcoin-core", "%s"),\n' % (os.getenv('PACKAGE_NAME'),))
|
2015-12-22 13:29:13 +01:00
|
|
|
f.write('QT_TRANSLATE_NOOP("bitcoin-core", "%s"),\n' % (os.getenv('COPYRIGHT_HOLDERS'),))
|
2016-01-19 09:42:05 +01:00
|
|
|
if os.getenv('COPYRIGHT_HOLDERS_SUBSTITUTION') != os.getenv('PACKAGE_NAME'):
|
|
|
|
f.write('QT_TRANSLATE_NOOP("bitcoin-core", "%s"),\n' % (os.getenv('COPYRIGHT_HOLDERS_SUBSTITUTION'),))
|
2012-06-13 18:17:28 +02:00
|
|
|
messages.sort(key=operator.itemgetter(0))
|
2011-06-13 19:24:53 +02:00
|
|
|
for (msgid, msgstr) in messages:
|
|
|
|
if msgid != EMPTY:
|
|
|
|
f.write('QT_TRANSLATE_NOOP("bitcoin-core", %s),\n' % ('\n'.join(msgid)))
|
2013-04-13 07:13:08 +02:00
|
|
|
f.write('};\n')
|
2011-06-13 19:24:53 +02:00
|
|
|
f.close()
|