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

Appearance settings

Commit 5443800

Browse filesBrowse files
authored
Merge branch '3.12' into feature/upgrade-makefile
2 parents 611c9e8 + 68d438a commit 5443800
Copy full SHA for 5443800

File tree

Expand file treeCollapse file tree

365 files changed

+51056
-45265
lines changed
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

365 files changed

+51056
-45265
lines changed

‎.github/workflows/ci.yml

Copy file name to clipboardExpand all lines: .github/workflows/ci.yml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ jobs:
1313
run: sudo apt-get install gettext
1414

1515
- name: Validate
16-
run: VERSION=${{ github.event.pull_request.base.ref }} MODE=dummy make all
16+
run: VERSION=${{ github.event.repository.default_branch }} MODE=dummy make all
+43Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: summarize_progress
2+
3+
on:
4+
schedule:
5+
- cron: '30 23 * * 5'
6+
7+
jobs:
8+
ci:
9+
if: github.repository == 'python/python-docs-zh-tw'
10+
runs-on: ubuntu-latest
11+
permissions:
12+
# Give the default GITHUB_TOKEN write permission to commit and push the
13+
# added or changed files to the repository.
14+
contents: write
15+
steps:
16+
- uses: actions/checkout@v2
17+
18+
- name: Install poetry
19+
uses: abatilo/actions-poetry@v2
20+
21+
- name: Execute Check Process
22+
run: |
23+
chmod +x .scripts/summarize_progress.sh
24+
.scripts/summarize_progress.sh
25+
shell: bash
26+
27+
28+
- name: Checkout wiki code
29+
uses: actions/checkout@v2
30+
with:
31+
repository: ${{github.repository}}.wiki
32+
path: markdown
33+
34+
- name: Copy content
35+
run: |
36+
cp .scripts/summarize_progress/result.md markdown/各檔案翻譯進度清單.md
37+
shell: bash
38+
39+
- name: Commit wiki code
40+
uses: stefanzweifel/git-auto-commit-action@v5
41+
with:
42+
commit_message: Weekly Update -- Summarize Progress
43+
repository: markdown

‎.pre-commit-config.yaml

Copy file name to clipboard
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Install the pre-commit hooks below with
2+
# 'pre-commit install'
3+
4+
# Auto-update the version of the hooks with
5+
# 'pre-commit autoupdate'
6+
7+
repos:
8+
- repo: https://git.afpy.org/AFPy/powrap
9+
# there's no release tag in repo, use the latest commit hash id instead
10+
rev: a34a9fed116d24562fbe4bb8d456ade85f056c36
11+
hooks:
12+
- id: powrap

‎.scripts/poetry.lock

Copy file name to clipboardExpand all lines: .scripts/poetry.lock
+225-87Lines changed: 225 additions & 87 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.scripts/pyproject.toml

Copy file name to clipboardExpand all lines: .scripts/pyproject.toml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ python = "^3.10"
1010
polib = "1.1.1"
1111
googletrans = "3.1.0a0"
1212
translate-toolkit = "3.8.1"
13-
13+
requests = "2.31.0"
1414

1515
[build-system]
1616
requires = ["poetry-core"]

‎.scripts/summarize_progress.sh

Copy file name to clipboard
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
WORK_DIR=.scripts
4+
cd $WORK_DIR
5+
6+
source utils/install_poetry.sh
7+
8+
poetry lock
9+
poetry install
10+
poetry run bash -c "
11+
python summarize_progress/main.py
12+
"

‎.scripts/summarize_progress/main.py

Copy file name to clipboard
+161Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
import re
2+
import polib
3+
import glob
4+
import requests
5+
6+
from pathlib import Path
7+
8+
9+
def entry_check(pofile: polib.POFile) -> str:
10+
'''
11+
Check the po file with how many entries are translated or not.
12+
'''
13+
14+
lines_tranlated = len(pofile.translated_entries())
15+
lines_untranlated = len(pofile.untranslated_entries())
16+
17+
if lines_tranlated == 0:
18+
result = "❌"
19+
elif lines_untranlated == 0:
20+
result = "✅"
21+
else:
22+
lines_all = lines_tranlated + lines_untranlated
23+
progress = lines_tranlated / lines_all
24+
progress_percentage = round(progress * 100, 2)
25+
result = f"{progress_percentage} %"
26+
27+
return result
28+
29+
30+
def get_open_issues_count() -> int:
31+
'''
32+
Fetch GitHub API to get the number of OPEN ISSUES.
33+
'''
34+
35+
url = f"https://api.github.com/search/issues?q=repo:python/python-docs-zh-tw+type:issue+state:open"
36+
headers = {
37+
"Accept": "application/vnd.github+json",
38+
"X-GitHub-Api-Version": "2022-11-28",
39+
}
40+
r = requests.get(url=url, headers=headers)
41+
result = r.json()
42+
43+
return result["total_count"]
44+
45+
46+
def get_github_issues() -> list:
47+
'''
48+
Fetch GitHub API to collect the infomation of OPEN ISSUES,
49+
including issue title and assignee.
50+
51+
Steps:
52+
1. Fetch GitHub API and get open issue list
53+
2. Filter the issue if it have no "Translate" in the title
54+
3. Filter the issue if it have no correct filepath in the title
55+
56+
Expected Output:
57+
[ ((dirname, filename), assignee_id, issue_url), ... ]
58+
'''
59+
NUMBER_OF_ISSUES = get_open_issues_count()
60+
61+
url = f"https://api.github.com/search/issues?q=repo:python/python-docs-zh-tw+type:issue+state:open&per_page={NUMBER_OF_ISSUES}"
62+
headers = {
63+
"Accept": "application/vnd.github+json",
64+
"X-GitHub-Api-Version": "2022-11-28",
65+
}
66+
r = requests.get(url=url, headers=headers)
67+
result = r.json()
68+
69+
result_list = []
70+
for issue in result["items"]:
71+
assignee = issue["assignee"]["login"] if issue["assignee"] else ""
72+
73+
title = issue["title"]
74+
if "翻譯" not in title and "translate" not in title.lower():
75+
continue
76+
77+
match = re.search(
78+
"(?P<dirname>[^\s`][a-zA-z-]+)/(?P<filename>[a-zA-Z0-9._-]+(.po)?)", title)
79+
if not match:
80+
continue
81+
82+
dirname, filename = match.group('dirname', 'filename')
83+
if not filename.endswith('.po'):
84+
filename += '.po'
85+
86+
result_list.append(((dirname, filename), assignee, issue["html_url"]))
87+
88+
return result_list
89+
90+
91+
def format_line_table_header() -> list:
92+
return [f"|Filename|Progress|Issue|Assignee|\r\n",
93+
f"|-------:|:-------|:----|:-------|\r\n"]
94+
95+
96+
def format_issue_link(url: str) -> str:
97+
return f"[{url.split('/')[-1]}]({url})" if len(url) > 0 else ''
98+
99+
100+
def format_line_file(filename: str, data: dict) -> str:
101+
return f"|`{filename}`|{data['progress']}|{format_issue_link(data['issue'])}|{data['assignee']}|\r\n"
102+
103+
104+
def format_line_directory(dirname: str) -> str:
105+
return f"## {dirname}\r\n"
106+
107+
108+
if __name__ == "__main__":
109+
issue_list = get_github_issues()
110+
111+
'''
112+
Search all the po file in the directory,
113+
and record the translation progress of each files.
114+
'''
115+
BASE_DIR = Path("../")
116+
summary = {}
117+
for filepath in glob.glob(str(BASE_DIR / "**/*.po"), recursive=True):
118+
path = Path(filepath)
119+
filename = path.name
120+
dirname = path.parent.name if path.parent.name != BASE_DIR.name else '/'
121+
po = polib.pofile(filepath)
122+
123+
summary.setdefault(dirname, {})[filename] = {
124+
'progress': entry_check(po),
125+
'issue': '',
126+
'assignee': '',
127+
}
128+
129+
'''
130+
Unpack the open issue list, and add assignee after the progress
131+
'''
132+
for (category, filename), assignee, issue_url in issue_list:
133+
try:
134+
summary[category][filename]['issue'] = issue_url
135+
summary[category][filename]['assignee'] = assignee
136+
except KeyError:
137+
pass
138+
139+
'''
140+
Adding Space for Formatting Markdown Link
141+
'''
142+
143+
'''
144+
Format the lines that will write into the markdown file,
145+
also sort the directory name and file name.
146+
'''
147+
writeliner = []
148+
summary_sorted = dict(sorted(summary.items()))
149+
for dirname, filedict in summary_sorted.items():
150+
writeliner.append(format_line_directory(dirname))
151+
writeliner.extend(format_line_table_header())
152+
153+
filedict_sorted = dict(sorted(filedict.items()))
154+
for filename, filedata in filedict_sorted.items():
155+
writeliner.append(format_line_file(filename, filedata))
156+
157+
with open(
158+
f"summarize_progress/result.md",
159+
"w",
160+
) as file:
161+
file.writelines(writeliner)

‎Makefile

Copy file name to clipboardExpand all lines: Makefile
+8-5Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,16 @@ $(VENV)/bin/activate:
9898
$(VENV)/bin/sphinx-build: $(VENV)/bin/activate
9999
. $(VENV)/bin/activate; python3 -m pip install sphinx python-docs-theme
100100

101+
$(VENV)/bin/sphinx-lint: $(VENV)/bin/activate
102+
. $(VENV)/bin/activate; python3 -m pip install sphinx-lint
101103

102104
$(VENV)/bin/blurb: $(VENV)/bin/activate
103105
. $(VENV)/bin/activate; python3 -m pip install blurb
104106

105107

106108
.PHONY: upgrade_venv
107109
upgrade_venv: $(VENV)/bin/activate ## Upgrade the venv that compiles the doc
108-
. $(VENV)/bin/activate; python3 -m pip install --upgrade sphinx python-docs-theme blurb
110+
. $(VENV)/bin/activate; python3 -m pip install --upgrade sphinx python-docs-theme blurb sphinx-lint
109111

110112

111113
.PHONY: progress
@@ -134,10 +136,7 @@ endif
134136
mkdir -p "$$(dirname "$$PO")";\
135137
if [ -f "$$PO" ];\
136138
then\
137-
case "$$POT" in\
138-
*whatsnew*) msgmerge --lang=$(LANGUAGE) --backup=off --force-po --no-fuzzy-matching -U "$$PO" "$$POT" ;;\
139-
*) msgmerge --lang=$(LANGUAGE) --backup=off --force-po -U "$$PO" "$$POT" ;;\
140-
esac\
139+
msgmerge --lang=$(LANGUAGE) --backup=off --force-po -U "$$PO" "$$POT";\
141140
else\
142141
msgcat --lang=$(LANGUAGE) -o "$$PO" "$$POT";\
143142
fi\
@@ -160,6 +159,10 @@ fuzzy: ## Find fuzzy strings
160159
rm_cpython: ## Remove cloned cpython repo
161160
rm -rf $(CPYTHON_CLONE)
162161

162+
.PHONY: lint
163+
lint: $(VENV)/bin/sphinx-lint ## Run sphinx-lint
164+
$(VENV)/bin/sphinx-lint --enable default-role
165+
163166
# This allows us to accept extra arguments (by doing nothing when we get a job that doesn't match, rather than throwing an error)
164167
%:
165168
@:

‎README.rst

Copy file name to clipboardExpand all lines: README.rst
+21-15Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,17 @@ the PSF for inclusion in the documentation.
8989
brew install gettext
9090
9191
brew link gettext --force
92+
- 安裝 pre-commit 自動在 commit 時檢查 ``.po`` 檔格式。
93+
.. code-block:: bash
94+
95+
pip install pre-commit
96+
pre-commit install
9297
9398
在進行任何動作以前,你必須在 GitHub 上 fork 此專案(按下右上角的 ``Fork``
9499
按鈕),這樣會把整個專案複製一份到你的 GitHub 帳號底下,你可以對這個 fork
95100
進行修改。
96101

97-
第一次貢獻以前(還沒有 clone 過)
102+
第一次貢獻以前(還沒有 clone 過
98103
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
99104

100105
請在 terminal 裡依照以下步驟:
@@ -118,7 +123,7 @@ the PSF for inclusion in the documentation.
118123
.. _GitHub Flow: https://guides.github.com/introduction/flow/
119124

120125
首先,`新增一個 issue <https://github.com/python/python-docs-zh-tw/issues>`_\
121-
,如:「翻譯 tutorial/introduction.po」,讓大家知道你正在翻譯這個檔案。可以使用 `make todo` 列出尚待翻譯的檔案。
126+
,如:「翻譯 tutorial/introduction.po」,讓大家知道你正在翻譯這個檔案。可以使用 ``make todo`` 列出尚待翻譯的檔案。
122127

123128
接著在 terminal 裡按照以下步驟:
124129

@@ -133,12 +138,18 @@ the PSF for inclusion in the documentation.
133138

134139
poedit glossary.po
135140

136-
3. 存檔以後,執行以下列指令編譯輸出文件,以確保你的修改沒有 rST 的語法錯誤或警告 ::
141+
3. 存檔以後,執行以下列指令編譯輸出完整文件,以確保你的修改沒有 reST 的語法錯誤或警告 ::
137142

138143
VERSION=3.12 make all
139144

145+
或者只想快速檢查是否有 reST 語法錯誤 ::
146+
147+
VERSION=3.12 make lint
148+
149+
確保輸出中沒有任何關於正在翻譯的檔案的警告訊息。
150+
140151
如果你還沒有執行 `維護、預覽`_ 的 clone CPython 的動作,此指令會自動幫你 clone CPython,\
141-
並且會使用 Sphinx 幫你檢查 rST 語法錯誤,我們盡量保持沒有 warning \
152+
並且會使用 Sphinx 幫你檢查 reST 語法錯誤,我們盡量保持沒有 warning \
142153
的狀態,因此如果有出現 warning 的話請修復它。另外也記得檢查是否符合\
143154
`翻譯守則`_
144155

@@ -247,11 +258,11 @@ po 檔皆為首要的翻譯對象。你也可以幫忙校對已經翻譯過的
247258
- 在本情況使用 ``zip(*[iter(x)]*n)`` 是很常見的情況(Python 慣例)。
248259
- 在超文件標示語言 (HTML) 中應注意跳脫符號。
249260

250-
rST 語法注意事項
261+
reST 語法注意事項
251262
----------------
252263

253-
- ``:xxx:`...``` 即為 rST 的語法,應該在譯文中保留。
254-
- rST 諸多語法需要保留前後的空白。在中文裡,該空白可以用 :literal:`\\\ \ `
264+
- ``:xxx:`...``` 即為 reST 的語法,應該在譯文中保留。
265+
- reST 諸多語法需要保留前後的空白。在中文裡,該空白可以用 :literal:`\\\ \ `
255266
來取代,製造一個沒有寬度的分隔符號。
256267

257268
例如:
@@ -307,18 +318,13 @@ rST 語法注意事項
307318

308319
.. code-block:: rst
309320
310-
以下是個程式範例:
311-
312-
::
313-
314-
注意\ **額外的空行是必須的**。
315-
321+
以下是個程式範例: ::
316322
317323
術語表 Glossary
318324
===============
319325

320-
為了讓翻譯保持統一,我們整理了一份 `術語列表
321-
<https://github.com/python/python-docs-zh-tw/wiki/%E8%A1%93%E8%AA%9E%E5%88%97%E8%A1%A8>`_ \
326+
為了讓翻譯保持統一,我們整理了一份 \
327+
`術語列表 <https://github.com/python/python-docs-zh-tw/wiki/%E8%A1%93%E8%AA%9E%E5%88%97%E8%A1%A8>`_ \
322328
如果翻譯過程中你覺得需要術語列表有所缺漏,請至 `Discussion \
323329
<https://github.com/python/python-docs-zh-tw/discussions>`_ 開啟新的討論補充術語。\
324330
新增的術語,將會於每次 Sprint 中共同討論是否合併進術語列表。

‎bugs.po

Copy file name to clipboardExpand all lines: bugs.po
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ msgid ""
1313
msgstr ""
1414
"Project-Id-Version: Python 3.12\n"
1515
"Report-Msgid-Bugs-To: \n"
16-
"POT-Creation-Date: 2023-02-27 00:17+0000\n"
16+
"POT-Creation-Date: 2023-11-05 09:50+0000\n"
1717
"PO-Revision-Date: 2022-08-31 12:34+0800\n"
1818
"Last-Translator: Steven Hsu <hsuhaochun@gmail.com>\n"
1919
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
@@ -117,9 +117,10 @@ msgstr "給有意成為 Python 說明文件貢獻者的綜合指南。"
117117

118118
#: ../../bugs.rst:41
119119
msgid ""
120-
"`Documentation Translations <https://devguide.python.org/documenting/"
121-
"#translating>`_"
122-
msgstr "`說明文件翻譯 <https://devguide.python.org/documenting/#translating>`_"
120+
"`Documentation Translations <https://devguide.python.org/documentation/"
121+
"translating/>`_"
122+
msgstr ""
123+
"`說明文件翻譯 <https://devguide.python.org/documentation/translating/>`_"
123124

124125
#: ../../bugs.rst:42
125126
msgid ""

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.