Localization Helper (#275)

* Localization Helper

* Update main.py

* Update main.py

* adding comments to code and translating exceptions into English

* cringe fix

* Update yml_parser.py

* tweak

* Update main.py
This commit is contained in:
comasqw
2024-06-25 19:02:02 +04:00
committed by GitHub
parent e12f499594
commit fa86f705aa
14 changed files with 270 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
def read_ftl(path: str) -> dict:
"""
The function looks at each line of the ftl
file and determines by the indentation in the line whether
it is a new prototype or an attribute of an old one.
"""
prototypes = {
}
last_prototype = ""
try:
with open(path, encoding="utf-8") as file:
for line in file.readlines():
if line.startswith("#") or line.startswith("\n"):
continue
if not line.startswith(" "):
proto_id, proto_name = line.split(" = ")
proto_id = proto_id.replace("ent-", "")
last_prototype = proto_id
prototypes[proto_id] = {"name": proto_name.strip(),
"desc": None,
"suffix": None
}
else:
if "desc" in line:
attr = "desc"
elif "suffix" in line:
attr = "suffix"
prototypes[last_prototype][attr] = line.split(" = ")[-1].strip()
except Exception as e:
with open("logs/errors_log.txt", "a") as file:
file.write(f"FTL-ERROR:\nAn error occurred while reading a file {path}, error - {e}\n")
return prototypes