forked from ergochat/ergo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
updatetranslations.py
executable file
·195 lines (157 loc) · 7.25 KB
/
updatetranslations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/env python3
# updatetranslations.py
#
# tl;dr this script updates our translation file with the newest, coolest strings we've added!
# it manually searches the source code, extracts strings and then updates the language files.
# Written in 2018 by Daniel Oaks <[email protected]>
#
# To the extent possible under law, the author(s) have dedicated all copyright
# and related and neighboring rights to this software to the public domain
# worldwide. This software is distributed without any warranty.
#
# You should have received a copy of the CC0 Public Domain Dedication along
# with this software. If not, see
# <http://creativecommons.org/publicdomain/zero/1.0/>.
"""updatetranslations.py
Usage:
updatetranslations.py run <irc-dir> <languages-dir>
updatetranslations.py --version
updatetranslations.py (-h | --help)
Options:
<irc-dir> Oragono's irc subdirectory where the Go code is kept.
<languages-dir> Languages directory."""
import os
import re
import json
from docopt import docopt
import yaml
ignored_strings = [
'none', 'saset'
]
if __name__ == '__main__':
arguments = docopt(__doc__, version="0.1.0")
if arguments['run']:
# general IRC strings
irc_strings = []
for subdir, dirs, files in os.walk(arguments['<irc-dir>']):
for fname in files:
filepath = subdir + os.sep + fname
if filepath.endswith('.go'):
content = open(filepath, 'r', encoding='UTF-8').read()
matches = re.findall(r'\.t\("((?:[^"]|\\")+)"\)', content)
for match in matches:
if match not in irc_strings:
irc_strings.append(match)
matches = re.findall(r'\.t\(\`([^\`]+)\`\)', content)
for match in matches:
if match not in irc_strings:
irc_strings.append(match)
for s in ignored_strings:
try:
irc_strings.remove(s)
except ValueError:
# ignore any that don't exist
...
print("irc strings:", len(irc_strings))
with open(os.path.join(arguments['<languages-dir>'], 'example', 'irc.lang.json'), 'w') as f:
f.write(json.dumps({k:k for k in irc_strings}, sort_keys=True, indent=2, separators=(',', ': ')))
f.write('\n')
for string in irc_strings:
if 1 < string.count('%s') + string.count('%d') + string.count('%f'):
print(' confirm:', string)
# help entries
help_strings = []
for subdir, dirs, files in os.walk(arguments['<irc-dir>']):
for fname in files:
filepath = subdir + os.sep + fname
if fname == 'help.go':
content = open(filepath, 'r', encoding='UTF-8').read()
matches = re.findall(r'\`([^\`]+)\`', content)
for match in matches:
if '\n' in match and match not in help_strings:
help_strings.append(match)
for s in ignored_strings:
try:
help_strings.remove(s)
except ValueError:
# ignore any that don't exist
...
print("help strings:", len(help_strings))
with open(os.path.join(arguments['<languages-dir>'], 'example', 'help.lang.json'), 'w') as f:
f.write(json.dumps({k:k for k in help_strings}, sort_keys=True, indent=2, separators=(',', ': ')))
f.write('\n')
for string in help_strings:
if 1 < string.count('%s') + string.count('%d') + string.count('%f'):
print(' confirm:', string.split('\n')[0])
# nickserv help entries
help_strings = []
for subdir, dirs, files in os.walk(arguments['<irc-dir>']):
for fname in files:
filepath = subdir + os.sep + fname
if fname == 'nickserv.go':
content = open(filepath, 'r', encoding='UTF-8').read()
matches = re.findall(r'\`([^\`]+)\`', content)
for match in matches:
if match not in help_strings:
help_strings.append(match)
for s in ignored_strings:
try:
help_strings.remove(s)
except ValueError:
# ignore any that don't exist
...
print("nickserv help strings:", len(help_strings))
with open(os.path.join(arguments['<languages-dir>'], 'example', 'nickserv.lang.json'), 'w') as f:
f.write(json.dumps({k:k for k in help_strings}, sort_keys=True, indent=2, separators=(',', ': ')))
f.write('\n')
for string in help_strings:
if 1 < string.count('%s') + string.count('%d') + string.count('%f'):
print(' confirm:', string)
# chanserv help entries
help_strings = []
for subdir, dirs, files in os.walk(arguments['<irc-dir>']):
for fname in files:
filepath = subdir + os.sep + fname
if fname == 'chanserv.go':
content = open(filepath, 'r', encoding='UTF-8').read()
matches = re.findall(r'\`([^\`]+)\`', content)
for match in matches:
if match not in help_strings:
help_strings.append(match)
for s in ignored_strings:
try:
help_strings.remove(s)
except ValueError:
# ignore any that don't exist
...
print("chanserv help strings:", len(help_strings))
with open(os.path.join(arguments['<languages-dir>'], 'example', 'chanserv.lang.json'), 'w') as f:
f.write(json.dumps({k:k for k in help_strings}, sort_keys=True, indent=2, separators=(',', ': ')))
f.write('\n')
for string in help_strings:
if 1 < string.count('%s') + string.count('%d') + string.count('%f'):
print(' confirm:', string)
# hostserv help entries
help_strings = []
for subdir, dirs, files in os.walk(arguments['<irc-dir>']):
for fname in files:
filepath = subdir + os.sep + fname
if fname == 'hostserv.go':
content = open(filepath, 'r', encoding='UTF-8').read()
matches = re.findall(r'\`([^\`]+)\`', content)
for match in matches:
if match not in help_strings:
help_strings.append(match)
for s in ignored_strings:
try:
help_strings.remove(s)
except ValueError:
# ignore any that don't exist
...
print("hostserv help strings:", len(help_strings))
with open(os.path.join(arguments['<languages-dir>'], 'example', 'hostserv.lang.json'), 'w') as f:
f.write(json.dumps({k:k for k in help_strings}, sort_keys=True, indent=2, separators=(',', ': ')))
f.write('\n')
for string in help_strings:
if 1 < string.count('%s') + string.count('%d') + string.count('%f'):
print(' confirm:', string)