Skip to content

Commit

Permalink
added param checks
Browse files Browse the repository at this point in the history
  • Loading branch information
TimGoll committed Oct 28, 2023
1 parent 7518409 commit 10de6fb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
7 changes: 7 additions & 0 deletions loadfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
multiline_text_pattern_open = r'L\.([a-zA-Z_][a-zA-Z_0-9]*)\s*=\s*\[\[([^\]]*)'
multiline_text_pattern_close = r'(.*?)\]\]'
multiline_single_line = r'L\.([a-zA-Z_][a-zA-Z_0-9]*)\s*=\s*\[\[(.*?)\]\]'
text_param_pattern = r'{([^{}]+)}'

def loadfile(path):
# Create a list to store the data
Expand Down Expand Up @@ -62,6 +63,8 @@ def loadfile(path):
"content" : singleline_text_match.group(2)
})

data[line_counter]["params"] = re.findall(text_param_pattern, data[line_counter]["content"])

line_counter += 1

continue
Expand All @@ -74,6 +77,8 @@ def loadfile(path):
"content" : multisingleline_text_match.group(2)
})

data[line_counter]["params"] = re.findall(text_param_pattern, data[line_counter]["content"])

line_counter += 1

continue
Expand All @@ -95,6 +100,8 @@ def loadfile(path):
if multiline_text_match_close and line[0:2] != "--":
data[line_counter]["content"] += "\n" + multiline_text_match_close.group(1)

data[line_counter]["params"] = re.findall(text_param_pattern, data[line_counter]["content"])

line_counter += 1

is_multiline = False
Expand Down
2 changes: 1 addition & 1 deletion parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
if not lang:
continue

new_lang = updatelang.updatelang(baselang, lang)
new_lang = updatelang.updatelang(baselang, lang, lang_file)

f = open(args.output + "/" + lang_file, "a", encoding="utf-8")

Expand Down
19 changes: 18 additions & 1 deletion updatelang.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def getelement(haystack, needle):
except KeyError:
continue

def updatelang(base, update):
def updatelang(base, update, lang_file):
newlang = []

found_alias = False
Expand Down Expand Up @@ -45,6 +45,23 @@ def updatelang(base, update):
transline = getelement(update, line["identifier"])

if transline != None:
in_base_not_in_trans = [param for param in line["params"] if param not in transline["params"]]
in_trans_not_in_base = [param for param in transline["params"] if param not in line["params"]]

if len(in_base_not_in_trans):
print("[ERROR] in " + lang_file + ": " + str(len(in_base_not_in_trans)) + " missing param(s) in traslation string with the following identifier: " + transline["identifier"])
print("[ERROR] - reference: " + line["content"].replace("\n", " /// "))
print("[ERROR] - translation: " + transline["content"].replace("\n", " /// "))
print("[ERROR] - missing: " + str(in_base_not_in_trans))
print("")

if len(in_trans_not_in_base):
print("[ERROR] in " + lang_file + ": " + str(len(in_trans_not_in_base)) + " unused param(s) in traslation string with the following identifier: " + transline["identifier"])
print("[ERROR] - reference: " + line["content"].replace("\n", " /// "))
print("[ERROR] - translation: " + transline["content"].replace("\n", " /// "))
print("[ERROR] - unused: " + str(in_trans_not_in_base))
print("")

if line["type"] == "single":
newlang.append("L." + transline["identifier"] + " = \"" + transline["content"] + "\"\n")
else:
Expand Down

0 comments on commit 10de6fb

Please sign in to comment.