Skip to content

Commit

Permalink
Improved error handling and added Workflow summary
Browse files Browse the repository at this point in the history
  • Loading branch information
wofsauge committed Jul 30, 2024
1 parent 1dbd571 commit d954016
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 30 deletions.
21 changes: 19 additions & 2 deletions .github/scripts/localizationChecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

ignoreNodesWithName = {"fonts"}

maxChecklimit = {"tarotClothBuffs": 2}


# count en_us entries for stats
def count_entries(t):
Expand All @@ -34,18 +36,26 @@ def count_entries(t):
count += count_entries(t[k])
return count

def getMaxCheckLimit(parentName):
for entry in maxChecklimit:
if entry in parentName:
return maxChecklimit[entry]
return float('inf')

# find entries in table2 that are missing or different than in table 1
def compare_tables(table1, table2, prev_key):
errorCount = 0
checkLimit = getMaxCheckLimit(prev_key)
for k in table1:
if k in ignoreNodesWithName:
checkLimit -= 1
if k in ignoreNodesWithName or checkLimit < 0:
# dont evaluate nodes that are listed in this table
continue
if k not in table2:
print(f"\tTable '{prev_key}' does not contain key: {k}")
errorCount += 1
# table is missing. add all missing entries as error
if lupa.lua_type(table1[k]) == "table":
if lupa.lua_type(table1[k]) == "table":
errorCount += count_entries(table1[k])
elif lupa.lua_type(table2[k]) != lupa.lua_type(table1[k]):
print(f"\tType mismatch in table '{prev_key}', key: {k}")
Expand Down Expand Up @@ -81,8 +91,15 @@ def compare_tables(table1, table2, prev_key):
languages[lang] = [percentage, errorCount]
print(f"{Red}Errors found: {errorCount} / {en_us_entries}{Color_Off}\n\n")



gitWorkflowSummary = "### Translation progress\n| Language | Completion | Missing entries |\n|---|---|---|\n"
print(f"{Blue}Translation progress:{Color_Off}")
for lang in languages:
print(
f"\t{BWhite}{lang}{Color_Off}\t{Blue}{round(languages[lang][0],2)}%{Color_Off}\t{Red}{languages[lang][1]} missing{Color_Off}"
)
errorMessage = languages[lang][1] if languages[lang][1] >0 else "🎉"
gitWorkflowSummary += f"| {lang} | {round(languages[lang][0],2)}% | {errorMessage} |"

os.environ["GITHUB_STEP_SUMMARY"] = gitWorkflowSummary
78 changes: 50 additions & 28 deletions features/eid_debugging.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,61 @@ EID:countEntries(EID.descriptions["en_us"])
local enUSEntries = count
print("en_us entries: "..enUSEntries)

for _,lang in ipairs(languageFilesToCheck) do

local maxChecklimit = {["tarotClothBuffs"] = 2}
function EID:getMaxCheckLimit(parentName)
for entry, _ in pairs(maxChecklimit) do
if string.find(parentName, entry) then
return maxChecklimit[entry]
end
end
return math.maxinteger
end

local ignoreNodesWithName = {["fonts"] = true}


for _, lang in ipairs(languageFilesToCheck) do
print("Now checking integrity of languagefile: " .. lang)
-- Generic function to compare two tables
function EID:compareTables(table1, table2, prevKey, progress)
local checkLimit = EID:getMaxCheckLimit(prevKey)
for k, _ in pairs(table1) do
progress[1] = progress[1] + 1
if not table2[k] then
print(" Table '" .. prevKey .. "' does not contain key: " .. k)
progress[2] = progress[2] + 1
elseif type(table2[k]) ~= type(table1[k]) then
print("Type mismatch in table '" .. prevKey .. "', key: " .. k)
progress[2] = progress[2] + 1
elseif type(table2[k]) == "table" then
EID:compareTables(table1[k], table2[k], k, progress)
else
-- check for broken markup stuff
local filteredText = EID:replaceShortMarkupStrings(table2[k])
local textPartsTable = EID:filterColorMarkup(filteredText, EID:getNameColor())
for _, textPart in ipairs(textPartsTable) do
local filteredSpriteText, spriteTable = EID:filterIconMarkup(textPart[1])

if string.find(filteredSpriteText, "{{") or string.find(filteredSpriteText, "}}") then
print(" Table '" .. prevKey .. "' entry '" .. k .. "' does contain a broken markup object: '" .. table2[k])
progress[1] = progress[1] - 2
progress[2] = progress[2] + 1
break
else
for _, sprite in ipairs(spriteTable) do
if sprite[1][1] == "ERROR" then
print(" Table '" .. prevKey .. "' entry '" .. k .. "' does contain a bad icon markup in string: '" .. table2[k])
progress[1] = progress[1] - 2
progress[2] = progress[2] + 1
break
checkLimit = checkLimit - 1
if not (ignoreNodesWithName[k] or checkLimit < 0) then
-- only evaluate nodes that are not listed in this table
if not table2[k] then
print(" Table '" .. prevKey .. "' does not contain key: " .. k)
progress[2] = progress[2] + 1
elseif type(table2[k]) ~= type(table1[k]) then
print("Type mismatch in table '" .. prevKey .. "', key: " .. k)
progress[2] = progress[2] + 1
elseif type(table2[k]) == "table" then
EID:compareTables(table1[k], table2[k], k, progress)
else
-- check for broken markup stuff
local filteredText = EID:replaceShortMarkupStrings(table2[k])
local textPartsTable = EID:filterColorMarkup(filteredText, EID:getNameColor())
for _, textPart in ipairs(textPartsTable) do
local filteredSpriteText, spriteTable = EID:filterIconMarkup(textPart[1])

if string.find(filteredSpriteText, "{{") or string.find(filteredSpriteText, "}}") then
print(" Table '" ..
prevKey .. "' entry '" .. k .. "' does contain a broken markup object: '" .. table2[k])
progress[1] = progress[1] - 2
progress[2] = progress[2] + 1
break
else
for _, sprite in ipairs(spriteTable) do
if sprite[1][1] == "ERROR" then
print(" Table '" ..
prevKey ..
"' entry '" .. k .. "' does contain a bad icon markup in string: '" .. table2[k])
progress[1] = progress[1] - 2
progress[2] = progress[2] + 1
break
end
end
end
end
Expand Down

0 comments on commit d954016

Please sign in to comment.