get-translator-credits.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import re
  2. import subprocess
  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. 'ht': 'Haitian',
  33. }
  34. def get_language_name(locale_string):
  35. try:
  36. return LANGUAGE_OVERRIDES[locale_string]
  37. except KeyError:
  38. return Locale.parse(locale_string).english_name
  39. language_names = [
  40. (get_language_name(locale_string), locale_string)
  41. for locale_string in authors_by_locale.keys()
  42. ]
  43. language_names.sort()
  44. for (language_name, locale) in language_names:
  45. print(("%s - %s" % (language_name, locale)))
  46. print("-----")
  47. for author in sorted(authors_by_locale[locale]):
  48. print(author)
  49. print('')