summaryrefslogtreecommitdiff
path: root/doc/translations
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2020-03-20 12:56:34 +0100
committerRémi Verschelde <rverschelde@gmail.com>2020-03-20 12:56:36 +0100
commit87d23bf85a3375c4c81f009d88beba66dc42e987 (patch)
tree6a8150a59115194c56cc95421277cddde04c1ee7 /doc/translations
parentaca1971a12341503e1b95035d6a2bf7355a56cbe (diff)
i18n: Add Makefile to extract classref strings
Change extract script `path` argument to support specifying multiple paths, like `makerst.py`. This prevents parsing invalid XML files while scanning the whole repository.
Diffstat (limited to 'doc/translations')
-rw-r--r--doc/translations/Makefile23
-rw-r--r--doc/translations/extract.py22
2 files changed, 36 insertions, 9 deletions
diff --git a/doc/translations/Makefile b/doc/translations/Makefile
new file mode 100644
index 0000000000..ceee79ec95
--- /dev/null
+++ b/doc/translations/Makefile
@@ -0,0 +1,23 @@
+# Makefile providing various facilities to manage translations
+
+TEMPLATE = classes.pot
+POFILES = $(wildcard *.po)
+LANGS = $(POFILES:%.po=%)
+
+all: update merge
+
+update:
+ @cd ../..; \
+ python3 doc/translations/extract.py \
+ --path doc/classes modules/*/doc_classes \
+ --output doc/translations/$(TEMPLATE)
+
+merge:
+ @for po in $(POFILES); do \
+ echo -e "\nMerging $$po..."; \
+ msgmerge -w 79 -C $$po $$po $(TEMPLATE) > "$$po".new; \
+ mv -f "$$po".new $$po; \
+ done
+
+check:
+ @for po in $(POFILES); do msgfmt -c $$po -o /dev/null; done
diff --git a/doc/translations/extract.py b/doc/translations/extract.py
index 1da6919f0b..cd06e13dda 100644
--- a/doc/translations/extract.py
+++ b/doc/translations/extract.py
@@ -235,7 +235,7 @@ def _generate_translation_catalog_file(unique_msgs, output):
def main():
parser = argparse.ArgumentParser()
- parser.add_argument("--path", "-p", default=".", help="The directory containing XML files to collect.")
+ parser.add_argument("--path", "-p", nargs="+", default=".", help="The directory or directories containing XML files to collect.")
parser.add_argument("--output", "-o", default="translation_catalog.pot", help="The path to the output file.")
args = parser.parse_args()
@@ -243,16 +243,20 @@ def main():
if not os.path.isdir(os.path.dirname(output)) or not output.endswith('.pot'):
print_error("Invalid output path: {}".format(output))
exit(1)
- if not os.path.isdir(args.path):
- print_error("Invalid working directory path: {}".format(args.path))
- exit(1)
- os.chdir(args.path)
- print("Current working dir: {}\n".format(os.getcwd()))
+ classes = OrderedDict()
+ for path in args.path:
+ if not os.path.isdir(path):
+ print_error("Invalid working directory path: {}".format(path))
+ exit(1)
+
+ print("\nCurrent working dir: {}".format(path))
+
+ path_classes = OrderedDict() ## dictionary of key=class_name, value=DescList objects
+ _collect_classes_dir(path, path_classes)
+ classes.update(path_classes)
- classes = OrderedDict() ## dictionary of key=class_name, value=DescList objects
- _collect_classes_dir('.', classes)
- classes = OrderedDict(sorted(classes.items(), key = lambda kv: kv[0].lower() ))
+ classes = OrderedDict(sorted(classes.items(), key = lambda kv: kv[0].lower()))
unique_msgs = _make_translation_catalog(classes)
_generate_translation_catalog_file(unique_msgs, output)