Skip to content

Commit

Permalink
Workaround for issue python#3324: Fix indentation issues caused by co…
Browse files Browse the repository at this point in the history
…de snippets
  • Loading branch information
cacrespo committed Dec 1, 2024
1 parent ed85ddb commit ac34348
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion scripts/check_spell.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys
import tempfile

import polib
import pospell


Expand Down Expand Up @@ -44,7 +45,29 @@ def check_spell(po_files=None):
if not po_files:
po_files = Path(".").glob("*/*.po")

detected_errors = pospell.spell_check(po_files, personal_dict=output_filename, language="es_ES")
# Workaround issue #3324 FIXME
# It seems that all code snippets have line breaks '\n'. This causes the
# currently indentation issues.

# Create temporary copies of the original files.
po_files_tmp = []
for po_file in po_files:
with open(tempfile.mktemp(), "w") as temp_file:
# Copy content of the .po file
with open(po_file, "r", encoding="utf-8") as f:
temp_file.write(f.read())
po_files_tmp.append(temp_file.name)

# Don't translate probably code entries
polib_temp_file = polib.pofile(temp_file.name)
for entry in polib_temp_file:
if "\n" in entry.msgid:
entry.msgstr = ""
polib_temp_file.save()

detected_errors = pospell.spell_check(po_files_tmp, personal_dict=output_filename, language="es_ES")
for tmp, orig in zip(po_files_tmp, po_files):
print(tmp, " == ", orig)
return detected_errors


Expand Down

0 comments on commit ac34348

Please sign in to comment.