Skip to content

Fix: Handle whitespace-only translations properly#2375

Closed
khushal-winner wants to merge 1 commit intoOWASP:masterfrom
khushal-winner:fix/translation-edge-cases
Closed

Fix: Handle whitespace-only translations properly#2375
khushal-winner wants to merge 1 commit intoOWASP:masterfrom
khushal-winner:fix/translation-edge-cases

Conversation

@khushal-winner
Copy link
Contributor

Fix: Handle whitespace-only translations properly

Description

Fixes the translation checker to properly detect whitespace-only strings as empty translations.

Fixes #2374


Problem

The _check_translation_tags() method in scripts/check_translations.py was not detecting whitespace-only translations (e.g., " ", "\t \n") as empty because the check not " " evaluates to False in Python.

Current Behavior

  • Whitespace-only strings pass validation ❌
  • Translations with extra spaces not detected as untranslated ❌

Root Cause

elif not trans_tags[tag_id]:  # Bug: "   " is truthy
    empty.append(tag_id)
elif trans_tags[tag_id] == eng_text:
    untranslated.append(tag_id)

Solution

Changes Made

1. scripts/check_translations.py

Added .strip() check to properly detect whitespace-only strings:

Before:

elif not trans_tags[tag_id]:
    empty.append(tag_id)
elif trans_tags[tag_id] == eng_text:
    untranslated.append(tag_id)

After:

elif not trans_tags[tag_id] or not trans_tags[tag_id].strip():
    empty.append(tag_id)
elif trans_tags[tag_id].strip() == eng_text.strip():
    untranslated.append(tag_id)

2. scripts/check_translations_utest.py

Added TestWhitespaceHandling class with 4 comprehensive unit tests:

  • test_whitespace_only_detected_as_empty - Detects " " as empty
  • test_tabs_and_newlines_detected_as_empty - Detects "\t \n" as empty
  • test_extra_spaces_detected_as_untranslated - Detects " Login " as untranslated
  • test_properly_translated_no_issues - Ensures valid translations still work

Testing

New Test Suite

python -m unittest check_translations_utest.TestWhitespaceHandling -v

Results:

test_whitespace_only_detected_as_empty ... ok ✅
test_tabs_and_newlines_detected_as_empty ... ok ✅
test_extra_spaces_detected_as_untranslated ... ok ✅
test_properly_translated_no_issues ... ok ✅

----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK

All Existing Tests Pass

python -m unittest check_translations_utest.py

All existing tests continue to pass without any modifications ✅

Test Coverage

The new tests cover:

  • Empty strings ("")
  • Whitespace-only strings (" ")
  • Tabs and newlines ("\t \n ")
  • Extra spaces around text (" Login ")
  • Valid translations (no false positives)

@sydseter
Copy link
Collaborator

@khushal-winner please make sure your commits are signed with a verified signature.

@sydseter
Copy link
Collaborator

@khushal-winner Make sure your commits have a verified signature

@khushal-winner
Copy link
Contributor Author

@sydseter now i have verified my commits, thanks :)

@sydseter
Copy link
Collaborator

all the commits must have a verified signature.

@khushal-winner khushal-winner force-pushed the fix/translation-edge-cases branch 2 times, most recently from 33742c7 to cfa700b Compare February 25, 2026 22:27
@khushal-winner
Copy link
Contributor Author

all the commits must have a verified signature.

@sydseter done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug:Translation checker fails to detect whitespace-only tags

2 participants