-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranslate.py
More file actions
29 lines (21 loc) · 841 Bytes
/
translate.py
File metadata and controls
29 lines (21 loc) · 841 Bytes
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
import sys
def translate_line(line):
found = line.find('qq{')
while found >= 0:
closing = line.find('},', found)
to_replace = line[found+3:closing]
replaced = '\'%s\'' % to_replace.replace('\'', '\\\'')
line = line[:found] + replaced + line[closing+1:]
found = line.find('qq{')
return line
for filename in sys.argv[1:]:
output_filename = filename[:-2] + 'py'
print 'processing: %s' % filename
with open(filename, 'r') as perl_input:
to_translate = perl_input.readlines()[2:-2]
translations = [translate_line(line) for line in to_translate]
checked = eval('[' + ''.join(translations) + ']')
print 'Found %s translations' % len(checked)
content = ['page = [\n'] + translations + ['\n]\n']
with open(output_filename, 'w') as python_output:
python_output.writelines(content)