2015-01-12 10:24:17 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from xml.dom import minidom
|
|
|
|
|
|
|
|
# STRINGTABLE DIAG TOOL
|
|
|
|
# Author: KoffeinFlummi
|
|
|
|
# ---------------------
|
|
|
|
# Checks for missing translations and all that jazz.
|
|
|
|
|
|
|
|
def get_all_languages(projectpath):
|
2015-04-07 19:38:27 +00:00
|
|
|
""" Checks what languages exist in the repo. """
|
|
|
|
languages = []
|
2015-01-12 10:24:17 +00:00
|
|
|
|
2015-04-07 19:38:27 +00:00
|
|
|
for module in os.listdir(projectpath):
|
|
|
|
if module[0] == ".":
|
|
|
|
continue
|
2015-01-12 10:24:17 +00:00
|
|
|
|
2015-04-07 19:38:27 +00:00
|
|
|
stringtablepath = os.path.join(projectpath, module, "stringtable.xml")
|
2015-01-12 10:24:17 +00:00
|
|
|
try:
|
2015-04-07 19:38:27 +00:00
|
|
|
xmldoc = minidom.parse(stringtablepath)
|
2015-01-12 10:24:17 +00:00
|
|
|
except:
|
2015-04-07 19:38:27 +00:00
|
|
|
continue
|
2015-01-12 10:24:17 +00:00
|
|
|
|
2015-04-07 19:38:27 +00:00
|
|
|
keys = xmldoc.getElementsByTagName("Key")
|
|
|
|
for key in keys:
|
|
|
|
for child in key.childNodes:
|
|
|
|
try:
|
|
|
|
if not child.tagName in languages:
|
|
|
|
languages.append(child.tagName)
|
|
|
|
except:
|
|
|
|
continue
|
|
|
|
|
|
|
|
return languages
|
2015-01-12 10:24:17 +00:00
|
|
|
|
|
|
|
def check_module(projectpath, module, languages):
|
2015-04-07 19:38:27 +00:00
|
|
|
""" Checks the given module for all the different languages. """
|
|
|
|
localized = []
|
2015-01-12 10:24:17 +00:00
|
|
|
|
2015-04-07 19:38:27 +00:00
|
|
|
stringtablepath = os.path.join(projectpath, module, "stringtable.xml")
|
|
|
|
try:
|
|
|
|
xmldoc = minidom.parse(stringtablepath)
|
|
|
|
except:
|
|
|
|
return 0, localized
|
2015-01-12 10:24:17 +00:00
|
|
|
|
2015-04-07 19:38:27 +00:00
|
|
|
keynumber = len(xmldoc.getElementsByTagName("Key"))
|
2015-01-12 10:24:17 +00:00
|
|
|
|
2015-04-07 19:38:27 +00:00
|
|
|
for language in languages:
|
|
|
|
localized.append(len(xmldoc.getElementsByTagName(language)))
|
2015-01-12 10:24:17 +00:00
|
|
|
|
2015-04-07 19:38:27 +00:00
|
|
|
return keynumber, localized
|
2015-01-12 10:24:17 +00:00
|
|
|
|
|
|
|
def main():
|
2015-04-07 19:38:27 +00:00
|
|
|
scriptpath = os.path.realpath(__file__)
|
|
|
|
projectpath = os.path.dirname(os.path.dirname(scriptpath))
|
|
|
|
projectpath = os.path.join(projectpath, "addons")
|
2015-01-12 10:24:17 +00:00
|
|
|
|
2015-05-08 17:27:42 +00:00
|
|
|
if "--markdown" not in sys.argv:
|
|
|
|
print("#########################")
|
|
|
|
print("# Stringtable Diag Tool #")
|
|
|
|
print("#########################")
|
2015-01-12 10:24:17 +00:00
|
|
|
|
2015-04-07 19:38:27 +00:00
|
|
|
languages = get_all_languages(projectpath)
|
2015-01-12 10:24:17 +00:00
|
|
|
|
2015-05-08 17:27:42 +00:00
|
|
|
if "--markdown" not in sys.argv:
|
|
|
|
print("\nLanguages present in the repo:")
|
|
|
|
print(", ".join(languages))
|
2015-01-12 10:24:17 +00:00
|
|
|
|
2015-04-07 19:38:27 +00:00
|
|
|
keysum = 0
|
|
|
|
localizedsum = list(map(lambda x: 0, languages))
|
|
|
|
missing = list(map(lambda x: [], languages))
|
2015-01-12 10:24:17 +00:00
|
|
|
|
2015-04-07 19:38:27 +00:00
|
|
|
for module in os.listdir(projectpath):
|
|
|
|
keynumber, localized = check_module(projectpath, module, languages)
|
2015-01-12 10:24:17 +00:00
|
|
|
|
2015-04-07 19:38:27 +00:00
|
|
|
if keynumber == 0:
|
|
|
|
continue
|
2015-01-12 10:24:17 +00:00
|
|
|
|
2015-05-08 17:27:42 +00:00
|
|
|
if "--markdown" not in sys.argv:
|
|
|
|
print("\n# " + module)
|
2015-01-12 10:24:17 +00:00
|
|
|
|
2015-04-07 19:38:27 +00:00
|
|
|
keysum += keynumber
|
|
|
|
for i in range(len(localized)):
|
2015-05-08 17:27:42 +00:00
|
|
|
if "--markdown" not in sys.argv:
|
|
|
|
print(" %s %s / %i" % ((languages[i]+":").ljust(10), str(localized[i]).ljust(3), keynumber))
|
2015-04-07 19:38:27 +00:00
|
|
|
localizedsum[i] += localized[i]
|
|
|
|
if localized[i] < keynumber:
|
|
|
|
missing[i].append(module)
|
2015-01-12 10:24:17 +00:00
|
|
|
|
2015-05-08 17:27:42 +00:00
|
|
|
if "--markdown" not in sys.argv:
|
|
|
|
print("\n###########")
|
|
|
|
print("# RESULTS #")
|
|
|
|
print("###########")
|
|
|
|
print("\nTotal number of keys: %i\n" % (keysum))
|
2015-01-12 10:24:17 +00:00
|
|
|
|
2015-05-08 17:27:42 +00:00
|
|
|
for i in range(len(languages)):
|
|
|
|
if localizedsum[i] == keysum:
|
|
|
|
print("%s No missing stringtable entries." % ((languages[i] + ":").ljust(12)))
|
|
|
|
else:
|
|
|
|
print("%s %s missing stringtable entry/entries." % ((languages[i] + ":").ljust(12), str(keysum - localizedsum[i]).rjust(4)), end="")
|
|
|
|
print(" ("+", ".join(missing[i])+")")
|
2015-01-12 10:24:17 +00:00
|
|
|
|
2015-05-08 17:27:42 +00:00
|
|
|
print("\n\n### MARKDOWN ###\n")
|
2015-01-12 10:24:17 +00:00
|
|
|
|
2015-05-08 17:27:42 +00:00
|
|
|
print("Total number of keys: %i\n" % (keysum))
|
2015-01-12 10:24:17 +00:00
|
|
|
|
2015-04-07 19:38:27 +00:00
|
|
|
print("| Language | Missing Entries | Relevant Modules | % done |")
|
|
|
|
print("|----------|----------------:|------------------|--------|")
|
2015-01-12 10:24:17 +00:00
|
|
|
|
2015-04-07 19:38:27 +00:00
|
|
|
for i, language in enumerate(languages):
|
|
|
|
if localizedsum[i] == keysum:
|
|
|
|
print("| {} | 0 | - | 100% |".format(language))
|
|
|
|
else:
|
|
|
|
print("| {} | {} | {} | {}% |".format(
|
|
|
|
language,
|
|
|
|
keysum - localizedsum[i],
|
|
|
|
", ".join(missing[i]),
|
2019-12-11 22:35:11 +00:00
|
|
|
round(100 * localizedsum[i] / keysum, 2)))
|
2015-01-12 10:24:17 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2015-04-07 19:38:27 +00:00
|
|
|
main()
|