66from pathlib import Path
77
88
9- def get_progress (pofile :polib .POFile )-> float :
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- return progress_percentage
26-
27-
289def get_open_issues_count ()-> int :
2910'''
3011 Fetch GitHub API to get the number of OPEN ISSUES.
@@ -87,7 +68,7 @@ def get_github_issues() -> list:
8768
8869
8970def format_line_table_header ()-> list :
90- return [f"|Filename|Progress|Issue|Assignee|\r \n " ,
71+ return [f"|Filename|Progress (#string) |Issue|Assignee|\r \n " ,
9172f"|-------:|:-------|:----|:-------|\r \n " ]
9273
9374
@@ -99,17 +80,11 @@ def format_line_po_issue_display(issue_link: str, issue_number: str, progress: f
9980return ""
10081
10182
102- def format_line_po (filename :str ,po_link :str ,progress :str ,issue_display :str ,assignee :str )-> str :
83+ def format_line_po (filename :str ,po_link :str ,progress :str ,num_entries : str , issue_display :str ,assignee :str )-> str :
10384progress_display = f"{ progress } %"
104- if progress == 0 :
105- progress_display = "❌"
106- elif progress == 100 :
85+ if progress == 100 :
10786progress_display = "✅"
108- return f"|[`{ filename } `]({ po_link } )|{ progress_display } |{ issue_display } |{ assignee } |\r \n "
109-
110-
111- def format_line_directory (dirname :str )-> str :
112- return f"##{ dirname } \r \n "
87+ return f"|[`{ filename } `]({ po_link } )|{ progress_display } ({ num_entries :,} )|{ issue_display } |{ assignee } |\r \n "
11388
11489
11590if __name__ == "__main__" :
@@ -124,11 +99,17 @@ def format_line_directory(dirname: str) -> str:
12499for filepath in glob .glob (str (BASE_DIR / "**/*.po" ),recursive = True ):
125100path = Path (filepath )
126101filename = path .name
127- dirname = path .parent .name if path .parent .name != BASE_DIR .name else '/ '
102+ dirname = path .parent .name if path .parent .name != BASE_DIR .name else 'root '
128103po = polib .pofile (filepath )
129104
105+ num_entries = len (list (filter (lambda e :not e .obsolete (),po )))
106+ num_translated = len (po .translated_entries ())
130107summary .setdefault (dirname , {})[filename ]= {
131- 'progress' :get_progress (po ),
108+ 'po_info' : {
109+ 'num_entries' :num_entries ,
110+ 'num_translated' :num_translated ,
111+ 'progress' :round (num_translated / num_entries * 100 ,2 ),
112+ },
132113'issue' :'' ,
133114'assignee' :'' ,
134115 }
@@ -144,19 +125,15 @@ def format_line_directory(dirname: str) -> str:
144125pass
145126
146127'''
147- Adding Space for Formatting Markdown Link
148- '''
149-
150- '''
151- Format the lines that will write into the markdown file,
128+ Format the lines that will be written into the markdown file,
152129 also sort the directory name and file name.
153130 '''
154131writeliner = []
155132summary_sorted = dict (sorted (summary .items ()))
133+ total_entries ,total_translated = 0 ,0
156134for dirname ,filedict in summary_sorted .items ():
157- writeliner .append (format_line_directory (dirname ))
158- writeliner .extend (format_line_table_header ())
159-
135+ dir_total_entries ,dir_total_translated = 0 ,0
136+ lines = []
160137filedict_sorted = dict (sorted (filedict .items ()))
161138for filename ,filedata in filedict_sorted .items ():
162139file_path = f"{ dirname } /{ filename } " if dirname else filename
@@ -165,11 +142,30 @@ def format_line_directory(dirname: str) -> str:
165142issue_number = f"#{ issue_link .split ('/' )[- 1 ]} "
166143create_issue_link = f"https://github.com/python/python-docs-zh-tw/issues/new?title=Translate%20`{ file_path } `"
167144issue_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 )
145+ line_po = format_line_po (
146+ filename ,
147+ po_link ,
148+ filedata ['po_info' ]['progress' ],
149+ filedata ['po_info' ]['num_entries' ],
150+ issue_display ,
151+ filedata ['assignee' ],
152+ )
153+ lines .append (line_po )
154+
155+ dir_total_entries += filedata ['po_info' ]['num_entries' ]
156+ dir_total_translated += filedata ['po_info' ]['num_translated' ]
157+
158+ dir_progress = round (dir_total_translated / dir_total_entries * 100 ,2 )
159+ writeliner .append (f"##{ dirname } ({ dir_progress } %)\r \n " )
160+ writeliner .extend (format_line_table_header ())
161+ writeliner .extend (lines )
162+
163+ total_entries += dir_total_entries
164+ total_translated += dir_total_translated
165+
166+ overall_progress = round (total_translated / total_entries * 100 ,2 )
167+ title = f"## Overall Progress:{ overall_progress } % ({ total_translated :,} /{ total_entries :,} )\r \n "
168+ writeliner = [title ]+ writeliner
170169
171- with open (
172- f"summarize_progress/result.md" ,
173- "w" ,
174- )as file :
170+ with open (f"summarize_progress/result.md" ,"w" )as file :
175171file .writelines (writeliner )