import os
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-08-16',
    authenticator=authenticator
)

language_translator.set_service_url(url)

def english_to_french(english_text):
    """
    Translate text from English to French
    """
    if english_text == '':
        return ''
    translation = language_translator.translate(
        text = english_text,
        model_id='en-fr').get_result()
    return translation.get('translations')[0].get('translation')

def french_to_english(french_text):
    """
    Translate text from French to English
    """
    if french_text == '':
        return ''
    translation = language_translator.translate(
        text = french_text,
        model_id = 'fr-en').get_result()
    return translation.get('translations')[0].get('translation')

import os
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-08-16',
    authenticator=authenticator
)

language_translator.set_service_url(url)

def english_to_french(english_text):
    """
    Translate text from English to French
    """
    if english_text == '':
        return ''
    translation = language_translator.translate(
        text = english_text,
        model_id='en-fr').get_result()
    return translation.get('translations')[0].get('translation')

def french_to_english(french_text):
    """
    Translate text from French to English
    """
    if french_text == '':
        return ''
    translation = language_translator.translate(
        text = french_text,
        model_id = 'fr-en').get_result()
    return translation.get('translations')[0].get('translation')

Translate text from English to French Translate text from French to English