diff --git a/make.py b/make.py index aab793227..a8a3960c7 100755 --- a/make.py +++ b/make.py @@ -70,6 +70,7 @@ if len(sys.argv) >= 4: addon = sys.argv[3] + def system(scmd, **kwargs): """ Replace and call system with scmd. @@ -250,6 +251,7 @@ def build_addon(addon): if files: do_tar(files) + def check_gramps_path(command): try: sys.path.insert(0, GRAMPSPATH) @@ -264,6 +266,7 @@ def check_gramps_path(command): ) exit() + def strip_header(po_file): """ Strip the header off a `po` file and return its contents. @@ -272,7 +275,7 @@ def strip_header(po_file): out_file = "" if not os.path.isfile(po_file): return out_file - with open(po_file, "r") as in_file: + with open(po_file, "r", encoding="utf-8") as in_file: for line in in_file: if not header: out_file += line @@ -286,8 +289,8 @@ def aggregate_pot(): Aggregate the template files for all addons into a single file without strings that are already present in core Gramps. """ - args = ["touch", "po/template.pot"] - call(args) + f = open("po/template.pot", "w") + f.close() args = ["xgettext", "-j", "-o", "po/template.pot"] args.extend(glob.glob("*/po/template.pot")) @@ -317,7 +320,7 @@ def extract_po(addon): if not os.path.exists(pot): return for lang in get_all_languages(): - #print (lang) + # print (lang) po = os.path.join(po_dir, f"{lang}-local.po") if os.path.exists(f"po/{lang}.po"): old_file = strip_header(po) @@ -337,6 +340,7 @@ def extract_po(addon): args = ["git", "restore", po] call(args) + if command == "clean": if len(sys.argv) == 3: for addon in [ @@ -396,18 +400,18 @@ def register(ptype, **kwargs): continue # skip this one if not listed mkdir(f"{addon}/po") - fnames = ' '.join(glob.glob(f"{addon}/*.py")) + fnames = " ".join(glob.glob(f"{addon}/*.py")) system( f"xgettext --language=Python --keyword=_ --keyword=N_" f" --from-code=UTF-8" f' -o "{addon}/po/template.pot" {fnames} ' ) - fnames = ' '.join(glob.glob("%s/*.glade" % addon)) + fnames = " ".join(glob.glob("%s/*.glade" % addon)) if fnames: system( "xgettext -j --add-comments -L Glade " f'--from-code=UTF-8 -o "{addon}/po/template.pot" ' - f'{fnames}' + f"{fnames}" ) # scan for xml files and get translation text where the tag @@ -510,9 +514,9 @@ def register(ptype, **kwargs): f'"{addon}/po/{locale}-local.po" ' ) # Get all of the addon strings out of the catalog: - system( - f"touch {addon}/po/{locale}-temp.po" - ) + f = open(f"{addon}/po/{locale}-temp.po", "w") + f.close() + system( f"msggrep --location={addon}/* " f'"{addon}/po/{locale}-global.po" ' @@ -572,9 +576,14 @@ def register(ptype, **kwargs): languages = get_all_languages() listings = {lang: [] for lang in languages} - dirs = [ - file for file in glob.glob("*") if os.path.isdir(file) and file != "__pycache__" - ] + if len(sys.argv) == 3 or addon == "all": + dirs = [ + file + for file in glob.glob("*") + if os.path.isdir(file) and file != "__pycache__" + ] + else: + dirs = [addon] for addon in sorted(dirs): todo = False for po in glob.glob(f"{addon}/po/*-local.po"): @@ -721,18 +730,18 @@ def register(ptype, **kwargs): cleanup(addon) if todo: # make an updated pot file mkdir("%(addon)s/po") - fnames = ' '.join(glob.glob(f"{addon}/*.py")) + fnames = " ".join(glob.glob(f"{addon}/*.py")) system( "xgettext --language=Python --keyword=_ --keyword=N_" " --from-code=UTF-8" f' -o "{addon}/po/temp.pot" {fnames} ' ) - fnames = ' '.join(glob.glob(f"{addon}/*.glade")) + fnames = " ".join(glob.glob(f"{addon}/*.glade")) if fnames: system( "xgettext -j --add-comments -L Glade " f'--from-code=UTF-8 -o "{addon}/po/temp.pot" ' - f'{fnames}' + f"{fnames}" ) # scan for xml files and get translation text where the tag @@ -1023,10 +1032,10 @@ def register(ptype, **kwargs): aggregate_pot() elif command == "extract-po": - for addon in [file for file in glob.glob("*") - if os.path.isdir(file) - and file != "po"]: - print (addon) + for addon in [ + file for file in glob.glob("*") if os.path.isdir(file) and file != "po" + ]: + print(addon) extract_po(addon) else: