Skip to content

Commit

Permalink
Update sanitize_po_files.py
Browse files Browse the repository at this point in the history
Handling potential abnormal situations
  • Loading branch information
zengwei2000 committed Jun 21, 2023
1 parent 96b5df9 commit e4bbe50
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions scripts/sanitize_po_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@

def sanitize_po_file(po_file):
print("Processing", po_file)
po = polib.pofile(po_file)
try:
po = polib.pofile(po_file)
except Exception as e:
print(f"Error: Failed to read PO file {po_file}: {e}")
return
for entry in po:
msgid_without_indents = entry.msgid.strip()
msgstr_without_indents = entry.msgstr.strip()
Expand All @@ -40,7 +44,10 @@ def sanitize_po_file(po_file):
msgstr_plural_without_indents)
if re.match(r"^\s+$", entry.msgstr_plural[i]):
entry.msgstr_plural[i] = ""
po.save()
try:
po.save()
except Exception as e:
print(f"Error: Failed to save PO file {po_file}: {e}")


if __name__ == "__main__":
Expand Down

0 comments on commit e4bbe50

Please sign in to comment.