Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add automatic translation progression tracker #181

Merged
merged 1 commit into from
Apr 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,20 @@ jobs:
path: 'sqf.log'
- name: Validate SQFLinter Logs
run: python3 tools/sqf_linter_LogChecker.py

stringtables:
runs-on: ubuntu-latest
steps:
- name: Install Python packages
run: |
pip3 install wheel
pip3 install setuptools
pip3 install pygithub
pip3 install pygithub3
- name: Checkout the source code
uses: actions/checkout@master
- name: Update Translation issue
if: github.repository == 'diwako/diwako_dui' && github.ref == 'refs/heads/master' && ! contains(github.event.head_commit.message, '[ci skip]')
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: python3 tools/stringtableDeploy.py
60 changes: 60 additions & 0 deletions tools/stringtableDeploy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env python3

###################################
# ZEN automatic deployment script #
# =============================== #
# This is not meant to be run #
# directly! #
###################################

import os
import sys
import shutil
import traceback
import subprocess as sp
from github import Github

TRANSLATIONISSUE = 92
TRANSLATIONBODY = """**[Translation Guide](http://ace3mod.com/wiki/development/how-to-translate-ace3.html)**
{}
"""

REPOUSER = "diwako"
REPONAME = "diwako_dui"
REPOPATH = "{}/{}".format(REPOUSER,REPONAME)


def update_translations(repo):
diag = sp.check_output(["python3", "tools/stringtablediag.py", "--markdown"])
diag = str(diag, "utf-8")
issue = repo.get_issue(TRANSLATIONISSUE)
issue.edit(body=TRANSLATIONBODY.format(diag))


def main():
print("Obtaining token ...")
try:
token = os.environ["GH_TOKEN"]
repo = Github(token).get_repo(REPOPATH)
except:
print("Could not obtain token.")
print(traceback.format_exc())
return 1
else:
print("Token sucessfully obtained.")

print("\nUpdating translation issue ...")
try:
update_translations(repo)
except:
print("Failed to update translation issue.")
print(traceback.format_exc())
return 1
else:
print("Translation issue successfully updated.")

return 0


if __name__ == "__main__":
sys.exit(main())
123 changes: 123 additions & 0 deletions tools/stringtablediag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/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):
""" Checks what languages exist in the repo. """
languages = []

for module in os.listdir(projectpath):
if module[0] == ".":
continue

stringtablepath = os.path.join(projectpath, module, "stringtable.xml")
try:
xmldoc = minidom.parse(stringtablepath)
except:
continue

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

def check_module(projectpath, module, languages):
""" Checks the given module for all the different languages. """
localized = []

stringtablepath = os.path.join(projectpath, module, "stringtable.xml")
try:
xmldoc = minidom.parse(stringtablepath)
except:
return 0, localized

keynumber = len(xmldoc.getElementsByTagName("Key"))

for language in languages:
localized.append(len(xmldoc.getElementsByTagName(language)))

return keynumber, localized

def main():
scriptpath = os.path.realpath(__file__)
projectpath = os.path.dirname(os.path.dirname(scriptpath))
projectpath = os.path.join(projectpath, "addons")

if "--markdown" not in sys.argv:
print("#########################")
print("# Stringtable Diag Tool #")
print("#########################")

languages = get_all_languages(projectpath)

if "--markdown" not in sys.argv:
print("\nLanguages present in the repo:")
print(", ".join(languages))

keysum = 0
localizedsum = list(map(lambda x: 0, languages))
missing = list(map(lambda x: [], languages))

for module in os.listdir(projectpath):
keynumber, localized = check_module(projectpath, module, languages)

if keynumber == 0:
continue

if "--markdown" not in sys.argv:
print("\n# " + module)

keysum += keynumber
for i in range(len(localized)):
if "--markdown" not in sys.argv:
print(" %s %s / %i" % ((languages[i]+":").ljust(10), str(localized[i]).ljust(3), keynumber))
localizedsum[i] += localized[i]
if localized[i] < keynumber:
missing[i].append(module)

if "--markdown" not in sys.argv:
print("\n###########")
print("# RESULTS #")
print("###########")
print("\nTotal number of keys: %i\n" % (keysum))

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])+")")

print("\n\n### MARKDOWN ###\n")

print("Total number of keys: %i\n" % (keysum))

print("| Language | Missing Entries | Relevant Modules | % done |")
print("|----------|----------------:|------------------|--------|")

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]),
round(100 * localizedsum[i] / keysum)))

if __name__ == "__main__":
main()