Skip to content

Commit 09da482

Browse files
authored
Fix translation progress badges (#318)
Create a new `.stat.json` file for each sync. A badge will be generated based on this stat file.
1 parent fdb12f6 commit 09da482

File tree

9 files changed

+55
-9
lines changed

9 files changed

+55
-9
lines changed

‎.github/ISSUE_TEMPLATE/translation.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ body:
1111
id: version
1212
attributes:
1313
label: Python Version
14-
description: Which version of Python docs contains the issue?
14+
description: Which version of the Python documentation covers this issue?
1515
placeholder: ex. 3.12
1616
validations:
1717
required: true
1818
- type: input
1919
id: url
2020
attributes:
2121
label: Docs Page
22-
description: What is the url of the page contains the issue?
22+
description: What is the url of the page containing the issue?
2323
placeholder: https://docs.python.org/3/about.html
2424
validations:
2525
required: true
@@ -41,6 +41,6 @@ body:
4141
id: zh-suggested
4242
attributes:
4343
label: Suggested Fix
44-
description: What is you suggeest fix?
44+
description: What is your suggested fix?
4545
validations:
4646
required: true

‎.github/scripts/tx_stat.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import json
2+
import os
3+
import urllib.request
4+
from datetime import datetime
5+
6+
key = os.environ.get('TX_TOKEN')
7+
project = os.environ.get('TX_PROJECT')
8+
9+
url = "https://rest.api.transifex.com/resource_language_stats?filter[project]=o%3Apython-doc%3Ap%3A{}&filter[language]=l%3Azh_CN".format(project)
10+
11+
headers = {
12+
"accept": "application/vnd.api+json",
13+
"authorization": "Bearer " + key
14+
}
15+
16+
total = 0
17+
translated = 0
18+
19+
while(url):
20+
request = urllib.request.Request(url=url,headers=headers)
21+
22+
with urllib.request.urlopen(request) as response:
23+
data = json.loads(response.read().decode("utf-8"))
24+
url = data['links'].get('next')
25+
for resourse in data['data']:
26+
translated = translated + resourse['attributes']['translated_strings']
27+
total = total + resourse['attributes']['total_strings']
28+
29+
p = '{:.2%}'.format(translated/total)
30+
print(json.dumps({
31+
'translation':p,
32+
'updated_at':datetime.utcnow().isoformat(timespec='seconds') + 'Z',
33+
}))

‎.github/workflows/python-310.yml

+1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ jobs:
1212
uses: ./.github/workflows/sync.yml
1313
with:
1414
version: "3.10"
15+
tx_project: "python-310"
1516
secrets: inherit
1617

‎.github/workflows/python-311.yml

+1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ jobs:
1212
uses: ./.github/workflows/sync.yml
1313
with:
1414
version: "3.11"
15+
tx_project: "python-311"
1516
secrets: inherit
1617

‎.github/workflows/python-312.yml

+1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ jobs:
1212
uses: ./.github/workflows/sync.yml
1313
with:
1414
version: "3.12"
15+
tx_project: "python-newest"
1516
secrets: inherit

‎.github/workflows/python-38.yml

+1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ jobs:
1212
uses: ./.github/workflows/sync.yml
1313
with:
1414
version: "3.8"
15+
tx_project: "python-38"
1516
secrets: inherit

‎.github/workflows/python-39.yml

+1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ jobs:
1212
uses: ./.github/workflows/sync.yml
1313
with:
1414
version: "3.9"
15+
tx_project: "python-39"
1516
secrets: inherit
1617

‎.github/workflows/sync.yml

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
version:
77
required: true
88
type: string
9+
tx_project:
10+
required: true
11+
type: string
912
secrets:
1013
TRANSIFEX_APIKEY:
1114
required: true
@@ -37,5 +40,10 @@ jobs:
3740
TX_TOKEN: ${{ secrets.TRANSIFEX_APIKEY }}
3841
- name: build
3942
run: .github/scripts/build.sh
43+
- name: stat
44+
run: python .github/scripts/tx_stat.py > ./docs/.stat.json
45+
env:
46+
TX_TOKEN: ${{ secrets.TRANSIFEX_APIKEY }}
47+
TX_PROJECT: ${{ inputs.tx_project }}
4048
- name: commit
4149
run: .github/scripts/commit.sh

‎README.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,27 @@ Maintained versions:
1515
* - `3.12 <https://github.com/python/python-docs-zh-cn/tree/3.12>`_
1616
- .. image:: https://github.com/python/python-docs-zh-cn/workflows/python-312/badge.svg
1717
:target: https://github.com/python/python-docs-zh-cn/actions?workflow=python-312
18-
- .. image:: https://img.shields.io/badge/dynamic/json.svg?label=zh_CN&query=%24.zh_CN&url=http://gce.zhsj.me/python/312
18+
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fpython%2Fpython-docs-zh-cn%2F3.12%2F.stat.json&query=%24.translation&label=zh-CN
1919
:target: https://app.transifex.com/python-doc/python-newest/
2020
* - `3.11 <https://github.com/python/python-docs-zh-cn/tree/3.11>`_
2121
- .. image:: https://github.com/python/python-docs-zh-cn/workflows/python-311/badge.svg
2222
:target: https://github.com/python/python-docs-zh-cn/actions?workflow=python-311
23-
- .. image:: https://img.shields.io/badge/dynamic/json.svg?label=zh_CN&query=%24.zh_CN&url=http://gce.zhsj.me/python/311
23+
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fpython%2Fpython-docs-zh-cn%2F3.11%2F.stat.json&query=%24.translation&label=zh-CN
2424
:target: https://app.transifex.com/python-doc/python-311/
2525
* - `3.10 <https://github.com/python/python-docs-zh-cn/tree/3.10>`_
2626
- .. image:: https://github.com/python/python-docs-zh-cn/workflows/python-310/badge.svg
2727
:target: https://github.com/python/python-docs-zh-cn/actions?workflow=python-310
28-
- .. image:: https://img.shields.io/badge/dynamic/json.svg?label=zh_CN&query=%24.zh_CN&url=http://gce.zhsj.me/python/310
28+
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fpython%2Fpython-docs-zh-cn%2F3.10%2F.stat.json&query=%24.translation&label=zh-CN
2929
:target: https://app.transifex.com/python-doc/python-310/
3030
* - `3.9 <https://github.com/python/python-docs-zh-cn/tree/3.9>`_
3131
- .. image:: https://github.com/python/python-docs-zh-cn/workflows/python-39/badge.svg
3232
:target: https://github.com/python/python-docs-zh-cn/actions?workflow=python-39
33-
- .. image:: https://img.shields.io/badge/dynamic/json.svg?label=zh_CN&query=%24.zh_CN&url=http://gce.zhsj.me/python/39
33+
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fpython%2Fpython-docs-zh-cn%2F3.9%2F.stat.json&query=%24.translation&label=zh-CN
3434
:target: https://app.transifex.com/python-doc/python-39/
3535
* - `3.8 <https://github.com/python/python-docs-zh-cn/tree/3.8>`_
3636
- .. image:: https://github.com/python/python-docs-zh-cn/workflows/python-38/badge.svg
3737
:target: https://github.com/python/python-docs-zh-cn/actions?workflow=python-38
38-
- .. image:: https://img.shields.io/badge/dynamic/json.svg?label=zh_CN&query=%24.zh_CN&url=http://gce.zhsj.me/python/38
38+
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fpython%2Fpython-docs-zh-cn%2F3.8%2F.stat.json&query=%24.translation&label=zh-CN
3939
:target: https://app.transifex.com/python-doc/python-38/
4040

4141
EOL versions:
@@ -49,7 +49,7 @@ EOL versions:
4949
* - `3.7 <https://github.com/python/python-docs-zh-cn/tree/3.7>`_
5050
- .. image:: https://github.com/python/python-docs-zh-cn/workflows/python-37/badge.svg
5151
:target: https://github.com/python/python-docs-zh-cn/actions?workflow=python-37
52-
- .. image:: https://img.shields.io/badge/dynamic/json.svg?label=zh_CN&query=%24.zh_CN&url=http://gce.zhsj.me/python/37
52+
- .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fpython%2Fpython-docs-zh-cn%2F3.7%2F.stat.json&query=%24.translation&label=zh-CN
5353
:target: https://app.transifex.com/python-doc/python-37/
5454

5555
Documentation Contribution Agreement

0 commit comments

Comments
 (0)