"""Translator.py by <NAME> 2021."""

import os
import json
from ibm_watson import LanguageTranslatorV3
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
from dotenv import load_dotenv

load_dotenv()

apikey = os.environ['apikey']
url = os.environ['url']

authenticator = IAMAuthenticator(apikey)
language_translator = LanguageTranslatorV3(
    version='2021-11-23',
    authenticator=authenticator
)

language_translator.set_service_url('https://api.eu-gb.language-translator.watson.cloud.ibm.com')

def englishToFrench(EnglishText):
    """Translate english to french."""
    translation = language_translator.translate(
    text=EnglishText,
    model_id='en-fr').get_result()
    jsonStr = json.dumps(translation, indent=2, ensure_ascii=False)
    data = json.loads(jsonStr)

    for i in data['translations']:
        return i['translation']

def frenchToEnglish(FrenchText):
    """Translate french to english."""
    translation = language_translator.translate(
    text=FrenchText,
    model_id='fr-en').get_result()
    jsonStr = json.dumps(translation, indent=2, ensure_ascii=False)
    data = json.loads(jsonStr)

    for i in data['translations']:
        return i['translation']

"""Translator.py by <NAME> 2021."""

import os
import json
from ibm_watson import LanguageTranslatorV3
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
from dotenv import load_dotenv

load_dotenv()

apikey = os.environ['apikey']
url = os.environ['url']

authenticator = IAMAuthenticator(apikey)
language_translator = LanguageTranslatorV3(
    version='2021-11-23',
    authenticator=authenticator
)

language_translator.set_service_url('https://api.eu-gb.language-translator.watson.cloud.ibm.com')

def englishToFrench(EnglishText):
    """Translate english to french."""
    translation = language_translator.translate(
    text=EnglishText,
    model_id='en-fr').get_result()
    jsonStr = json.dumps(translation, indent=2, ensure_ascii=False)
    data = json.loads(jsonStr)

    for i in data['translations']:
        return i['translation']

def frenchToEnglish(FrenchText):
    """Translate french to english."""
    translation = language_translator.translate(
    text=FrenchText,
    model_id='fr-en').get_result()
    jsonStr = json.dumps(translation, indent=2, ensure_ascii=False)
    data = json.loads(jsonStr)

    for i in data['translations']:
        return i['translation']

Translator.py by <NAME> 2021. Translate english to french. Translate french to english.