get-translator-credits.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import subprocess
  2. import re
  3. from collections import defaultdict
  4. authors_by_locale = defaultdict(set)
  5. file_listing = subprocess.Popen('find ../wagtail -iname *.po', shell=True, stdout=subprocess.PIPE)
  6. for file_listing_line in file_listing.stdout:
  7. filename = file_listing_line.strip()
  8. # extract locale string from filename
  9. locale = re.search(r'locale/(\w+)/LC_MESSAGES', filename).group(1)
  10. if locale == 'en':
  11. continue
  12. # read author list from each file
  13. with file(filename) as f:
  14. has_found_translators_heading = False
  15. for line in f:
  16. line = line.strip()
  17. if line.startswith('#'):
  18. if has_found_translators_heading:
  19. author = re.match(r'\# (.*), [\d\-]+', line).group(1)
  20. authors_by_locale[locale].add(author)
  21. elif line.startswith('# Translators:'):
  22. has_found_translators_heading = True
  23. else:
  24. if has_found_translators_heading:
  25. break
  26. else:
  27. raise Exception("No 'Translators:' heading found in %s" % filename)
  28. locales = sorted(authors_by_locale.keys())
  29. for locale in locales:
  30. print(locale)
  31. print("-----")
  32. for author in sorted(authors_by_locale[locale]):
  33. print(author)
  34. print('')