Skip to content

Commit ac34348

Browse files
committed
Workaround for issue python#3324: Fix indentation issues caused by code snippets
1 parent ed85ddb commit ac34348

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

scripts/check_spell.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import sys
88
import tempfile
99

10+
import polib
1011
import pospell
1112

1213

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

47-
detected_errors = pospell.spell_check(po_files, personal_dict=output_filename, language="es_ES")
48+
# Workaround issue #3324 FIXME
49+
# It seems that all code snippets have line breaks '\n'. This causes the
50+
# currently indentation issues.
51+
52+
# Create temporary copies of the original files.
53+
po_files_tmp = []
54+
for po_file in po_files:
55+
with open(tempfile.mktemp(), "w") as temp_file:
56+
# Copy content of the .po file
57+
with open(po_file, "r", encoding="utf-8") as f:
58+
temp_file.write(f.read())
59+
po_files_tmp.append(temp_file.name)
60+
61+
# Don't translate probably code entries
62+
polib_temp_file = polib.pofile(temp_file.name)
63+
for entry in polib_temp_file:
64+
if "\n" in entry.msgid:
65+
entry.msgstr = ""
66+
polib_temp_file.save()
67+
68+
detected_errors = pospell.spell_check(po_files_tmp, personal_dict=output_filename, language="es_ES")
69+
for tmp, orig in zip(po_files_tmp, po_files):
70+
print(tmp, " == ", orig)
4871
return detected_errors
4972

5073

0 commit comments

Comments
 (0)