|
@@ -29,15 +29,15 @@ def read_po_files(inputdirpath):
|
|
|
os.chdir(inputdirpath)
|
|
|
languages = {}
|
|
|
for pofile in sorted(glob.glob("*.po")):
|
|
|
- lang = pofile.split('_')[1:]
|
|
|
+ lang = pofile.split("_")[1:]
|
|
|
# check if are two definitions like pt_br
|
|
|
if len(lang) == 2:
|
|
|
- lang = ['_'.join(lang)]
|
|
|
- lang = lang[0].split('.')[0]
|
|
|
+ lang = ["_".join(lang)]
|
|
|
+ lang = lang[0].split(".")[0]
|
|
|
|
|
|
# if keys is not in languages add it and the file's name
|
|
|
if lang not in languages:
|
|
|
- languages[lang] = [pofile, ]
|
|
|
+ languages[lang] = [pofile]
|
|
|
# add only files name
|
|
|
else:
|
|
|
languages[lang].append(pofile)
|
|
@@ -49,33 +49,33 @@ def read_msgfmt_statistics(msg, lgood, lfuzzy, lbad):
|
|
|
"""Return a dictionary, and the good, fuzzy and bad values from a string"""
|
|
|
langdict = {}
|
|
|
# split the output
|
|
|
- out = msg.split(b',')
|
|
|
+ out = msg.split(b",")
|
|
|
# TODO maybe check using regex
|
|
|
# check for each answer
|
|
|
for o in out:
|
|
|
o = o.lower().strip()
|
|
|
# each answer is written into dictionary and
|
|
|
# the value add to variable for the sum
|
|
|
- if b'untranslated' in o:
|
|
|
- val = int(o.split(b' ')[0])
|
|
|
- langdict['bad'] = val
|
|
|
+ if b"untranslated" in o:
|
|
|
+ val = int(o.split(b" ")[0])
|
|
|
+ langdict["bad"] = val
|
|
|
lbad += val
|
|
|
- elif b'fuzzy' in o:
|
|
|
- val = int(o.split(b' ')[0])
|
|
|
- langdict['fuzzy'] = val
|
|
|
+ elif b"fuzzy" in o:
|
|
|
+ val = int(o.split(b" ")[0])
|
|
|
+ langdict["fuzzy"] = val
|
|
|
lfuzzy += val
|
|
|
else:
|
|
|
- val = int(o.split(b' ')[0])
|
|
|
- langdict['good'] = val
|
|
|
+ val = int(o.split(b" ")[0])
|
|
|
+ langdict["good"] = val
|
|
|
lgood += val
|
|
|
return langdict, lgood, lfuzzy, lbad
|
|
|
|
|
|
|
|
|
def langDefinition(fil):
|
|
|
- f = codecs.open(fil, encoding='utf-8', errors='replace', mode='r')
|
|
|
+ f = codecs.open(fil, encoding="utf-8", errors="replace", mode="r")
|
|
|
for l in f.readlines():
|
|
|
if '"Language-Team:' in l:
|
|
|
- lang = l.split(' ')[1:-1]
|
|
|
+ lang = l.split(" ")[1:-1]
|
|
|
break
|
|
|
f.close()
|
|
|
if len(lang) == 2:
|
|
@@ -92,14 +92,16 @@ def get_stats(languages, directory):
|
|
|
output = {}
|
|
|
# TO DO TOTALS OF ENGLISH WORD FOR EACH FILE
|
|
|
# all the total string in english
|
|
|
- output['totals'] = {}
|
|
|
+ output["totals"] = {}
|
|
|
# all the information about each lang
|
|
|
- output['langs'] = {}
|
|
|
+ output["langs"] = {}
|
|
|
# for each language
|
|
|
for lang, pofilelist in languages.items():
|
|
|
- output['langs'][lang] = {}
|
|
|
- output['langs'][lang]['total'] = {}
|
|
|
- output['langs'][lang]['name'] = langDefinition(os.path.join(directory, pofilelist[0]))
|
|
|
+ output["langs"][lang] = {}
|
|
|
+ output["langs"][lang]["total"] = {}
|
|
|
+ output["langs"][lang]["name"] = langDefinition(
|
|
|
+ os.path.join(directory, pofilelist[0])
|
|
|
+ )
|
|
|
# variables to create sum for each language
|
|
|
lgood = 0
|
|
|
lfuzzy = 0
|
|
@@ -107,25 +109,28 @@ def get_stats(languages, directory):
|
|
|
# for each file
|
|
|
for flang in pofilelist:
|
|
|
|
|
|
- fpref = flang.split('_')[0]
|
|
|
+ fpref = flang.split("_")[0]
|
|
|
# run msgfmt for statistics
|
|
|
# TODO check if it's working on windows
|
|
|
- process = subprocess.Popen(['msgfmt', '--statistics',
|
|
|
- os.path.join(directory,flang)],
|
|
|
- stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
+ process = subprocess.Popen(
|
|
|
+ ["msgfmt", "--statistics", os.path.join(directory, flang)],
|
|
|
+ stdout=subprocess.PIPE,
|
|
|
+ stderr=subprocess.PIPE,
|
|
|
+ )
|
|
|
msg = process.communicate()[1].strip()
|
|
|
# check if some errors occurs
|
|
|
- if msg.find(b'error') != -1:
|
|
|
+ if msg.find(b"error") != -1:
|
|
|
# TODO CHECK IF grass.warning()
|
|
|
print("WARNING: file <%s> has some problems: <%s>" % (flang, msg))
|
|
|
continue
|
|
|
- output['langs'][lang][fpref], lgood, lfuzzy, lbad = \
|
|
|
- read_msgfmt_statistics(msg, lgood, lfuzzy, lbad)
|
|
|
+ output["langs"][lang][fpref], lgood, lfuzzy, lbad = read_msgfmt_statistics(
|
|
|
+ msg, lgood, lfuzzy, lbad
|
|
|
+ )
|
|
|
# write the sum and total of each file
|
|
|
- output['langs'][lang]['total']['good'] = lgood
|
|
|
- output['langs'][lang]['total']['fuzzy'] = lfuzzy
|
|
|
- output['langs'][lang]['total']['bad'] = lbad
|
|
|
- output['langs'][lang]['total']['total'] = lgood + lfuzzy + lbad
|
|
|
+ output["langs"][lang]["total"]["good"] = lgood
|
|
|
+ output["langs"][lang]["total"]["fuzzy"] = lfuzzy
|
|
|
+ output["langs"][lang]["total"]["bad"] = lbad
|
|
|
+ output["langs"][lang]["total"]["total"] = lgood + lfuzzy + lbad
|
|
|
return output
|
|
|
|
|
|
|
|
@@ -135,7 +140,7 @@ def writejson(stats, outfile):
|
|
|
# write a string with pretty style
|
|
|
outjson = os.linesep.join([l.rstrip() for l in fjson.splitlines()])
|
|
|
# write out file
|
|
|
- fout = open(outfile, 'w')
|
|
|
+ fout = open(outfile, "w")
|
|
|
fout.write(outjson)
|
|
|
fout.write(os.linesep)
|
|
|
fout.close()
|
|
@@ -155,6 +160,6 @@ def main(in_dirpath, out_josonpath):
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
- directory = 'po/'
|
|
|
- outfile = os.path.join(os.environ['GISBASE'], 'translation_status.json')
|
|
|
+ directory = "po/"
|
|
|
+ outfile = os.path.join(os.environ["GISBASE"], "translation_status.json")
|
|
|
sys.exit(main(directory, outfile))
|