5 from pathlib
import Path
7 from translation_utils
import get_translations
, init_sync_dir
9 RESOURCE_NAME
= "mc.pot"
11 SCRIPT_DIR
= Path(__file__
).parent
12 SOURCE_DIR
= SCRIPT_DIR
.parent
.parent
13 PO_DIR
= SOURCE_DIR
/ "po"
16 def strip_message_locations(work_dir
: Path
):
17 for po_file
in (work_dir
/ filename
for filename
in glob
.glob("*.po", root_dir
=work_dir
)):
19 "".join(line
for line
in po_file
.read_text().splitlines(keepends
=True) if not line
.startswith("#:"))
23 def copy_translations_to_source_dir(source_dir
: Path
, target_dir
: Path
):
24 for po_file
in (source_dir
/ filename
for filename
in glob
.glob("*.po", root_dir
=source_dir
)):
25 (target_dir
/ po_file
.name
).write_text(po_file
.read_text())
28 def update_linguas(po_dir
: Path
):
29 translations
= get_translations(po_dir
)
30 (po_dir
/ "LINGUAS").write_text("# List of available translations\n" + "\n".join(translations
) + "\n")
33 sync_dir
= init_sync_dir(SCRIPT_DIR
, RESOURCE_NAME
)
35 subprocess
.run(("tx", "pull", "--all", "--force"), cwd
=sync_dir
, check
=True)
37 strip_message_locations(sync_dir
)
39 copy_translations_to_source_dir(sync_dir
, PO_DIR
)
41 update_linguas(PO_DIR
)