Skip to content
This repository has been archived by the owner on Aug 24, 2023. It is now read-only.

Commit

Permalink
Merge pull request CleverRaven#53119 from BrettDong/lang
Browse files Browse the repository at this point in the history
Improve 3rd party mods compatibility in the new translation template generator
  • Loading branch information
ZhilkinSerg authored Nov 30, 2021
2 parents cfaec2f + 8aa7afb commit 5299ceb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
7 changes: 6 additions & 1 deletion lang/string_extractor/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ def parse_json_object(json, origin):
if "type" in json and type(json["type"]) is str:
json_type = json["type"].lower()
if json_type in parsers:
parsers[json_type](json, origin)
try:
parsers[json_type](json, origin)
except Exception as E:
print("Exception when parsing JSON data type \"{}\""
.format(json_type))
raise E
else:
raise Exception("Unrecognized JSON data type \"{}\""
.format(json_type))
Expand Down
16 changes: 11 additions & 5 deletions lang/string_extractor/parsers/npc_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@

def parse_npc_class(json, origin):
comment = json.get("//", None)
name = get_singular_name(json["name"])
write_text(json["name"], origin, comment=["Name of an NPC class", comment])
write_text(json["job_description"], origin,
comment=["Job description of \"{}\" NPC class".format(name),
comment])
name = ""
if "name" in json:
name = get_singular_name(json["name"])
write_text(json["name"], origin,
comment=["Name of an NPC class", comment])
elif "id" in json:
name = json["id"]
if "job_description" in json:
write_text(json["job_description"], origin,
comment=["Job description of \"{}\" NPC class".format(name),
comment])
4 changes: 3 additions & 1 deletion lang/string_extractor/parsers/profession.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
def parse_profession(json, origin):
name_male = ""
name_female = ""
if type(json["name"]) is dict:
if "name" not in json:
name_male = name_female = json["id"]
elif type(json["name"]) is dict:
name_male = json["name"]["male"]
name_female = json["name"]["female"]
elif type(json["name"]) is str:
Expand Down
7 changes: 6 additions & 1 deletion lang/string_extractor/parsers/speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@


def parse_speech(json, origin):
speaker = ", ".join(json.get("speaker", []))
speaker = ""
if "speaker" in json:
if type(json["speaker"]) is list:
speaker = ", ".join(json.get("speaker", []))
elif type(json["speaker"]) is str:
speaker = json["speaker"]
if "sound" in json:
write_text(json["sound"], origin, c_format=False,
comment="Speech from speaker {}".format(speaker))

0 comments on commit 5299ceb

Please sign in to comment.