Skip to content

Commit d24f806

Browse files
committed
📝 Update tools/stringtableDiag.py
1 parent 86f48ab commit d24f806

File tree

1 file changed

+46
-47
lines changed

1 file changed

+46
-47
lines changed

tools/stringtableDiag.py

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import sys
5+
56
from xml.dom import minidom
67

78
# STRINGTABLE DIAG TOOL
@@ -52,73 +53,71 @@ def check_module(projectpath, module, languages):
5253
return keynumber, localized
5354

5455
def main():
55-
markdown = "--markdown" in sys.argv
56-
5756
scriptpath = os.path.realpath(__file__)
5857
projectpath = os.path.dirname(os.path.dirname(scriptpath))
5958
projectpath = os.path.join(projectpath, "addons")
6059

61-
if not markdown:
60+
if "--markdown" not in sys.argv:
6261
print("#########################")
6362
print("# Stringtable Diag Tool #")
6463
print("#########################")
6564

6665
languages = get_all_languages(projectpath)
6766

68-
if not markdown:
67+
if "--markdown" not in sys.argv:
6968
print("\nLanguages present in the repo:")
7069
print(", ".join(languages))
7170

7271
keysum = 0
73-
localizedsum = [0 for _ in languages]
74-
missing = {lang: {} for lang in languages} # module -> list of missing keys
72+
localizedsum = list(map(lambda x: 0, languages))
73+
missing = list(map(lambda x: [], languages))
7574

7675
for module in os.listdir(projectpath):
77-
stringtablepath = os.path.join(projectpath, module, "stringtable.xml")
78-
try:
79-
xmldoc = minidom.parse(stringtablepath)
80-
except:
81-
continue
76+
keynumber, localized = check_module(projectpath, module, languages)
8277

83-
keys = xmldoc.getElementsByTagName("Key")
84-
keynumber = len(keys)
8578
if keynumber == 0:
8679
continue
8780

88-
keysum += keynumber
81+
if "--markdown" not in sys.argv:
82+
print("\n# " + module)
8983

90-
for i, lang in enumerate(languages):
91-
localized_count = len(xmldoc.getElementsByTagName(lang))
92-
localizedsum[i] += localized_count
93-
if localized_count < keynumber:
94-
missing_keys = []
95-
for key in keys:
96-
if not key.getElementsByTagName(lang):
97-
missing_keys.append(key.getAttribute("name") or key.getAttribute("id") or "(unknown)")
98-
missing[lang][module] = missing_keys
99-
100-
# --- Markdown Table ---
101-
print(f"**Translation Status Report**\n")
102-
print(f"_Total number of keys: {keysum}_\n")
103-
print("| Language | Missing Entries | Modules Missing Keys | % Complete |")
104-
print("|----------|----------------:|--------------------|------------|")
105-
for i, lang in enumerate(languages):
106-
percent_done = round(100 * localizedsum[i] / keysum) if keysum > 0 else 100
107-
missing_count = sum(len(v) for v in missing[lang].values())
108-
modules = ", ".join(missing[lang].keys()) if missing_count > 0 else "-"
109-
entry_display = f"**{missing_count} ⚠️**" if missing_count > 0 else "0"
110-
print(f"| {lang} | {entry_display} | {modules} | {percent_done}% |")
111-
112-
# --- Collapsible Sections with Missing Keys ---
113-
for lang in languages:
114-
missing_count = sum(len(v) for v in missing[lang].values())
115-
if missing_count == 0:
116-
continue
117-
print(f"\n<details>")
118-
print(f"<summary>{lang} ({missing_count} missing)</summary>\n")
119-
for module, keys in missing[lang].items():
120-
print(f"- **{module}**: {', '.join(keys)}")
121-
print("</details>\n")
84+
keysum += keynumber
85+
for i in range(len(localized)):
86+
if "--markdown" not in sys.argv:
87+
print(" %s %s / %i" % ((languages[i]+":").ljust(10), str(localized[i]).ljust(3), keynumber))
88+
localizedsum[i] += localized[i]
89+
if localized[i] < keynumber:
90+
missing[i].append(module)
91+
92+
if "--markdown" not in sys.argv:
93+
print("\n###########")
94+
print("# RESULTS #")
95+
print("###########")
96+
print("\nTotal number of keys: %i\n" % (keysum))
97+
98+
for i in range(len(languages)):
99+
if localizedsum[i] == keysum:
100+
print("%s No missing stringtable entries." % ((languages[i] + ":").ljust(12)))
101+
else:
102+
print("%s %s missing stringtable entry/entries." % ((languages[i] + ":").ljust(12), str(keysum - localizedsum[i]).rjust(4)), end="")
103+
print(" ("+", ".join(missing[i])+")")
104+
105+
print("\n\n### MARKDOWN ###\n")
106+
107+
print("Total number of keys: %i\n" % (keysum))
108+
109+
print("| Language | Missing Entries | Relevant Modules | % done |")
110+
print("|----------|----------------:|------------------|--------|")
111+
112+
for i, language in enumerate(languages):
113+
if localizedsum[i] == keysum:
114+
print("| {} | 0 | - | 100% |".format(language))
115+
else:
116+
print("| {} | {} | {} | {}% |".format(
117+
language,
118+
keysum - localizedsum[i],
119+
", ".join(missing[i]),
120+
round(100 * localizedsum[i] / keysum)))
122121

123122
if __name__ == "__main__":
124-
main()
123+
main()

0 commit comments

Comments
 (0)