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

fix #415: [EN] Support 'named-after' template #418

Merged
merged 1 commit into from Dec 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions scripts/lang/en/__init__.py
Expand Up @@ -53,6 +53,7 @@
"multiple images",
"+obj",
"picdic",
"picimg",
"picdiclabel",
"rel-bottom",
"rel-top",
Expand Down Expand Up @@ -281,6 +282,13 @@ def last_template_handler(
>>> last_template_handler(["given name", "en", "male", "from=Hindi", "meaning=patience"], "en")
'<i>A male given name from Hindi, meaning "patience"</i>'

>>> last_template_handler(["named-after", "en", "nationality=French", "occupation=Renault engineer", "Pierre Bézier", "nocap=1"], "en")
'named after French Renault engineer Pierre Bézier'
>>> last_template_handler(["named-after", "en", "Bertrand Russell", "tr=tr", "died=1970", "born=1872", "nat=English", "occ=mathematician", "occ2=logician"], "en")
'Named after English mathematician and logician Bertrand Russell (<i>tr</i>) (1872–1970)'
>>> last_template_handler(["named-after", "en", "Patrick Swayze", "alt="], "en")
'Patrick Swayze'

>>> last_template_handler(["place", "en", "A country in the Middle East"], "en")
'A country in the Middle East'
>>> last_template_handler(["place", "en", "A country", "modern=Iraq"], "en")
Expand Down Expand Up @@ -718,6 +726,30 @@ class Seg(TypedDict, total=False):

return italic(phrase)

if tpl == "named-after":
parts.pop(0) # Remove the language
p = parts.pop(0)
p = p or "an unknown person"
if "alt" in data:
phrase = data["alt"]
else:
starter = "named after"
phrase = starter if data["nocap"] else starter.capitalize()
if data["nationality"]:
phrase += f" {data['nationality']}"
elif data["nat"]:
phrase += f" {data['nat']}"
occ = join_names("occ", " and ", False, "occupation")
if occ:
phrase += f" {occ}"
phrase += " "
phrase += f"{p}"
if data["tr"]:
phrase += f" ({italic(data['tr'])})"
if data["died"] or data["born"]:
phrase += f" ({data['born'] or '?'}–{data['died']})"
return phrase

if tpl == "place":
parts.pop(0) # Remove the language
phrase = ""
Expand Down