2 # Copyright (c) 2012-2016 The Bitcoin Core developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 Extract _("...") strings for translation and convert to Qt stringdefs so that
7 they can be picked up by Qt linguist.
9 from __future__
import division
,print_function
,unicode_literals
10 from subprocess
import Popen
, PIPE
15 OUT_CPP
="qt/bitcoinstrings.cpp"
20 Parse 'po' format produced by xgettext.
21 Return a list of (msgid,msgstr) tuples.
29 for line
in text
.split('\n'):
30 line
= line
.rstrip('\r')
31 if line
.startswith('msgid '):
33 messages
.append((msgid
, msgstr
))
39 elif line
.startswith('msgstr '):
43 elif line
.startswith('"'):
50 messages
.append((msgid
, msgstr
))
56 # xgettext -n --keyword=_ $FILES
57 XGETTEXT
=os
.getenv('XGETTEXT', 'xgettext')
59 print('Cannot extract strings: xgettext utility is not installed or not configured.',file=sys
.stderr
)
60 print('Please install package "gettext" and re-run \'./configure\'.',file=sys
.stderr
)
62 child
= Popen([XGETTEXT
,'--output=-','-n','--keyword=_'] + files
, stdout
=PIPE
)
63 (out
, err
) = child
.communicate()
65 messages
= parse_po(out
.decode('utf-8'))
67 f
= open(OUT_CPP
, 'w')
72 // Automatically generated by extract_strings_qt.py
74 #define UNUSED __attribute__((unused))
79 f
.write('static const char UNUSED *bitcoin_strings[] = {\n')
80 f
.write('QT_TRANSLATE_NOOP("bitcoin-core", "%s"),\n' % (os
.getenv('PACKAGE_NAME'),))
81 f
.write('QT_TRANSLATE_NOOP("bitcoin-core", "%s"),\n' % (os
.getenv('COPYRIGHT_HOLDERS'),))
82 if os
.getenv('COPYRIGHT_HOLDERS_SUBSTITUTION') != os
.getenv('PACKAGE_NAME'):
83 f
.write('QT_TRANSLATE_NOOP("bitcoin-core", "%s"),\n' % (os
.getenv('COPYRIGHT_HOLDERS_SUBSTITUTION'),))
84 messages
.sort(key
=operator
.itemgetter(0))
85 for (msgid
, msgstr
) in messages
:
87 f
.write('QT_TRANSLATE_NOOP("bitcoin-core", %s),\n' % ('\n'.join(msgid
)))