diff --git a/.github/ISSUE_TEMPLATE/translation.yml b/.github/ISSUE_TEMPLATE/translation.yml new file mode 100644 index 000000000..780ebc722 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/translation.yml @@ -0,0 +1,46 @@ +name: Translation Issue Report +description: File a translation issue report +title: "[Typo]: " +labels: ["translation"] +body: + - type: markdown + attributes: + value: | + Thanks for taking the time to fill out this translation issue report! + - type: input + id: version + attributes: + label: Python Version + 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 containing the issue? + placeholder: https://docs.python.org/3/about.html + validations: + required: true + - type: textarea + id: zh-original + attributes: + label: Original Translation + description: Which translated paragraph in Chinese contains the issue? + validations: + required: true + - type: textarea + id: en-original + attributes: + label: Original Docs Paragraph + description: Which original paragraph in English contains the issue? + validations: + required: false + - type: textarea + id: zh-suggested + attributes: + label: Suggested Fix + description: What is your suggested fix? + validations: + required: true \ No newline at end of file diff --git a/.github/scripts/build.sh b/.github/scripts/build.sh new file mode 100755 index 000000000..46c229e10 --- /dev/null +++ b/.github/scripts/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +set -e +set -u +set -o pipefail + +error() { + while read -r line; do + echo + echo ::error::"$line" + done +} + +cd cpython/Doc || exit 1 +mkdir -p locales/"$LOCALE"/ +ln -sfn "$(realpath ../../docs)" locales/"$LOCALE"/LC_MESSAGES +pip3 install -q -r requirements.txt +sphinx-build -b dummy -d build/doctrees -j auto -D language=$LOCALE -D gettext_compact=0 -E --keep-going -W . build/html 2> >(error) diff --git a/.github/scripts/commit.sh b/.github/scripts/commit.sh new file mode 100755 index 000000000..878c0d57e --- /dev/null +++ b/.github/scripts/commit.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -ex + +cd docs || exit 1 +git config user.email "github-actions[bot]@users.noreply.github.com" +git config user.name "github-actions[bot]" +if ! git status -s|grep '\.po'; then + echo "Nothing to commit" + exit 0 +fi +git add . +git commit -m '[po] auto sync' +git push diff --git a/.github/scripts/generate_tx_config.py b/.github/scripts/generate_tx_config.py new file mode 100755 index 000000000..ebcc3b2dd --- /dev/null +++ b/.github/scripts/generate_tx_config.py @@ -0,0 +1,87 @@ +"""Please note that this script requires a Transifex API token to run.""" +import glob +import subprocess +from functools import partial +from pathlib import Path +import re +import os + +run = partial(subprocess.run, check=True) + + +def init_project(): + run(["tx", "init"]) + + +def add_files(project_name: str): + run( + [ + "tx", + "add", + "remote", + "--file-filter", + "trans//.", + f"https://www.transifex.com/python-doc/{project_name}/dashboard/", + ] + ) + + +FILTER_PATTERN = re.compile( + r"^(?Pfile_filter( *)=( *))(?P.+)$", re.MULTILINE +) + + +def name_replacer(match: re.Match[str]): + prefix, resource = match.group("prefix", "resource") + override_prefix = prefix.replace("file_filter", "trans.zh_CN") + pattern = ( + resource.replace("trans//", "") + .replace("glossary_", "glossary") + .replace("--", "/") + .replace("_", "?") + ) + matches = list(glob.glob(pattern.replace(".po", ".rst"))) + if not matches: + print("missing", pattern) + return f"{prefix}{resource}\n{override_prefix}{pattern.replace('?', '_')}" + elif len(matches) == 1: + filename = matches[0].replace(".rst", ".po").replace("\\", "/") + else: + raise ValueError("multi match", resource, pattern, matches) + return f"{prefix}{resource}\n{override_prefix}{filename}" + + +def patch_config(path: str): + tx_config_path = Path(".tx", "config") + + config_content = tx_config_path.read_text("utf-8") + + cwd = os.getcwd() + os.chdir(path) + config_content = FILTER_PATTERN.sub(name_replacer, config_content) + config_content = re.sub(r'replace_edited_strings.*\n','', config_content) + config_content = re.sub(r'keep_translations.*\n','', config_content) + config_content = re.sub(r'0\ntrans\.zh_CN.*\n','0\n', config_content) + config_content = config_content.replace(' =','=') + os.chdir(cwd) + + tx_config_path.write_text(config_content, "utf-8") + + +if __name__ == "__main__": + from argparse import ArgumentParser + + parser = ArgumentParser() + + parser.add_argument("--token", default="") + parser.add_argument("--project-name", required=True) + parser.add_argument("--doc-path", required=True) + + params = parser.parse_args() + + if params.token: + os.environ["TX_TOKEN"] = params.token + + init_project() + add_files(params.project_name) + patch_config(params.doc_path) diff --git a/.github/scripts/prepare.sh b/.github/scripts/prepare.sh new file mode 100755 index 000000000..1ca5daab0 --- /dev/null +++ b/.github/scripts/prepare.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +set -ex + +curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash \ No newline at end of file diff --git a/.github/scripts/tx_stat.py b/.github/scripts/tx_stat.py new file mode 100644 index 000000000..00dcf965c --- /dev/null +++ b/.github/scripts/tx_stat.py @@ -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', + })) \ No newline at end of file diff --git a/.github/scripts/update.sh b/.github/scripts/update.sh new file mode 100755 index 000000000..0f2231d9f --- /dev/null +++ b/.github/scripts/update.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -u + +cd cpython || exit 1 + +# Restore git timestamp for enabling build cache +rev=HEAD +for f in $(git ls-tree -r -t --full-name --name-only "$rev" Doc) ; do + touch -d $(git log --pretty=format:%cI -1 "$rev" -- "$f") "$f"; +done + +cd .. +cd docs || exit 1 + +# Restore git timestamp for enabling build cache +rev=HEAD +for f in $(git ls-tree -r -t --full-name --name-only "$rev") ; do + touch -d $(git log --pretty=format:%cI -1 "$rev" -- "$f") "$f"; +done + +$(realpath ../tx) pull --languages "$LOCALE" -t --use-git-timestamps --workers 25 --silent diff --git a/.github/workflows/python-310.yml b/.github/workflows/python-310.yml new file mode 100644 index 000000000..35a148f47 --- /dev/null +++ b/.github/workflows/python-310.yml @@ -0,0 +1,18 @@ +name: python-310 + +on: + workflow_dispatch: + push: + branches: + - master + schedule: + - cron: "22 * * * *" + +jobs: + sync: + uses: ./.github/workflows/sync.yml + with: + version: "3.10" + tx_project: "python-310" + secrets: inherit + \ No newline at end of file diff --git a/.github/workflows/python-311.yml b/.github/workflows/python-311.yml new file mode 100644 index 000000000..4fa85bb77 --- /dev/null +++ b/.github/workflows/python-311.yml @@ -0,0 +1,18 @@ +name: python-311 + +on: + workflow_dispatch: + push: + branches: + - master + schedule: + - cron: "32 * * * *" + +jobs: + sync: + uses: ./.github/workflows/sync.yml + with: + version: "3.11" + tx_project: "python-311" + secrets: inherit + diff --git a/.github/workflows/python-312.yml b/.github/workflows/python-312.yml new file mode 100644 index 000000000..75cc1d35e --- /dev/null +++ b/.github/workflows/python-312.yml @@ -0,0 +1,17 @@ +name: python-312 + +on: + workflow_dispatch: + push: + branches: + - master + schedule: + - cron: "42 * * * *" + +jobs: + sync: + uses: ./.github/workflows/sync.yml + with: + version: "3.12" + tx_project: "python-312" + secrets: inherit diff --git a/.github/workflows/python-313.yml b/.github/workflows/python-313.yml new file mode 100644 index 000000000..657d53443 --- /dev/null +++ b/.github/workflows/python-313.yml @@ -0,0 +1,17 @@ +name: python-313 + +on: + workflow_dispatch: + push: + branches: + - master + schedule: + - cron: "52 * * * *" + +jobs: + sync: + uses: ./.github/workflows/sync.yml + with: + version: "3.13" + tx_project: "python-newest" + secrets: inherit diff --git a/.github/workflows/python-37.yml b/.github/workflows/python-37.yml new file mode 100644 index 000000000..47c224c3b --- /dev/null +++ b/.github/workflows/python-37.yml @@ -0,0 +1,10 @@ +name: python-37 + +on: workflow_dispatch + +jobs: + sync: + uses: ./.github/workflows/sync.yml + with: + version: "3.7" + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/python-38.yml b/.github/workflows/python-38.yml new file mode 100644 index 000000000..9d0bc6daf --- /dev/null +++ b/.github/workflows/python-38.yml @@ -0,0 +1,11 @@ +name: python-38 + +on: workflow_dispatch + +jobs: + sync: + uses: ./.github/workflows/sync.yml + with: + version: "3.8" + tx_project: "python-38" + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/python-39.yml b/.github/workflows/python-39.yml new file mode 100644 index 000000000..39305f585 --- /dev/null +++ b/.github/workflows/python-39.yml @@ -0,0 +1,18 @@ +name: python-39 + +on: + workflow_dispatch: + push: + branches: + - master + schedule: + - cron: "12 * * * *" + +jobs: + sync: + uses: ./.github/workflows/sync.yml + with: + version: "3.9" + tx_project: "python-39" + secrets: inherit + \ No newline at end of file diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml new file mode 100644 index 000000000..0788a37c0 --- /dev/null +++ b/.github/workflows/sync.yml @@ -0,0 +1,68 @@ +name: Reusable workflow example + +on: + workflow_call: + inputs: + version: + required: true + type: string + tx_project: + required: true + type: string + secrets: + TRANSIFEX_APIKEY: + required: true + +jobs: + sync: + runs-on: ubuntu-latest + env: + LOCALE: zh_CN + VERSION: ${{ inputs.version }} + steps: + - uses: actions/checkout@v4 + - name: Checkout CPython + uses: actions/checkout@v4 + with: + repository: 'python/cpython' + ref: ${{env.VERSION}} + path: cpython + - uses: actions/cache/restore@v4 + with: + path: | + cpython/Doc/build + docs + key: cache-${{ inputs.version }}-${{ github.run_id }} + restore-keys: cache-${{ inputs.version }}- + - name: Checkout Current Branch + uses: actions/checkout@v4 + with: + ref: ${{env.VERSION}} + path: docs + clean: false + - name: prepare + run: .github/scripts/prepare.sh + - name: update + run: .github/scripts/update.sh + env: + TX_TOKEN: ${{ secrets.TRANSIFEX_APIKEY }} + - uses: actions/cache/restore@v4 + with: + path: cpython/Doc/build + key: cache-${{ inputs.version }}-${{ github.run_id }} + restore-keys: cache-${{ inputs.version }}- + - name: build + run: .github/scripts/build.sh + - uses: actions/cache/save@v4 + with: + path: | + cpython/Doc/build + docs + key: cache-${{ inputs.version }}-${{ github.run_id }} + - 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 \ No newline at end of file diff --git a/README.rst b/README.rst index 2209635d1..a4eb6ee9a 100644 --- a/README.rst +++ b/README.rst @@ -4,7 +4,58 @@ zh_CN Translation of the Python Documentation All translations are done on transifex. https://www.transifex.com/python-doc/public/ -See branch 3.7 for po files fetched from transifex. +Maintained versions: + +.. list-table:: + :header-rows: 1 + + * - Version + - Sync status + - Translation progress + * - `3.13 `_ + - .. image:: https://github.com/python/python-docs-zh-cn/workflows/python-313/badge.svg + :target: https://github.com/python/python-docs-zh-cn/actions?workflow=python-313 + - .. image:: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fpython%2Fpython-docs-zh-cn%2F3.13%2F.stat.json&query=%24.translation&label=zh-CN + :target: https://app.transifex.com/python-doc/python-newest/ + * - `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?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-312/ + * - `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?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 `_ + - .. 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?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 `_ + - .. 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?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/ + +EOL versions: + +.. list-table:: + :header-rows: 1 + + * - Version + - Sync status + - Translation progress + * - `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?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/ + * - `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?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 ------------------------------------ diff --git a/TRANSLATORS b/TRANSLATORS new file mode 100644 index 000000000..8c653ac28 --- /dev/null +++ b/TRANSLATORS @@ -0,0 +1,118 @@ +# The latest translators list is in each po file. +# Following are the names that translators set at Transifex. +# Generated by: +# grep -ohP '(?<=^# )(.+)(?=, \d+$)' -r .|sed 's| <.*>||g' | sort -u + +3vilive D +443 +ailin zhang +allenjuly7 +Aloxaf +ausaki +banxi +cdarlint +chen_chao +Chengeng Ning +ChenYuan +chordy +cissoid +CommonZ +c pan +Danny Vi +dgy18787 +dhcn +dykai +emrich +eric R +Fei Yin +focusheart +Fred +Freesand Leo +gashero liu +hanfeng +Hanxi Fu +Harry Z +Henry Zhu +isaced +isombyt +Jack Wu +Jann Li +Jarry Shaw +Jerry Chen +Josh Ouyang +jsgang +Junkai Shao +Kaizhao Zhang +Kder +keelii +kevin wong +Larry wang +Larry Wang +Madlee +Meng Du +Menghua Xiao +Ming Jia +musan cheng +MuSheng Chen +Nasy +Natasha Li +Pandaaaa906 +Pan Felix +Pikachu +QR Wang +RSNOW +ryohei +Saiyang Gou +sgqy +Shengjing Zhu +shiyu Peng +Siyuan Xu +SKY H. +SonnyZhang +Steve Ni +sunsol s +Thomas ZHANG +tom smith +Tony Tong +Trim21 +TX Lee +walkinrain +Wang Saul +wenhui +wevsty +Woko +Woostundy +Wu Pipi +wwj402 +ww song +xiao xu +Yan Gao +Yinuo Huang +Yiyi Python +YIZHU LIN +yuan chen +yuxin wang +zc Jin +Zephyr Waitzman +Zhe He +Ziqi Wang +zkonge +Zombie110year +付裕如 +兴然 刘 +刘士 +叶浚安 +启迪 吴 +吴彬 +开 方 +张俊(fighting) +志正 韩 +操旭 +林行众 +梁启凡 +欢 王 +殷平乐 +汇民 王 +演奏王 +非法操作 +马强