check-translation-strings.py 820 B

12345678910111213141516171819202122
  1. import re
  2. from pathlib import Path
  3. import polib
  4. placeholder_regexp = re.compile(r'\{[^\}]*?\}')
  5. for path in Path(__file__).parent.resolve().parent.rglob('LC_MESSAGES/*.po'):
  6. po = polib.pofile(path)
  7. for entry in po:
  8. if not entry.msgstr:
  9. continue # ignore untranslated strings
  10. expected_placeholders = set(placeholder_regexp.findall(entry.msgid))
  11. actual_placeholders = set(placeholder_regexp.findall(entry.msgstr))
  12. if expected_placeholders != actual_placeholders:
  13. print("Invalid string at %s line %d:" % (path, entry.linenum))
  14. print("\toriginal string %r has placeholders: %r" % (entry.msgid, expected_placeholders))
  15. print("\ttranslated string %r has placeholders: %r" % (entry.msgstr, actual_placeholders))
  16. print()