2
0

get-translator-credits.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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_match = re.match(r'\# (.*), [\d\-]+', line)
  22. if not author_match:
  23. break
  24. author = author_match.group(1)
  25. authors_by_locale[locale].add(author)
  26. elif line.startswith('# Translators:'):
  27. has_found_translators_heading = True
  28. else:
  29. if has_found_translators_heading:
  30. break
  31. else:
  32. raise Exception("No 'Translators:' heading found in %s" % filename)
  33. LANGUAGE_OVERRIDES = {
  34. 'tet': 'Tetum',
  35. 'ht': 'Haitian',
  36. }
  37. def get_language_name(locale_string):
  38. try:
  39. return LANGUAGE_OVERRIDES[locale_string]
  40. except KeyError:
  41. return Locale.parse(locale_string).english_name
  42. language_names = [
  43. (get_language_name(locale_string), locale_string)
  44. for locale_string in authors_by_locale.keys()
  45. ]
  46. language_names.sort()
  47. for (language_name, locale) in language_names:
  48. print(("%s - %s" % (language_name, locale)))
  49. print("-----")
  50. for author in sorted(authors_by_locale[locale]):
  51. print(author)
  52. print('')