hints-from-transifex.py 887 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env python3
  2. import glob
  3. import subprocess
  4. from pathlib import Path
  5. from textwrap import wrap
  6. from translation_utils import create_po4a_config, init_sync_dir
  7. RESOURCE_NAME = "mc.hint"
  8. SCRIPT_DIR = Path(__file__).parent
  9. SOURCE_DIR = SCRIPT_DIR.parent.parent
  10. def unwrap_paragraphs():
  11. hint_files = glob.glob(str(SOURCE_DIR / "doc" / "hints" / "l10n" / "mc.hint.*"))
  12. for hint_file in map(Path, hint_files):
  13. lines = hint_file.read_text().split("\n\n")
  14. hint_file.write_text("\n\n".join("".join(wrap(line, width=1024)) for line in lines) + "\n")
  15. sync_dir = init_sync_dir(SCRIPT_DIR, RESOURCE_NAME)
  16. subprocess.run(("tx", "pull", "--all", "--force"), cwd=sync_dir, check=True)
  17. po4a_config = create_po4a_config(sync_dir, SCRIPT_DIR, SOURCE_DIR, RESOURCE_NAME)
  18. subprocess.run(("po4a", str(po4a_config)), cwd=SCRIPT_DIR, check=True)
  19. unwrap_paragraphs()