Skip to content

Fix translation progress badge #318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 4, 2023
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/translation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ body:
id: version
attributes:
label: Python Version
description: Which version of Python docs contains the issue?
description: Which version of the Python documentation covers this issue?
placeholder: ex. 3.12
validations:
required: true
- type: input
id: url
attributes:
label: Docs Page
description: What is the url of the page contains the issue?
description: What is the url of the page containing the issue?
placeholder: https://docs.python.org/3/about.html
validations:
required: true
Expand All @@ -41,6 +41,6 @@ body:
id: zh-suggested
attributes:
label: Suggested Fix
description: What is you suggeest fix?
description: What is your suggested fix?
validations:
required: true
33 changes: 33 additions & 0 deletions .github/scripts/tx_stat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import json
import os
import urllib.request
from datetime import datetime

key = os.environ.get('TX_TOKEN')
project = os.environ.get('TX_PROJECT')

url = "https://rest.api.transifex.com/resource_language_stats?filter[project]=o%3Apython-doc%3Ap%3A{}&filter[language]=l%3Azh_CN".format(project)

headers = {
"accept": "application/vnd.api+json",
"authorization": "Bearer " + key
}

total = 0
translated = 0

while(url):
request = urllib.request.Request(url=url,headers=headers)

with urllib.request.urlopen(request) as response:
data = json.loads(response.read().decode("utf-8"))
url = data['links'].get('next')
for resourse in data['data']:
translated = translated + resourse['attributes']['translated_strings']
total = total + resourse['attributes']['total_strings']

p = '{:.2%}'.format(translated/total)
print(json.dumps({
'translation':p,
'updated_at':datetime.utcnow().isoformat(timespec='seconds') + 'Z',
}))
1 change: 1 addition & 0 deletions .github/workflows/python-310.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ jobs:
uses: ./.github/workflows/sync.yml
with:
version: "3.10"
tx_project: "python-310"
secrets: inherit

1 change: 1 addition & 0 deletions .github/workflows/python-311.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ jobs:
uses: ./.github/workflows/sync.yml
with:
version: "3.11"
tx_project: "python-311"
secrets: inherit

1 change: 1 addition & 0 deletions .github/workflows/python-312.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ jobs:
uses: ./.github/workflows/sync.yml
with:
version: "3.12"
tx_project: "python-newest"
secrets: inherit
1 change: 1 addition & 0 deletions .github/workflows/python-38.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ jobs:
uses: ./.github/workflows/sync.yml
with:
version: "3.8"
tx_project: "python-38"
secrets: inherit
1 change: 1 addition & 0 deletions .github/workflows/python-39.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ jobs:
uses: ./.github/workflows/sync.yml
with:
version: "3.9"
tx_project: "python-39"
secrets: inherit

8 changes: 8 additions & 0 deletions .github/workflows/sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
version:
required: true
type: string
tx_project:
required: true
type: string
secrets:
TRANSIFEX_APIKEY:
required: true
Expand Down Expand Up @@ -37,5 +40,10 @@ jobs:
TX_TOKEN: ${{ secrets.TRANSIFEX_APIKEY }}
- name: build
run: .github/scripts/build.sh
- name: stat
run: python .github/scripts/tx_stat.py > ./docs/.stat.json
env:
TX_TOKEN: ${{ secrets.TRANSIFEX_APIKEY }}
TX_PROJECT: ${{ inputs.tx_project }}
- name: commit
run: .github/scripts/commit.sh
12 changes: 6 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@ Maintained versions:
* - `3.12 <https://github.com/python/python-docs-zh-cn/tree/3.12>`_
- .. image:: https://github.com/python/python-docs-zh-cn/workflows/python-312/badge.svg
:target: https://github.com/python/python-docs-zh-cn/actions?workflow=python-312
- .. image:: https://img.shields.io/badge/dynamic/json.svg?label=zh_CN&query=%24.zh_CN&url=http://gce.zhsj.me/python/312
- .. 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
:target: https://app.transifex.com/python-doc/python-newest/
* - `3.11 <https://github.com/python/python-docs-zh-cn/tree/3.11>`_
- .. image:: https://github.com/python/python-docs-zh-cn/workflows/python-311/badge.svg
:target: https://github.com/python/python-docs-zh-cn/actions?workflow=python-311
- .. image:: https://img.shields.io/badge/dynamic/json.svg?label=zh_CN&query=%24.zh_CN&url=http://gce.zhsj.me/python/311
- .. 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
:target: https://app.transifex.com/python-doc/python-311/
* - `3.10 <https://github.com/python/python-docs-zh-cn/tree/3.10>`_
- .. image:: https://github.com/python/python-docs-zh-cn/workflows/python-310/badge.svg
:target: https://github.com/python/python-docs-zh-cn/actions?workflow=python-310
- .. image:: https://img.shields.io/badge/dynamic/json.svg?label=zh_CN&query=%24.zh_CN&url=http://gce.zhsj.me/python/310
- .. 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
:target: https://app.transifex.com/python-doc/python-310/
* - `3.9 <https://github.com/python/python-docs-zh-cn/tree/3.9>`_
- .. image:: https://github.com/python/python-docs-zh-cn/workflows/python-39/badge.svg
:target: https://github.com/python/python-docs-zh-cn/actions?workflow=python-39
- .. image:: https://img.shields.io/badge/dynamic/json.svg?label=zh_CN&query=%24.zh_CN&url=http://gce.zhsj.me/python/39
- .. 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
:target: https://app.transifex.com/python-doc/python-39/
* - `3.8 <https://github.com/python/python-docs-zh-cn/tree/3.8>`_
- .. image:: https://github.com/python/python-docs-zh-cn/workflows/python-38/badge.svg
:target: https://github.com/python/python-docs-zh-cn/actions?workflow=python-38
- .. image:: https://img.shields.io/badge/dynamic/json.svg?label=zh_CN&query=%24.zh_CN&url=http://gce.zhsj.me/python/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
:target: https://app.transifex.com/python-doc/python-38/

EOL versions:
Expand All @@ -49,7 +49,7 @@ EOL versions:
* - `3.7 <https://github.com/python/python-docs-zh-cn/tree/3.7>`_
- .. image:: https://github.com/python/python-docs-zh-cn/workflows/python-37/badge.svg
:target: https://github.com/python/python-docs-zh-cn/actions?workflow=python-37
- .. image:: https://img.shields.io/badge/dynamic/json.svg?label=zh_CN&query=%24.zh_CN&url=http://gce.zhsj.me/python/37
- .. 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
:target: https://app.transifex.com/python-doc/python-37/

Documentation Contribution Agreement
Expand Down