Skip to content

Commit 4721a13

Browse files
committed
Update make.py from Gramps50 branch
1 parent 0ccd7b0 commit 4721a13

File tree

1 file changed

+48
-14
lines changed

1 file changed

+48
-14
lines changed

make.py

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import sys
4848
import os
4949
import tarfile
50+
from xml.etree import ElementTree
5051

5152
if "GRAMPSPATH" in os.environ:
5253
GRAMPSPATH = os.environ["GRAMPSPATH"]
@@ -160,6 +161,8 @@ def cleanup(addon_dir):
160161
#'%s/po/template.pot' % addon_dir,
161162
'%s/po/*-global.po' % addon_dir,
162163
'%s/po/*-temp.po' % addon_dir,
164+
'%s/po/??.po' % addon_dir,
165+
'%s/po/?????.po' % addon_dir,
163166
'%s/*.pyc' % addon_dir,
164167
'%s/*.pyo' % addon_dir]
165168
for pat in patterns:
@@ -208,7 +211,6 @@ def tar_filt(tinfo):
208211
dirs = [addon]
209212
if len(sys.argv) == 4:
210213
from gramps.gen.plug import make_environment, PTYPE_STR
211-
from xml.etree import ElementTree
212214

213215
def register(ptype, **kwargs):
214216
global plugins
@@ -237,8 +239,7 @@ def register(ptype, **kwargs):
237239
if not listed:
238240
continue # skip this one if not listed
239241

240-
mkdir(r("%(addon)s/po"))
241-
mkdir("%(addon)s/locale")
242+
mkdir("%(addon)s/po")
242243
system('''xgettext --language=Python --keyword=_ --keyword=N_'''
243244
''' --from-code=UTF-8'''
244245
''' -o "%(addon)s/po/template.pot" "%(addon)s"/*.py ''')
@@ -340,12 +341,9 @@ def register(ptype, **kwargs):
340341
'''"%(addon)s/po/%(locale)s-temp.po" '''
341342
'''"%(addon)s/po/%(locale)s-local.po" '''
342343
'''-o "%(addon)s/po/%(locale)s-local.po.2" ''')
343-
system('''cp "%(addon)s/po/%(locale)s-local.po" '''
344-
'''"%(addon)s/po/%(locale)s-local.po.1" ''')
345-
system('''cp "%(addon)s/po/%(locale)s-local.po.2" '''
346-
'''"%(addon)s/po/%(locale)s-local.po" ''')
347-
system('''rm -v "%(addon)s/po/%(locale)s-local.po.1" '''
348-
'''"%(addon)s/po/%(locale)s-local.po.2" ''')
344+
os.remove(r("%(addon)s/po/%(locale)s-local.po"))
345+
os.rename(r("%(addon)s/po/%(locale)s-local.po.2"),
346+
r("%(addon)s/po/%(locale)s-local.po"))
349347
# # Done!
350348
echo('''\nYou can edit "%(addon)s/po/%(locale)s-local.po"''')
351349

@@ -519,6 +517,7 @@ def register(ptype, **kwargs):
519517
# Build it.
520518
do_tar(sfiles)
521519
print("***Rebuilt: %s" % addon)
520+
522521
# Add addon to newly created listing (equivalent to 'listing all')
523522
for lang in languages:
524523
gpr_bad = False # to flag a bad gpr
@@ -559,6 +558,45 @@ def register(ptype, **kwargs):
559558
if gpr_bad or not do_list:
560559
break
561560
cleanup(addon)
561+
if todo: # make an updated pot file
562+
mkdir("%(addon)s/po")
563+
system('''xgettext --language=Python --keyword=_ --keyword=N_'''
564+
''' --from-code=UTF-8'''
565+
''' -o "%(addon)s/po/temp.pot" "%(addon)s"/*.py ''')
566+
fnames = glob.glob("%s/*.glade" % addon)
567+
if fnames:
568+
system('''xgettext -j --add-comments -L Glade '''
569+
'''--from-code=UTF-8 -o "%(addon)s/po/temp.pot" '''
570+
'''"%(addon)s"/*.glade''')
571+
572+
# scan for xml files and get translation text where the tag
573+
# starts with an '_'. Create a .h file with the text strings
574+
fnames = glob.glob("%s/*.xml" % addon)
575+
for filename in fnames:
576+
tree = ElementTree.parse(filename)
577+
root = tree.getroot()
578+
with open(filename + '.h', 'w', encoding='utf-8') as head:
579+
for key in root.iter():
580+
if key.tag.startswith('_') and len(key.tag) > 1:
581+
msg = key.text.replace('"', '\\"')
582+
txl = '_("%s")\n' % msg
583+
head.write(txl)
584+
root.clear()
585+
# now append XML text to the pot
586+
system('''xgettext -j --keyword=_ --from-code=UTF-8 '''
587+
'''--language=Python -o "%(addon)s/po/temp.pot" '''
588+
'''"%(filename)s.h"''')
589+
os.remove(filename + '.h')
590+
if os.path.isfile(r('''%(addon)s/po/template.pot''')):
591+
# we do a merge so changes to header are not lost
592+
system('''msgmerge --no-fuzzy-matching -U '''
593+
'''%(addon)s/po/template.pot '''
594+
'''%(addon)s/po/temp.pot''')
595+
os.remove(r('''%(addon)s/po/temp.pot'''))
596+
else:
597+
os.rename(r('''%(addon)s/po/temp.pot'''),
598+
r('''%(addon)s/po/template.pot'''))
599+
# write out the listings
562600
for lang in languages:
563601
fp = open(r("../addons/%(gramps_version)s/listings/") +
564602
("addons-%s.txt" % lang), "w", encoding="utf-8",
@@ -744,12 +782,8 @@ def register(ptype, **kwargs):
744782
f.read(),
745783
gpr.encode("utf-8", errors="backslashreplace"),
746784
'exec')
747-
try:
748-
exec(code, make_environment(_=local_gettext),
785+
exec(code, make_environment(_=local_gettext),
749786
{"register": register, "build_script": True})
750-
except:
751-
print('%s failed to register its .gpr.py file' % addon)
752-
continue
753787
for p in plugins:
754788
tgz_file = "%s.addon.tgz" % gpr.split(os.sep, 1)[0]
755789
tgz_exists = os.path.isfile(

0 commit comments

Comments
 (0)