Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. ignored_strings = [
  29. 'none', 'saset'
  30. ]
  31. if __name__ == '__main__':
  32. arguments = docopt(__doc__, version="0.1.0")
  33. if arguments['run']:
  34. # general IRC strings
  35. irc_strings = []
  36. for subdir, dirs, files in os.walk(arguments['<irc-dir>']):
  37. for fname in files:
  38. filepath = subdir + os.sep + fname
  39. if filepath.endswith('.go'):
  40. content = open(filepath, 'r', encoding='UTF-8').read()
  41. matches = re.findall(r'\.t\("((?:[^"]|\\")+)"\)', content)
  42. for match in matches:
  43. if match not in irc_strings:
  44. irc_strings.append(match)
  45. matches = re.findall(r'\.t\(\`([^\`]+)\`\)', content)
  46. for match in matches:
  47. if match not in irc_strings:
  48. irc_strings.append(match)
  49. for s in ignored_strings:
  50. try:
  51. irc_strings.remove(s)
  52. except ValueError:
  53. # ignore any that don't exist
  54. ...
  55. print("irc strings:", len(irc_strings))
  56. with open(os.path.join(arguments['<languages-dir>'], 'example', 'irc.lang.json'), 'w') as f:
  57. f.write(json.dumps({k:k for k in irc_strings}, sort_keys=True, indent=2, separators=(',', ': ')))
  58. f.write('\n')
  59. for string in irc_strings:
  60. if 1 < string.count('%s') + string.count('%d') + string.count('%f'):
  61. print(' confirm:', string)
  62. # 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 == 'help.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. for s in ignored_strings:
  74. try:
  75. help_strings.remove(s)
  76. except ValueError:
  77. # ignore any that don't exist
  78. ...
  79. print("help strings:", len(help_strings))
  80. with open(os.path.join(arguments['<languages-dir>'], 'example', 'help.lang.json'), 'w') as f:
  81. f.write(json.dumps({k:k for k in help_strings}, sort_keys=True, indent=2, separators=(',', ': ')))
  82. f.write('\n')
  83. for string in help_strings:
  84. if 1 < string.count('%s') + string.count('%d') + string.count('%f'):
  85. print(' confirm:', string.split('\n')[0])
  86. # nickserv help entries
  87. help_strings = []
  88. for subdir, dirs, files in os.walk(arguments['<irc-dir>']):
  89. for fname in files:
  90. filepath = subdir + os.sep + fname
  91. if fname == 'nickserv.go':
  92. content = open(filepath, 'r', encoding='UTF-8').read()
  93. matches = re.findall(r'\`([^\`]+)\`', content)
  94. for match in matches:
  95. if match not in help_strings:
  96. help_strings.append(match)
  97. for s in ignored_strings:
  98. try:
  99. help_strings.remove(s)
  100. except ValueError:
  101. # ignore any that don't exist
  102. ...
  103. print("nickserv help strings:", len(help_strings))
  104. with open(os.path.join(arguments['<languages-dir>'], 'example', 'nickserv.lang.json'), 'w') as f:
  105. f.write(json.dumps({k:k for k in help_strings}, sort_keys=True, indent=2, separators=(',', ': ')))
  106. f.write('\n')
  107. for string in help_strings:
  108. if 1 < string.count('%s') + string.count('%d') + string.count('%f'):
  109. print(' confirm:', string)
  110. # chanserv help entries
  111. help_strings = []
  112. for subdir, dirs, files in os.walk(arguments['<irc-dir>']):
  113. for fname in files:
  114. filepath = subdir + os.sep + fname
  115. if fname == 'chanserv.go':
  116. content = open(filepath, 'r', encoding='UTF-8').read()
  117. matches = re.findall(r'\`([^\`]+)\`', content)
  118. for match in matches:
  119. if match not in help_strings:
  120. help_strings.append(match)
  121. for s in ignored_strings:
  122. try:
  123. help_strings.remove(s)
  124. except ValueError:
  125. # ignore any that don't exist
  126. ...
  127. print("chanserv help strings:", len(help_strings))
  128. with open(os.path.join(arguments['<languages-dir>'], 'example', 'chanserv.lang.json'), 'w') as f:
  129. f.write(json.dumps({k:k for k in help_strings}, sort_keys=True, indent=2, separators=(',', ': ')))
  130. f.write('\n')
  131. for string in help_strings:
  132. if 1 < string.count('%s') + string.count('%d') + string.count('%f'):
  133. print(' confirm:', string)
  134. # hostserv help entries
  135. help_strings = []
  136. for subdir, dirs, files in os.walk(arguments['<irc-dir>']):
  137. for fname in files:
  138. filepath = subdir + os.sep + fname
  139. if fname == 'hostserv.go':
  140. content = open(filepath, 'r', encoding='UTF-8').read()
  141. matches = re.findall(r'\`([^\`]+)\`', content)
  142. for match in matches:
  143. if match not in help_strings:
  144. help_strings.append(match)
  145. for s in ignored_strings:
  146. try:
  147. help_strings.remove(s)
  148. except ValueError:
  149. # ignore any that don't exist
  150. ...
  151. print("hostserv help strings:", len(help_strings))
  152. with open(os.path.join(arguments['<languages-dir>'], 'example', 'hostserv.lang.json'), 'w') as f:
  153. f.write(json.dumps({k:k for k in help_strings}, sort_keys=True, indent=2, separators=(',', ': ')))
  154. f.write('\n')
  155. for string in help_strings:
  156. if 1 < string.count('%s') + string.count('%d') + string.count('%f'):
  157. print(' confirm:', string)