Add script for finding translated strings with broken placeholders

pull/7590/head
Matt Westcott 2021-10-14 15:05:36 +01:00 zatwierdzone przez LB (Ben Johnston)
rodzic 20ed834132
commit 4cc93bac68
2 zmienionych plików z 25 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,22 @@
import re
from pathlib import Path
import polib
placeholder_regexp = re.compile(r'\{[^\}]*?\}')
for path in Path(__file__).parent.resolve().parent.rglob('LC_MESSAGES/*.po'):
po = polib.pofile(path)
for entry in po:
if not entry.msgstr:
continue # ignore untranslated strings
expected_placeholders = set(placeholder_regexp.findall(entry.msgid))
actual_placeholders = set(placeholder_regexp.findall(entry.msgstr))
if expected_placeholders != actual_placeholders:
print("Invalid string at %s line %d:" % (path, entry.linenum))
print("\toriginal string %r has placeholders: %r" % (entry.msgid, expected_placeholders))
print("\ttranslated string %r has placeholders: %r" % (entry.msgstr, actual_placeholders))
print()

Wyświetl plik

@ -68,6 +68,9 @@ testing_extras = [
# django-taggit 1.3.0 made changes to verbose_name which affect migrations;
# the test suite migrations correspond to >=1.3.0
'django-taggit>=1.3.0,<2.0',
# for validating string formats in .po translation files
'polib>=1.1,<2.0',
]
# Documentation dependencies