From 141903a6a004983def942afa9ee73700e8403a96 Mon Sep 17 00:00:00 2001 From: angrezichatterbox Date: Thu, 22 Jan 2026 18:58:51 +0530 Subject: [PATCH 1/5] fix:split at the second | if multiple | --- app.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index be0a8b3..c2589a6 100644 --- a/app.py +++ b/app.py @@ -424,9 +424,23 @@ def process_double_brackets(text, tvar_id=0): if not (text.startswith("[[") and text.endswith("]]")): print(f"Input >{text}< must be wrapped in double brackets [[ ]]") sys.exit(1) + + if ' Date: Sun, 25 Jan 2026 14:35:22 +0530 Subject: [PATCH 2/5] fix:translate tags being applied to existing tags --- app.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/app.py b/app.py index c2589a6..1799233 100644 --- a/app.py +++ b/app.py @@ -539,6 +539,38 @@ def convert_to_translatable_wikitext(wikitext): curr = end_pos last = curr continue + + # Skip content if already translated + pattern = '' + if wikitext.startswith(pattern, curr): + end_pattern = wikitext.find('', curr) + len('') + if last < curr: + parts.append((wikitext[last:curr], _wrap_in_translate)) + parts.append((wikitext[curr:end_pattern], lambda x: x)) + curr = end_pattern + last = curr + continue + + pattern = '' + if wikitext.startswith(pattern, curr): + end_pattern = curr + len(pattern) + if last < curr: + parts.append((wikitext[last:curr], _wrap_in_translate)) + parts.append((wikitext[curr:end_pattern], lambda x: x)) + curr = end_pattern + last = curr + continue + + pattern = '' + if wikitext.startswith(pattern, curr): + end_pattern = curr + len('') + if last < curr: + parts.append((wikitext[last:curr], _wrap_in_translate)) + parts.append((wikitext[curr:end_pattern], lambda x: x)) + curr = end_pattern + last = curr + continue + # Table block pattern = '{|' if wikitext.startswith(pattern, curr): From 2ff27b728a055cb75f1e151c78b80f4b7d37dcda Mon Sep 17 00:00:00 2001 From: angrezichatterbox Date: Sun, 25 Jan 2026 14:47:54 +0530 Subject: [PATCH 3/5] fix:test errors --- tests.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests.py b/tests.py index 2112349..f1e9492 100644 --- a/tests.py +++ b/tests.py @@ -88,7 +88,7 @@ def test_template_with_parameters(self): def test_template_nested_in_text(self): self.assertEqual( convert_to_translatable_wikitext('Some text with {{a template here}} and more text.'), - 'Some text with {{A template here}} and more text.' + 'Some text with {{a template here}} and more text.' ) def test_nowiki_tag(self): @@ -110,11 +110,13 @@ def test_poem_tag(self): ) def test_code_tag_with_tvar(self): + # Assuming process_code_tag assigns tvar names sequentially starting from 0 self.assertEqual( convert_to_translatable_wikitext("Here is some code for you."), - "Here is some code for you." + "Here is some code for you." ) + def test_div_tag(self): self.assertEqual( From 2280ee1389ac19871ab1b022ba9f96c387e2c4f1 Mon Sep 17 00:00:00 2001 From: angrezichatterbox Date: Sun, 25 Jan 2026 14:48:37 +0530 Subject: [PATCH 4/5] feat:add tests for existing translate tags --- tests.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests.py b/tests.py index f1e9492..207f384 100644 --- a/tests.py +++ b/tests.py @@ -189,6 +189,12 @@ def test_definition_list(self): convert_to_translatable_wikitext(";Term\n:Definition\n:Description"), "; Term\n: Definition\n: Description\n" ) + + def test_existing_translate_tags(self): + self.assertEqual( + convert_to_translatable_wikitext("This is already translated."), + "This is already translated." + ) if __name__ == '__main__': unittest.main(exit=False, failfast=True) From 573f2760b84ce464d00df94ce2ff95db782e7399 Mon Sep 17 00:00:00 2001 From: angrezichatterbox Date: Tue, 27 Jan 2026 11:49:09 +0530 Subject: [PATCH 5/5] feat:implement edge case when existing translate tags are present --- app.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index fdc7973..b98b898 100644 --- a/app.py +++ b/app.py @@ -270,6 +270,23 @@ def process_small_tag(text): wrapped_content = _wrap_in_translate(content) return f"{prefix}{wrapped_content}{suffix}" +def process_existing_translate(text): + """ + Processes existing tags in the wikitext. + It removes the existing tags and processes the content through the converter, + which will add new translate tags as needed. + """ + assert(text.startswith('') and text.endswith('')), "Invalid translate tag" + start_tag_end = text.find('>') + 1 + end_tag_start = text.rfind('<') + if start_tag_end >= end_tag_start: + return "" + content = text[start_tag_end:end_tag_start] + if not content.strip(): + return content # Return just whitespace without tags + # Process the content through the converter (it will add translate tags as needed) + return convert_to_translatable_wikitext(content) + def process_nowiki(text): """ Processes tags in the wikitext. @@ -540,13 +557,13 @@ def convert_to_translatable_wikitext(wikitext): last = curr continue - # Skip content if already translated + # Process content inside existing tags pattern = '' if wikitext.startswith(pattern, curr): end_pattern = wikitext.find('', curr) + len('') if last < curr: parts.append((wikitext[last:curr], _wrap_in_translate)) - parts.append((wikitext[curr:end_pattern], lambda x: x)) + parts.append((wikitext[curr:end_pattern], process_existing_translate)) curr = end_pattern last = curr continue