Skip to content

Commit 87b0d5d

Browse files
feat:implement translate tags for templates (#17)
1 parent 532abbb commit 87b0d5d

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

app.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -472,15 +472,14 @@ def process_template(text):
472472
"""
473473
assert(text.startswith('{{') and text.endswith('}}')), "Invalid template tag"
474474
# Split the template content from the rest of the text
475-
inner_content = text[2:-2].strip() # Remove the leading {{ and trailing }}
476-
inner_content = capitalise_first_letter(inner_content) # Capitalise the first letter of the inner content
477-
478-
# If the inner content is empty, return an empty string
479-
if not inner_content :
480-
return text
481-
482-
# Wrap the inner content in <translate> tags
483-
return '{{' + inner_content + '}}'
475+
code = mwparserfromhell.parse(text)
476+
template = code.filter_templates()[0]
477+
478+
if template.has(2):
479+
param = template.get(2)
480+
param.value = f"2=<translate>{param.value.strip_code()}</translate>"
481+
482+
return str(code)
484483

485484
def process_raw_url(text):
486485
"""

0 commit comments

Comments
 (0)