I have been exploring the Azure cognitive services of text translator to translate text from one origin to the other. In my case I want to translate Japanese text into English.
I have followed the documentation and utilized the python code to achieve the above task. However I received an error while getting the response from the API.
Error code:400003
Message: One of the language specified is not valid.
Didn't find much help on the error code. Attaching the code for reference. Any suggestions/workarounds will be helpful.
import os, requests, uuid, json
key_var_name =subscription_key
endpoint_var_name =endpoint_details_of_API
path = '/transliterate?api-version=3.0'
params = '&to=en'
constructed_url = endpoint_var_name + path + params
headers = {
'Ocp-Apim-Subscription-Key':subscription_key',
'Content-type': 'application/json',
'Ocp-Apim-Subscription-Region': 'eastasia',
'X-ClientTraceId': str(uuid.uuid4())
}
body =[{
'text': 'こんにちは'
}]
request=requests.post(constructed_url,headers=headers,json=body)
response=request.json()
print(response)
There is a difference in translation and transliteration, and also in the way you call the respective APIs.
Since you are using the Transliteration API, you need to specify the script you would like to transliterate to/from.
ja
Jpan
en
Latn
More info: Language and region support for Translator .
Constructing the URL of the API in python should look something like this:
path = '/transliterate?api-version=3.0'
params = '&language=ja&fromScript=jpan&toScript=latn'
constructed_url = endpoint_var_name + path + params
More info on this can be found in the Quickstart: Use the translator to transliterate text .
For more info on the Transliterate API, see the Translator 3.0: Transliterate documentation. This shows that the parameters api-version
, language
, fromScript
and toScript
are all required.
EDIT:
I just tested translating ( not transliterating) from Japanese to English, and that works. At least, if this:こんにちは
means Hello, it does. Transliterating might not be necessary.
私はこれが役立つことを願っています。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.