Skip to content

# Fix: Handle whitespace-only translations properly#2382

Merged
sydseter merged 2 commits intoOWASP:masterfrom
khushal-winner:fix/whitespace-translation-detection
Feb 25, 2026
Merged

# Fix: Handle whitespace-only translations properly#2382
sydseter merged 2 commits intoOWASP:masterfrom
khushal-winner:fix/whitespace-translation-detection

Conversation

@khushal-winner
Copy link
Contributor

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)

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

Changes:
- Added .strip() check to properly detect whitespace-only strings
- Added .strip() comparison to detect translations with extra spaces as untranslated
- Added comprehensive unit tests for whitespace handling

Fixes OWASP#2374
- Fix path calculation for test files in check_translations_utest.py
- Tests now correctly locate test data in cornucopia/tests/test_files/source
- No impact on production code, only test infrastructure
@khushal-winner
Copy link
Contributor Author

@sydseter i created a new PR now, because that was getting messy, :)

@sydseter sydseter merged commit dd63f3d into OWASP:master Feb 25, 2026
8 of 9 checks passed
@sydseter
Copy link
Collaborator

@khushal-winner Thank you for your contribution.

@sydseter
Copy link
Collaborator

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