-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtranslate.py
34 lines (29 loc) · 853 Bytes
/
translate.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
#dictionary Translater
import goslate
from goslate import WRITING_NATIVE_AND_ROMAN, WRITING_ROMAN, WRITING_NATIVE
class Translator:
def __init__(self, language):
self.gs = goslate.Goslate(WRITING_ROMAN,timeout = 8)
self.language = language
def translate(self, text):
#First split dictionary into words
text = text.split('\n')
#Now we build text into set size chunks
chunks = []
tempChunk =""
for i in text:
#print i
if len(tempChunk) > 20000:
chunks.append(tempChunk)
tempChunk = i + '\n'
continue
else:
tempChunk += i + '\n'
translation = ""
print "[-] Translating dictionary to {0}...".format(self.language)
count = 0
for i in chunks:
count += 1
print "[-] Translating part {0} of {1}".format(count,len(chunks))
translation += self.gs.translate(i, self.language)
return translation