6
6
from pathlib import Path
7
7
8
8
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
-
28
9
def get_open_issues_count () -> int :
29
10
'''
30
11
Fetch GitHub API to get the number of OPEN ISSUES.
@@ -87,7 +68,7 @@ def get_github_issues() -> list:
87
68
88
69
89
70
def format_line_table_header () -> list :
90
- return [f"|Filename|Progress|Issue|Assignee|\r \n " ,
71
+ return [f"|Filename|Progress (#string) |Issue|Assignee|\r \n " ,
91
72
f"|-------:|:-------|:----|:-------|\r \n " ]
92
73
93
74
@@ -99,17 +80,11 @@ def format_line_po_issue_display(issue_link: str, issue_number: str, progress: f
99
80
return ""
100
81
101
82
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 :
103
84
progress_display = f"{ progress } %"
104
- if progress == 0 :
105
- progress_display = "❌"
106
- elif progress == 100 :
85
+ if progress == 100 :
107
86
progress_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 "
113
88
114
89
115
90
if __name__ == "__main__" :
@@ -124,11 +99,17 @@ def format_line_directory(dirname: str) -> str:
124
99
for filepath in glob .glob (str (BASE_DIR / "**/*.po" ), recursive = True ):
125
100
path = Path (filepath )
126
101
filename = 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 '
128
103
po = polib .pofile (filepath )
129
104
105
+ num_entries = len (list (filter (lambda e : not e .obsolete (), po )))
106
+ num_translated = len (po .translated_entries ())
130
107
summary .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
+ },
132
113
'issue' : '' ,
133
114
'assignee' : '' ,
134
115
}
@@ -144,19 +125,15 @@ def format_line_directory(dirname: str) -> str:
144
125
pass
145
126
146
127
'''
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,
152
129
also sort the directory name and file name.
153
130
'''
154
131
writeliner = []
155
132
summary_sorted = dict (sorted (summary .items ()))
133
+ total_entries , total_translated = 0 , 0
156
134
for 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 = []
160
137
filedict_sorted = dict (sorted (filedict .items ()))
161
138
for filename , filedata in filedict_sorted .items ():
162
139
file_path = f"{ dirname } /{ filename } " if dirname else filename
@@ -165,11 +142,30 @@ def format_line_directory(dirname: str) -> str:
165
142
issue_number = f"#{ issue_link .split ('/' )[- 1 ]} "
166
143
create_issue_link = f"https://github.com/python/python-docs-zh-tw/issues/new?title=Translate%20`{ file_path } `"
167
144
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 )
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
170
169
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 :
175
171
file .writelines (writeliner )
0 commit comments