6
6
from pathlib import Path
7
7
8
8
9
- def entry_check (pofile : polib .POFile ) -> str :
9
+ def get_progress (pofile : polib .POFile ) -> float :
10
10
'''
11
11
Check the po file with how many entries are translated or not.
12
12
'''
13
13
14
14
lines_tranlated = len (pofile .translated_entries ())
15
15
lines_untranlated = len (pofile .untranslated_entries ())
16
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
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
+ return progress_percentage
28
26
29
27
30
28
def get_open_issues_count () -> int :
@@ -93,13 +91,21 @@ def format_line_table_header() -> list:
93
91
f"|-------:|:-------|:----|:-------|\r \n " ]
94
92
95
93
96
- def format_issue_link (url : str ) -> str :
97
- return f"[{ url .split ('/' )[- 1 ]} ]({ url } )" if len (url ) > 0 else ''
94
+ def format_line_po_issue_display (issue_link : str , issue_number : str , create_issue_link : str , progress : float ) -> str :
95
+ if issue_link :
96
+ return f"[{ issue_number } ]({ issue_link } )"
97
+ if progress != 100 :
98
+ return f"[create issue]({ create_issue_link } )"
99
+ return ""
98
100
99
101
100
- def format_line_file (dirname : str , filename : str , data : dict ) -> str :
101
- return f"|[`{ filename } `](https://github.com/python/python-docs-zh-tw/tree/3.13/{ dirname } /{ filename } )" + \
102
- f"|{ data ['progress' ]} |{ format_issue_link (data ['issue' ])} |{ data ['assignee' ]} |\r \n "
102
+ def format_line_po (filename : str , po_link : str , progress : str , issue_display : str , assignee : str ) -> str :
103
+ progress_display = f"{ progress } %"
104
+ if progress == 0 :
105
+ progress_display = "❌"
106
+ elif progress == 100 :
107
+ progress_display = "✅"
108
+ return f"|[`{ filename } `]({ po_link } )|{ progress_display } |{ issue_display } |{ assignee } |\r \n "
103
109
104
110
105
111
def format_line_directory (dirname : str ) -> str :
@@ -122,7 +128,7 @@ def format_line_directory(dirname: str) -> str:
122
128
po = polib .pofile (filepath )
123
129
124
130
summary .setdefault (dirname , {})[filename ] = {
125
- 'progress' : entry_check (po ),
131
+ 'progress' : get_progress (po ),
126
132
'issue' : '' ,
127
133
'assignee' : '' ,
128
134
}
@@ -153,7 +159,14 @@ def format_line_directory(dirname: str) -> str:
153
159
154
160
filedict_sorted = dict (sorted (filedict .items ()))
155
161
for filename , filedata in filedict_sorted .items ():
156
- writeliner .append (format_line_file (dirname , filename , filedata ))
162
+ file_path = f"{ dirname } /{ filename } "
163
+ po_link = f"https://github.com/python/python-docs-zh-tw/tree/3.13/{ file_path } "
164
+ issue_link = filedata ['issue' ]
165
+ issue_number = f"#{ issue_link .split ('/' )[- 1 ]} "
166
+ create_issue_link = f"https://github.com/python/python-docs-zh-tw/issues/new?title=Translate `{ file_path } `"
167
+ issue_display = format_line_po_issue_display (issue_link , issue_number , filedata ['progress' ], create_issue_link )
168
+ line_po = format_line_po (filename , po_link , filedata ['progress' ], issue_display , filedata ['assignee' ])
169
+ writeliner .append (line_po )
157
170
158
171
with open (
159
172
f"summarize_progress/result.md" ,
0 commit comments