Thank you @VasaviLankipalle-MSFT
Please find below an example translation from Japanese to English in my python script (I've omitted my key but can provide this if required privately) -
import requests
def translate_text_external(text, show_status = True):
# Set your Azure subscription key and endpoint
subscription_key = "(removed)"
endpoint = "https://api.cognitive.microsofttranslator.com/"
path = '/translate'
constructed_url = endpoint + path
# Add your text to translate here
body = [{'text': text}]
# Set the translation parameters
params = {
'api-version': '3.0',
'from': 'ja',
'to': 'en'
}
headers = {
'Ocp-Apim-Subscription-Key': subscription_key,
'Ocp-Apim-Subscription-Region' : 'eastus',
'Content-type': 'application/json'
}
# Make the API request
request = requests.post(constructed_url, params=params, headers=headers, json=body)
# Check for errors
if request.status_code != 200:
print("Error with request:")
print(request.json())
return None
response = request.json()
# Extract the translated text
try:
translated_text = response[0]['translations'][0]['text']
if show_status:
print(f"translated: {translated_text}")
return translated_text
except KeyError:
print("Unexpected response format:")
print(response)
return None
translate_text_external("あなたをファック")
The translation is only returning "You" for example, whereas in the Bing translator at https://www.bing.com/translator the proper sentence is being returned without omissions.