-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
translator.py
39 lines (32 loc) · 1.01 KB
/
translator.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
'''Functions to translate from English to French and German'''
from ibm_watson import LanguageTranslatorV3
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
import os
from dotenv import load_dotenv
load_dotenv()
API_KEY = os.getenv('API_KEY')
URL= os.getenv('URL')
authenticator = IAMAuthenticator(API_KEY)
language_translator = LanguageTranslatorV3(
version='2018-05-01',
authenticator=authenticator
)
language_translator.set_service_url(URL)
def englishtofrench(english):
'''
Translate English to French
'''
translation = language_translator.translate(
text=english,
model_id='en-fr').get_result()
french_translation = translation['translations'][0]['translation']
return french_translation
def englishtogerman(english):
'''
Translates English to German
'''
translation = language_translator.translate(
text=english,
model_id='en-de').get_result()
german_translation = translation['translations'][0]['translation']
return german_translation