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 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. import json
  26. from docopt import docopt
  27. import yaml
  28. if __name__ == '__main__':
  29. arguments = docopt(__doc__, version="0.1.0")
  30. if arguments['run']:
  31. # general IRC strings
  32. irc_strings = []
  33. for subdir, dirs, files in os.walk(arguments['<irc-dir>']):
  34. for fname in files:
  35. filepath = subdir + os.sep + fname
  36. if filepath.endswith('.go'):
  37. content = open(filepath, 'r', encoding='UTF-8').read()
  38. matches = re.findall(r'\.t\("((?:[^"]|\\")+)"\)', content)
  39. for match in matches:
  40. if match not in irc_strings:
  41. irc_strings.append(match)
  42. matches = re.findall(r'\.t\(\`([^\`]+)\`\)', content)
  43. for match in matches:
  44. if match not in irc_strings:
  45. irc_strings.append(match)
  46. print("irc strings:")
  47. print(json.dumps({k:k for k in irc_strings}, sort_keys=True, indent=2, separators=(',', ': ')))
  48. # help entries
  49. help_strings = []
  50. for subdir, dirs, files in os.walk(arguments['<irc-dir>']):
  51. for fname in files:
  52. filepath = subdir + os.sep + fname
  53. if fname == 'help.go':
  54. content = open(filepath, 'r', encoding='UTF-8').read()
  55. matches = re.findall(r'\`([^\`]+)\`', content)
  56. for match in matches:
  57. if '\n' in match and match not in help_strings:
  58. help_strings.append(match)
  59. print()
  60. print("help strings:")
  61. print(json.dumps({k:k for k in help_strings}, sort_keys=True, indent=2, separators=(',', ': ')))
  62. # nickserv help entries
  63. help_strings = []
  64. for subdir, dirs, files in os.walk(arguments['<irc-dir>']):
  65. for fname in files:
  66. filepath = subdir + os.sep + fname
  67. if fname == 'nickserv.go':
  68. content = open(filepath, 'r', encoding='UTF-8').read()
  69. matches = re.findall(r'\`([^\`]+)\`', content)
  70. for match in matches:
  71. if '\n' in match and match not in help_strings:
  72. help_strings.append(match)
  73. print()
  74. print("nickserv help strings:")
  75. print(json.dumps({k:k for k in help_strings}, sort_keys=True, indent=2, separators=(',', ': ')))