66from pathlib import Path
77
88
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-
309def get_open_issues_count () -> int :
3110 '''
3211 Fetch GitHub API to get the number of OPEN ISSUES.
@@ -89,20 +68,23 @@ def get_github_issues() -> list:
8968
9069
9170def format_line_table_header () -> list :
92- return [f"|Filename|Progress|Issue|Assignee|\r \n " ,
71+ return [f"|Filename|Progress (#string) |Issue|Assignee|\r \n " ,
9372 f"|-------:|:-------|:----|:-------|\r \n " ]
9473
9574
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 "
75+ def format_line_po_issue_display ( issue_link : str , issue_number : str , progress : float , create_issue_link : str ) -> str :
76+ if issue_link :
77+ return f"[ { issue_number } ]( { issue_link } )"
78+ if progress != 100. :
79+ return f"[create issue]( { create_issue_link } )"
80+ return " "
10281
10382
104- def format_line_directory (dirname : str ) -> str :
105- return f"## { dirname } \r \n "
83+ def format_line_po (filename : str , po_link : str , progress : str , num_entries : str , issue_display : str , assignee : str ) -> str :
84+ progress_display = f"{ progress } %"
85+ if progress == 100 :
86+ progress_display = "✅"
87+ return f"|[`{ filename } `]({ po_link } )|{ progress_display } ({ num_entries :,} )|{ issue_display } |{ assignee } |\r \n "
10688
10789
10890if __name__ == "__main__" :
@@ -117,11 +99,17 @@ def format_line_directory(dirname: str) -> str:
11799 for filepath in glob .glob (str (BASE_DIR / "**/*.po" ), recursive = True ):
118100 path = Path (filepath )
119101 filename = path .name
120- 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 '
121103 po = polib .pofile (filepath )
122104
105+ num_entries = len (list (filter (lambda e : not e .obsolete , po )))
106+ num_translated = len (po .translated_entries ())
123107 summary .setdefault (dirname , {})[filename ] = {
124- 'progress' : entry_check (po ),
108+ 'po_info' : {
109+ 'num_entries' : num_entries ,
110+ 'num_translated' : num_translated ,
111+ 'progress' : round (num_translated / num_entries * 100 , 2 ),
112+ },
125113 'issue' : '' ,
126114 'assignee' : '' ,
127115 }
@@ -137,25 +125,47 @@ def format_line_directory(dirname: str) -> str:
137125 pass
138126
139127 '''
140- Adding Space for Formatting Markdown Link
141- '''
142-
143- '''
144- Format the lines that will write into the markdown file,
128+ Format the lines that will be written into the markdown file,
145129 also sort the directory name and file name.
146130 '''
147131 writeliner = []
148132 summary_sorted = dict (sorted (summary .items ()))
133+ total_entries , total_translated = 0 , 0
149134 for dirname , filedict in summary_sorted .items ():
150- writeliner .append (format_line_directory (dirname ))
151- writeliner .extend (format_line_table_header ())
152-
135+ dir_total_entries , dir_total_translated = 0 , 0
136+ lines = []
153137 filedict_sorted = dict (sorted (filedict .items ()))
154138 for filename , filedata in filedict_sorted .items ():
155- writeliner .append (format_line_file (filename , filedata ))
139+ file_path = f"{ dirname } /{ filename } " if dirname else filename
140+ po_link = f"https://github.com/python/python-docs-zh-tw/tree/3.13/{ file_path } "
141+ issue_link = filedata ['issue' ]
142+ issue_number = f"#{ issue_link .split ('/' )[- 1 ]} "
143+ create_issue_link = f"https://github.com/python/python-docs-zh-tw/issues/new?title=Translate%20`{ file_path } `"
144+ issue_display = format_line_po_issue_display (issue_link , issue_number , filedata ['po_info' ]['progress' ], create_issue_link )
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
156169
157- with open (
158- f"summarize_progress/result.md" ,
159- "w" ,
160- ) as file :
170+ with open (f"summarize_progress/result.md" , "w" ) as file :
161171 file .writelines (writeliner )
0 commit comments