-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtranslate.py
25 lines (22 loc) · 926 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
from google.cloud import translate_v2 as translator
import six
translator = translator.Client()
new1 = open('new1.txt', encoding="utf8").read().split('\n')
new2 = open('new2.txt', encoding="utf8").read().split('\n')
new3 = open('new3.txt', encoding="utf8").read().split('\n')
new4 = open('new4.txt', encoding="utf8").read().split('\n')
new5 = open('new5.txt', encoding="utf8").read().split('\n')
new6 = open('new6.txt', encoding="utf8").read().split('\n')
new = [new1, new2, new3, new4, new5, new6]
def translate(files):
text = []
for word in files:
translation = translator.translate(word, source_language='zh-CN', target_language='en')
print(translation)
a = translation['input'] + "," + translation['translatedText']
text.append(a)
return text
file = translate(new[4])
with open(f'trans{5}.txt', 'w',encoding='utf8') as f:
for item in file:
f.write("%s\n" % item)