2 from pathlib
import Path
5 def get_config_file(root_dir
: Path
, resource
: str, name
: str) -> Path
:
6 return root_dir
/ "config.d" / resource
/ name
9 def init_sync_dir(root_dir
: Path
, resource
: str) -> Path
:
10 tx_dir
= root_dir
/ "var.d" / resource
/ ".tx"
11 tx_dir
.mkdir(parents
=True, exist_ok
=True)
12 (tx_dir
/ "config").write_text(get_config_file(root_dir
, resource
, "tx.config").read_text())
16 def create_po4a_config(sync_dir
: Path
, script_dir
: Path
, source_dir
: Path
, resource
: str) -> Path
:
17 langs
= get_translations(sync_dir
)
19 config
= get_config_file(script_dir
, resource
, "po4a.cfg").read_text()
21 config
= config
.replace("@translations@", " ".join(f
"{lang}:var.d/$master/{lang}.po" for lang
in langs
))
22 config
= config
.replace("@resources@", " ".join(f
"{lang}:@srcdir@/doc/hints/l10n/mc.hint.{lang}" for lang
in langs
))
24 config
= config
.replace("@srcdir@", str(source_dir
))
26 config_path
= sync_dir
/ "po4a.cfg"
27 config_path
.write_text(config
)
32 def get_translations(root_dir
: Path
) -> list[str]:
33 return sorted(Path(filename
).name
.removesuffix(".po") for filename
in glob
.glob("*.po", root_dir
=root_dir
))