GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — python-docs-fa/scripts/compile_mo.py at 3.14 · python/python-docs-fa

Expand file tree

/

compile_mo.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
57 lines (41 loc) · 1.49 KB
/

compile_mo.py

Copy path

File metadata and controls

57 lines (41 loc) · 1.49 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/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_tools = os.environ.get(
"MSGFMT_TOOLS_PATH",
os.path.join("venv", "cpython", "Tools", "i18n"),
)
sys.path.insert(0, _venv_tools)
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()
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.