Skip to content

Commit

Permalink
[ES] Fix handling of the 'l+' template (fixes #134)
Browse files Browse the repository at this point in the history
  • Loading branch information
BoboTiG committed Sep 21, 2020
1 parent 435af24 commit f56deaa
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions scripts/lang/es.py
Expand Up @@ -200,8 +200,6 @@
"impropia": "italic(parts[1])",
# {{l|es|tamo}}
"l": "parts[-1]",
# {{l+|pt|freguesia}}
"l+": "italic(parts[-1])",
# {{nombre científico}}
"nombre científico": "superscript(tpl)",
# {{plm}}
Expand Down Expand Up @@ -284,6 +282,13 @@ def last_template_handler(template: Tuple[str, ...], locale: str) -> str:
'De <i>átomo</i> y el sufijo <i>-́ico</i>'
>>> last_template_handler(["etimología", "sufijo", "átomo", "ico"], "es")
'De <i>átomo</i> y el sufijo <i>-ico</i>'
>>> last_template_handler(["l+", "la", "impello", "impellō, impellere", "glosa=empujar"], "es")
'<i>impellō, impellere</i> ("empujar")'
>>> last_template_handler(["l+", "grc", "ἀράχνη", "tr=aráchnē", "glosa=araña"], "es")
'ἀράχνη (<i>aráchnē</i>, "araña")'
>>> last_template_handler(["l+", "ar", "حتى", "tr=ḥatta"], "es")
'حتى (<i>ḥatta</i>)'
"""
from collections import defaultdict
from itertools import zip_longest
Expand Down Expand Up @@ -343,6 +348,30 @@ def last_template_handler(template: Tuple[str, ...], locale: str) -> str:

return phrase

# Handle the {{l+}} template
if tpl == "l+":
data = defaultdict(str)
for part in parts.copy():
if "=" in part:
key, value = part.split("=", 1)
data[key] = value
parts.pop(parts.index(part))

trans = data.get("tr", "")
glosa = data.get("glosa", "")
phrase = parts[-1] if trans else italic(parts[-1])
if trans or glosa:
phrase += " ("
if trans:
phrase += f"{italic(trans)}"
if glosa:
if trans:
phrase += ", "
phrase += f'"{glosa}"'
phrase += ")"

return phrase

res = ""
for word1, word2 in zip_longest(template, parts):
# Filter out "leng=" parts
Expand Down

0 comments on commit f56deaa

Please sign in to comment.