-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_owners.py
41 lines (26 loc) · 1.1 KB
/
gen_owners.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
import sys
from google.cloud import translate_v3beta1 as translate
client = translate.TranslationServiceClient()
#export GOOGLE_APPLICATION_CREDENTIALS='/home/dijo/dev/learn/Enforcement/enforcement-c0db214466b6.json'
project_id = 'enforcement'
#text = u'62ನೇ ತೋಕೂರು ಗ್ರಾಮದ ಪಂಚಾಯತ್ ಅಭಿವೃದ್ದಿ ಅಧಿಕಾರಿ'
source_language_code = 'kn'
target_language_code = 'en'
location = 'global'
parent = client.location_path(project_id, location)
names = []
with open('own1.txt', encoding='utf8') as owner:
names = owner.read().split('\x01')
for name in names:
response = client.translate_text(
parent=parent,
contents=[name],
mime_type='text/plain',
source_language_code=source_language_code,
target_language_code=target_language_code )
for translation in enumerate(response.translations):
t = str(translation[1]).replace('\n', '').split('"')
print(name+'\x02'+t[1]+'\x01', end='')
#^A
#print(u'Text: {}'.format(text))
#print(u'Translation: {}'.format(translation['translatedText']))