Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ build:
- mkdir -p venv/cpython/Doc/locales/fa/LC_MESSAGES
- cp --parents *.po venv/cpython/Doc/locales/fa/LC_MESSAGES/
- find */ -name "*.po" -not -path "venv/*" | xargs -I{} cp --parents {} venv/cpython/Doc/locales/fa/LC_MESSAGES/
- find venv/cpython/Doc/locales/fa/LC_MESSAGES -name "*.po" | xargs python3 scripts/strip_fuzzy.py
- find venv/cpython/Doc/locales/fa/LC_MESSAGES -name "*.po" | while read f; do python venv/cpython/Tools/i18n/msgfmt.py -o "${f%.po}.mo" "$f"; done
- find venv/cpython/Doc/locales/fa/LC_MESSAGES -name "*.po" | python3 scripts/compile_mo.py
- python -m sphinx -T -j auto -b html
-d $READTHEDOCS_OUTPUT/doctrees
-D language=fa
Expand All @@ -21,4 +20,4 @@ build:
-D gettext_allow_fuzzy_translations=1
-D html_theme_options.is_rtl=1
venv/cpython/Doc
$READTHEDOCS_OUTPUT/html
$READTHEDOCS_OUTPUT/html
54 changes: 54 additions & 0 deletions scripts/compile_mo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python3
"""Strip stray '#, fuzzy' markers and compile .po files to .mo, in one pass.

CPython's Tools/i18n/msgfmt.py treats a fuzzy flag on the file header as
applying to every entry in the file, silently producing an empty .mo
catalog. Since our translations are complete (not actually rough
drafts), we strip the marker before compiling.

Compilation calls msgfmt.make() directly instead of spawning a fresh
Python interpreter per file, since interpreter startup is the dominant
cost when compiling hundreds of small .po files.

Reads paths from stdin (one per line, e.g. via `find ... | python3
compile_mo.py`).
"""
import sys
import os

# venv/cpython/Tools/i18n/msgfmt.py, relative to repo root.
sys.path.insert(0, os.path.join("venv", "cpython", "Tools", "i18n"))
import msgfmt # noqa: E402


def strip_fuzzy(path: str) -> None:
with open(path, encoding="utf-8") as f:
lines = f.readlines()

kept = [line for line in lines if not line.lstrip().startswith("#, fuzzy")]

if kept != lines:
with open(path, "w", encoding="utf-8") as f:
f.writelines(kept)


def compile_po(path: str) -> None:
msgfmt.MESSAGES = {}
out = path[:-3] + ".mo" if path.endswith(".po") else path + ".mo"
msgfmt.make(path, out)


def process(path: str) -> None:
strip_fuzzy(path)
compile_po(path)


def main() -> None:
for line in sys.stdin:
path = line.strip()
if path:
process(path)


if __name__ == "__main__":
main()
29 changes: 0 additions & 29 deletions scripts/strip_fuzzy.py

This file was deleted.

Loading