Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb86b9c5

Browse files
authored
Get translation stats from local PO files (#256)
* Get translation stats from local PO files* Add percentage sign
1 parent4bf908d commitb86b9c5

File tree

3 files changed

+72
-19
lines changed

3 files changed

+72
-19
lines changed

‎.github/workflows/sync.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
repository:'python/cpython'
3939
ref:${{ env.PYDOC_VERSION }}
4040
path:cpython
41-
41+
4242
-name:Set language dir variable
4343
run:
4444
echo "LANGUAGE_DIR=cpython/Doc/locales/${{ env.PYDOC_LANGUAGE }}/LC_MESSAGES" >> $GITHUB_ENV
@@ -113,12 +113,10 @@ jobs:
113113
powrap *.po **/*.po
114114
115115
-name:Update statistics
116-
if:always() && steps.secret-check.outputs.available == 'true'
116+
if:always()
117117
run:|
118-
python./scripts/tx_stats.py > ./${{ env.LANGUAGE_DIR }}/stats.json
118+
./scripts/stats.py
119119
git -C ./${{ env.LANGUAGE_DIR }} diff stats.json
120-
env:
121-
TX_TOKEN:${{ secrets.TX_TOKEN }}
122120
123121
-name:Update potodo.md
124122
if:always()

‎README.rst

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,46 +29,46 @@ Maintained versions:
2929
* - `3.13<https://github.com/python/python-docs-pt-br/tree/3.13>`_
3030
- .. image:: https://github.com/python/python-docs-pt-br/workflows/python-313/badge.svg
3131
:target: https://github.com/python/python-docs-pt-br/actions?workflow=python-313
32-
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpython%2Fpython-docs-pt-br%2Fraw%2F3.13%2Fstats.json&query=translation&label=pt_BR
32+
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpython%2Fpython-docs-pt-br%2Fraw%2F3.13%2Fstats.json&query=completion&label=pt_BR
3333
:alt: Brazilian Portuguese translation status for Python 3.13
3434
:target: https://app.transifex.com/python-doc/python-newest/
35-
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpython%2Fpython-docs-pt-br%2Fraw%2F3.13%2Fstats.json&query=total&label=3.13
35+
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpython%2Fpython-docs-pt-br%2Fraw%2F3.13%2Fstats.json&query=entries&label=3.13
3636
:alt: Total strings for Python 3.13
3737
:target: https://app.transifex.com/python-doc/python-newest/
3838
* - `3.12<https://github.com/python/python-docs-pt-br/tree/3.12>`_
3939
- .. image:: https://github.com/python/python-docs-pt-br/workflows/python-312/badge.svg
4040
:target: https://github.com/python/python-docs-pt-br/actions?workflow=python-312
41-
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpython%2Fpython-docs-pt-br%2Fraw%2F3.12%2Fstats.json&query=translation&label=pt_BR
41+
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpython%2Fpython-docs-pt-br%2Fraw%2F3.12%2Fstats.json&query=completion&label=pt_BR
4242
:alt: Brazilian Portuguese translation status for Python 3.12
4343
:target: https://app.transifex.com/python-doc/python-312/
44-
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpython%2Fpython-docs-pt-br%2Fraw%2F3.12%2Fstats.json&query=total&label=3.12
44+
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpython%2Fpython-docs-pt-br%2Fraw%2F3.12%2Fstats.json&query=entries&label=3.12
4545
:alt: Total strings for Python 3.12
4646
:target: https://app.transifex.com/python-doc/python-312/
4747
* - `3.11<https://github.com/python/python-docs-pt-br/tree/3.11>`_
4848
- .. image:: https://github.com/python/python-docs-pt-br/workflows/python-311/badge.svg
4949
:target: https://github.com/python/python-docs-pt-br/actions?workflow=python-311
50-
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpython%2Fpython-docs-pt-br%2Fraw%2F3.11%2Fstats.json&query=translation&label=pt_BR
50+
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpython%2Fpython-docs-pt-br%2Fraw%2F3.11%2Fstats.json&query=completion&label=pt_BR
5151
:alt: Brazilian Portuguese translation status for Python 3.11
5252
:target: https://app.transifex.com/python-doc/python-311/
53-
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpython%2Fpython-docs-pt-br%2Fraw%2F3.11%2Fstats.json&query=total&label=3.11
53+
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpython%2Fpython-docs-pt-br%2Fraw%2F3.11%2Fstats.json&query=entries&label=3.11
5454
:alt: Total strings for Python 3.11
5555
:target: https://app.transifex.com/python-doc/python-311/
5656
* - `3.10<https://github.com/python/python-docs-pt-br/tree/3.10>`_
5757
- .. image:: https://github.com/python/python-docs-pt-br/workflows/python-310/badge.svg
5858
:target: https://github.com/python/python-docs-pt-br/actions?workflow=python-310
59-
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpython%2Fpython-docs-pt-br%2Fraw%2F3.10%2Fstats.json&query=translation&label=pt_BR
59+
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpython%2Fpython-docs-pt-br%2Fraw%2F3.10%2Fstats.json&query=completion&label=pt_BR
6060
:alt: Brazilian Portuguese translation status for Python 3.10
6161
:target: https://app.transifex.com/python-doc/python-310/
62-
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpython%2Fpython-docs-pt-br%2Fraw%2F3.10%2Fstats.json&query=total&label=3.10
62+
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpython%2Fpython-docs-pt-br%2Fraw%2F3.10%2Fstats.json&query=entries&label=3.10
6363
:alt: Total strings for Python 3.10
6464
:target: https://app.transifex.com/python-doc/python-310/
6565
* - `3.9<https://github.com/python/python-docs-pt-br/tree/3.9>`_
6666
- .. image:: https://github.com/python/python-docs-pt-br/workflows/python-39/badge.svg
6767
:target: https://github.com/python/python-docs-pt-br/actions?workflow=python-39
68-
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpython%2Fpython-docs-pt-br%2Fraw%2F3.9%2Fstats.json&query=translation&label=pt_BR
68+
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpython%2Fpython-docs-pt-br%2Fraw%2F3.9%2Fstats.json&query=completion&label=pt_BR
6969
:alt: Brazilian Portuguese translation status for Python 3.9
7070
:target: https://app.transifex.com/python-doc/python-39/
71-
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpython%2Fpython-docs-pt-br%2Fraw%2F3.9%2Fstats.json&query=total&label=3.9
71+
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpython%2Fpython-docs-pt-br%2Fraw%2F3.9%2Fstats.json&query=entries&label=3.9
7272
:alt: Total strings for Python 3.9
7373
:target: https://app.transifex.com/python-doc/python-39/
7474

@@ -87,19 +87,19 @@ EOL versions:
8787
* - `3.8<https://github.com/python/python-docs-pt-br/tree/3.8>`_
8888
- .. image:: https://github.com/python/python-docs-pt-br/workflows/python-38/badge.svg
8989
:target: https://github.com/python/python-docs-pt-br/actions?workflow=python-38
90-
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpython%2Fpython-docs-pt-br%2Fraw%2F3.8%2Fstats.json&query=translation&label=pt_BR
90+
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpython%2Fpython-docs-pt-br%2Fraw%2F3.8%2Fstats.json&query=completion&label=pt_BR
9191
:alt: Brazilian Portuguese translation status for Python 3.8
9292
:target: https://app.transifex.com/python-doc/python-38/
93-
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpython%2Fpython-docs-pt-br%2Fraw%2F3.8%2Fstats.json&query=total&label=3.8
93+
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpython%2Fpython-docs-pt-br%2Fraw%2F3.8%2Fstats.json&query=entries&label=3.8
9494
:alt: Total strings for Python 3.8
9595
:target: https://app.transifex.com/python-doc/python-38/
9696
* - `3.7<https://github.com/python/python-docs-pt-br/tree/3.7>`_
9797
- .. image:: https://github.com/python/python-docs-pt-br/workflows/python-37/badge.svg
9898
:target: https://github.com/python/python-docs-pt-br/actions?workflow=python-37
99-
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpython%2Fpython-docs-pt-br%2Fraw%2F3.7%2Fstats.json&query=translation&label=pt_BR
99+
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpython%2Fpython-docs-pt-br%2Fraw%2F3.7%2Fstats.json&query=completion&label=pt_BR
100100
:alt: Brazilian Portuguese translation status for Python 3.7
101101
:target: https://app.transifex.com/python-doc/python-37/
102-
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpython%2Fpython-docs-pt-br%2Fraw%2F3.7%2Fstats.json&query=total&label=3.7
102+
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpython%2Fpython-docs-pt-br%2Fraw%2F3.7%2Fstats.json&query=entries&label=3.7
103103
:alt: Total strings for Python 3.7
104104
:target: https://app.transifex.com/python-doc/python-37/
105105

‎scripts/stats.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env python
2+
"""
3+
Obtain translation stats from the PO files directory and
4+
store it with JSON format into 'stats.json'.
5+
"""
6+
7+
importjson
8+
importos
9+
importlogging
10+
fromdatetimeimportdatetime,timezone
11+
frompathlibimportPath
12+
13+
frompotodo.potodoimportscan_path
14+
15+
logging.basicConfig(level=logging.INFO)
16+
17+
18+
defmain()->None:
19+
"""Main function to generate translation stats."""
20+
language=os.environ.get("PYDOC_LANGUAGE")
21+
ifnotlanguage:
22+
raiseValueError("Environment variable PYDOC_LANGUAGE is not set.")
23+
24+
pofiles_path=Path(f"cpython/Doc/locales/{language}/LC_MESSAGES")
25+
ifnotpofiles_path.exists():
26+
raiseFileNotFoundError(f"Path does not exist:{pofiles_path}")
27+
28+
# Check for PO files inside the pofiles_path
29+
ifnotlist(pofiles_path.rglob("*.po")):
30+
raiseFileNotFoundError(f"No PO files found in{pofiles_path}")
31+
32+
stats=scan_path(pofiles_path,no_cache=True,hide_reserved=False,api_url="")
33+
34+
stats_data= {
35+
"completion":str(round(stats.completion,2))+"%",
36+
"translated":stats.translated,
37+
"entries":stats.entries,
38+
"updated_at":datetime.now(timezone.utc).isoformat(timespec="seconds")+"Z",
39+
}
40+
41+
stats_json=pofiles_path/"stats.json"
42+
try:
43+
withstats_json.open("w")asoutput_file:
44+
json.dump(stats_data,output_file)
45+
logging.info(f"Content written to{stats_json}")
46+
exceptIOErrorase:
47+
logging.error(f"Failed to write to{stats_json}:{e}")
48+
raise
49+
50+
51+
if__name__=="__main__":
52+
try:
53+
main()
54+
exceptExceptionase:
55+
logging.error(f"An error occurred:{e}")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp