Skip to content

Commit d8ee1da

Browse files
committed
fix: wrap entire section heading in <translate> tags per MediaWiki guidelines
Instead of wrapping only the heading text (==<translate>text</translate>==), the entire heading including == markers is now wrapped with translate tags on their own lines (<translate>\n==text==\n</translate>). This preserves heading context for translators and enables automatic language anchors without needing {{anchor}} workarounds.
1 parent 1a16c40 commit d8ee1da

3 files changed

Lines changed: 20 additions & 4 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ instance/
3838
*.pylint.d/
3939
*.pydist/
4040
*.pytest_cache/
41+
42+
.claude/*
43+
CLAUDE.md

app.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,16 +516,17 @@ def process_template(text):
516516
# --- Section Heading Handler ---
517517
def process_section_heading(text):
518518
"""
519-
Processes section headings like ==Title== and wraps the heading text in <translate> tags.
519+
Processes section headings like ==Title== and wraps the entire heading in <translate> tags,
520+
with the tags on their own lines per MediaWiki translation guidelines.
520521
"""
521522
# Match ==Title==, ===Subsection===, etc.
522523
match = re.match(r'^(=+)([^=]+)(=+)$', text.strip())
523524
if not match:
524525
return text
525526
level = match.group(1)
526527
heading_text = match.group(2).strip()
527-
# Reconstruct with same number of = on both sides
528-
return f'{level}<translate>{heading_text}</translate>{level}'
528+
# Wrap the entire heading (including == markers) in <translate> tags on their own lines
529+
return f'<translate>\n{level}{heading_text}{level}\n</translate>'
529530

530531
def process_raw_url(text):
531532
"""

tests.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,19 @@ class TestTranslatableWikitext(unittest.TestCase):
66
def test_section_headers(self):
77
self.assertEqual(
88
convert_to_translatable_wikitext("==HELLO=="),
9-
"<translate>==HELLO==</translate>" # Removed the \n\n that was expected
9+
"<translate>\n==HELLO==\n</translate>"
10+
)
11+
12+
def test_section_heading_strips_spaces(self):
13+
self.assertEqual(
14+
convert_to_translatable_wikitext("== Example =="),
15+
"<translate>\n==Example==\n</translate>"
16+
)
17+
18+
def test_section_headings_multiple_levels_with_body(self):
19+
self.assertEqual(
20+
convert_to_translatable_wikitext("== Example ==\n\nlorem ipsum\n\n=== Second example ===\n\nlorem ipsum"),
21+
"<translate>\n==Example==\n</translate>\n\n<translate>lorem ipsum</translate>\n\n<translate>\n===Second example===\n</translate>\n\n<translate>lorem ipsum</translate>"
1022
)
1123

1224
def test_file_tag_translations(self):

0 commit comments

Comments
 (0)