get-translator-credits.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import subprocess
  2. import re
  3. from collections import defaultdict
  4. from io import open
  5. from babel import Locale
  6. authors_by_locale = defaultdict(set)
  7. file_listing = subprocess.Popen('find ../wagtail -iname *.po', shell=True, stdout=subprocess.PIPE)
  8. for file_listing_line in file_listing.stdout:
  9. filename = file_listing_line.strip()
  10. # extract locale string from filename
  11. locale = re.search(r'locale/(\w+)/LC_MESSAGES', str(filename)).group(1)
  12. if locale == 'en':
  13. continue
  14. # read author list from each file
  15. with open(filename, 'rt') as f:
  16. has_found_translators_heading = False
  17. for line in f:
  18. line = line.strip()
  19. if line.startswith('#'):
  20. if has_found_translators_heading:
  21. author = re.match(r'\# (.*), [\d\-]+', line).group(1)
  22. authors_by_locale[locale].add(author)
  23. elif line.startswith('# Translators:'):
  24. has_found_translators_heading = True
  25. else:
  26. if has_found_translators_heading:
  27. break
  28. else:
  29. raise Exception("No 'Translators:' heading found in %s" % filename)
  30. LANGUAGE_OVERRIDES = {
  31. 'tet': 'Tetum',
  32. }
  33. def get_language_name(locale_string):
  34. try:
  35. return LANGUAGE_OVERRIDES[locale_string]
  36. except KeyError:
  37. return Locale.parse(locale_string).english_name
  38. language_names = [
  39. (get_language_name(locale_string), locale_string)
  40. for locale_string in authors_by_locale.keys()
  41. ]
  42. language_names.sort()
  43. for (language_name, locale) in language_names:
  44. print(("%s - %s" % (language_name, locale)))
  45. print("-----")
  46. for author in sorted(authors_by_locale[locale]):
  47. print(author)
  48. print('')