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

Improve item name presentation in translation comments #51989

Merged
merged 1 commit into from
Sep 30, 2021
Merged
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
25 changes: 19 additions & 6 deletions lang/extract_json_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,21 @@ def warning_supressed(filename):
def gender_options(subject):
return [subject + ":" + g for g in all_genders]


def get_singular_name(name):
if type(name) is dict:
if "str_sp" in name:
return name["str_sp"]
elif "str" in name:
return name["str"]
else:
raise Exception("Cannot find singular name in {}".format(name))
elif type(name) is str:
return name
else:
raise Exception("Cannot find singular name in {}".format(name))


#
# SPECIALIZED EXTRACTION FUNCTIONS
#
Expand Down Expand Up @@ -797,8 +812,9 @@ def extract_missiondef(item):
if item_name is None:
raise WrongJSONItem("JSON item don't contain 'name' field", item)
writestr(outfile, item_name)
singular_name = get_singular_name(item_name)
if "description" in item:
comment = "Description for mission '{}'".format(item_name)
comment = "Description for mission '{}'".format(singular_name)
writestr(outfile, item["description"], comment=comment)
if "dialogue" in item:
dialogue = item.get("dialogue")
Expand Down Expand Up @@ -1304,10 +1320,7 @@ def extract(item, infilename):
else:
writestr(outfile, name, **kwargs)
wrote = True
if type(name) is dict and "str" in name:
singular_name = name["str"]
else:
singular_name = name
singular_name = get_singular_name(name)

def do_extract(item):
wrote = False
Expand All @@ -1327,7 +1340,7 @@ def do_extract(item):
if "conditional_names" in item:
for cname in item["conditional_names"]:
c = "Conditional name for {} when {} matches {}".format(
name, cname["type"], cname["condition"])
singular_name, cname["type"], cname["condition"])
writestr(outfile, cname["name"], comment=c,
format_strings=True, pl_fmt=True, **kwargs)
wrote = True
Expand Down