1212import json
1313import os
1414import re
15+ import shlex
1516import subprocess
1617import sys
1718import textwrap
@@ -84,21 +85,13 @@ def makeParser():
8485
8586
8687def call (* args , ** kwargs ) -> subprocess .CompletedProcess :
87- cmdstr = ""
88- for token in args :
89- cmdstr += " "
90- if " " in token :
91- cmdstr += F"\" { token } \" "
92- else :
93- cmdstr += token
94- print (F">{ cmdstr } " )
95-
88+ print (f"> { shlex .join (args )} " )
9689 capture_output = kwargs .pop ("capture_output" , True )
9790 check = kwargs .pop ("check" , True )
9891 try :
9992 return subprocess .run (args , encoding = 'utf-8' , capture_output = capture_output , check = check , ** kwargs )
10093 except subprocess .CalledProcessError as e :
101- print (F "Aborting setup because : { e } " )
94+ print (f "Aborting: { e } " )
10295 sys .exit (1 )
10396
10497
@@ -294,6 +287,7 @@ def updatePoFiles():
294287 "--update" ,
295288 "--sort-by-file" ,
296289 "--no-wrap" ,
290+ "--backup=off" ,
297291 str (poPath ),
298292 LANG_TEMPLATE ,
299293 capture_output = False )
@@ -316,29 +310,30 @@ def compileMoFiles():
316310 """ Generate .mo files from .po files """
317311 wipLanguages = []
318312
319- for poPath in Path (LANG_DIR ).glob ("*.po" ):
313+ def extractStderrNumber (pattern , stderr ):
314+ match = re .search (pattern , stderr )
315+ return int (match .group (1 )) if match else 0
316+
317+ for poPath in sorted (Path (LANG_DIR ).glob ("*.po" )):
320318 moPath : Path = poPath .with_suffix (".mo" )
321319
322- call ("msgfmt" , "-o" , str (moPath ), str (poPath ), capture_output = False )
320+ msgfmt = call ("msgfmt" , "--no-hash" , "--statistics" , "-o" , str (moPath ), str (poPath ),
321+ env = {"LANGUAGE" : "C" }, capture_output = True )
323322
324- moSizeKB = moPath .stat ().st_size // 1024
323+ complete = extractStderrNumber (r"(\d+) translated messages" , msgfmt .stderr )
324+ missing1 = extractStderrNumber (r"(\d+) fuzzy translations" , msgfmt .stderr )
325+ missing2 = extractStderrNumber (r"(\d+) untranslated messages" , msgfmt .stderr )
326+ ratio = round (100.0 * complete / (complete + missing1 + missing2 ))
327+ print (f" { poPath .stem } : { ratio } % complete | { msgfmt .stderr .strip ()} " )
325328
326329 # Remove empty po/mo files
327- if moSizeKB = = 0 :
330+ if ratio < = 0 :
328331 print (f"*** Removing empty translation '{ poPath .name } '" )
329332 poPath .unlink ()
330333 moPath .unlink ()
331334 continue
332335
333- # Small .mo files are considered stubs and won't be included in builds
334- if moSizeKB < 5 :
335- print (f"*** Removing '{ moPath .name } ' -- looks like a stub ({ moSizeKB } KB)" )
336- moPath .unlink ()
337- continue
338-
339- # .mo files below 100 KB are considered incomplete
340- if moSizeKB < 100 :
341- wipLanguages += [moPath .stem ]
336+ wipLanguages += [f"{ moPath .stem } { ratio } " ]
342337
343338 Path (LANG_DIR , "wip.txt" ).write_text ("\n " .join (wipLanguages ) + "\n " )
344339
0 commit comments