FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-docs-fa/scripts/compile_mo.py at 3.14 · python/python-docs-fa · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
python
/
python-docs-fa
Public
Notifications
You must be signed in to change notification settings
Fork
11
Star
51
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-docs-fa
/
scripts
/
compile_mo.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
57 lines (41 loc) · 1.49 KB
Breadcrumbs
python-docs-fa
/
scripts
/
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
()
Back
|
FazBrowse Home
|
New Git URL