You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

updatetranslations.py 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env python3
  2. # updatetranslations.py
  3. #
  4. # tl;dr this script updates our translation file with the newest, coolest strings we've added!
  5. # it manually searches the source code, extracts strings and then updates the language files.
  6. # Written in 2018 by Daniel Oaks <daniel@danieloaks.net>
  7. #
  8. # To the extent possible under law, the author(s) have dedicated all copyright
  9. # and related and neighboring rights to this software to the public domain
  10. # worldwide. This software is distributed without any warranty.
  11. #
  12. # You should have received a copy of the CC0 Public Domain Dedication along
  13. # with this software. If not, see
  14. # <http://creativecommons.org/publicdomain/zero/1.0/>.
  15. """updatetranslations.py
  16. Usage:
  17. updatetranslations.py run <irc-dir> <languages-dir>
  18. updatetranslations.py --version
  19. updatetranslations.py (-h | --help)
  20. Options:
  21. <irc-dir> Oragono's irc subdirectory where the Go code is kept.
  22. <languages-dir> Languages directory."""
  23. import os
  24. import re
  25. from docopt import docopt
  26. import yaml
  27. if __name__ == '__main__':
  28. arguments = docopt(__doc__, version="0.1.0")
  29. if arguments['run']:
  30. lang_strings = []
  31. for subdir, dirs, files in os.walk(arguments['<irc-dir>']):
  32. for fname in files:
  33. filepath = subdir + os.sep + fname
  34. if filepath.endswith('.go'):
  35. content = open(filepath, 'r').read()
  36. matches = re.findall(r'\.t\("((?:[^"]|\\")+)"\)', content)
  37. for match in matches:
  38. if match not in lang_strings:
  39. lang_strings.append(match)
  40. matches = re.findall(r'\.t\(\`([^\`]+)\`\)', content)
  41. for match in matches:
  42. match = match.replace("\n", "\\n").replace("\"", "\\\"")
  43. if match not in lang_strings:
  44. lang_strings.append(match)
  45. for match in sorted(lang_strings):
  46. print(' "' + match + '": ""')