const handleTranslation = async () => {
const encodedParams = new URLSearchParams();
encodedParams.set(“source_language”, “en”);
encodedParams.set(“target_language”, selectedLanguage);
encodedParams.set(“text”, initialSummary);
const options = {
method: "POST",
url: "https://text-translator2.p.rapidapi.com/translate",
headers: {
"content-type": "application/x-www-form-urlencoded",
"X-RapidAPI-Key": "apikey",
"X-RapidAPI-Host": "text-translator2.p.rapidapi.com",
},
data: encodedParams,
};
console.log("Translating summary...");
console.log("Translation options:", options);
console.log(initialSummary)
console.log(selectedLanguage)
try {
const response = await axios.request(options);
const translatedText = response.data.translatedText;
setTranslatedSummary(translatedText);
} catch (error) {
console.error("Error translating summary:", error);
console.log("Error response:", error.response);
setTranslatedSummary("Error occurred while translating the summary.");
}
};
This function take summary and then returns translated summary. I am getting error 400 bad req.
The way of passing inputs is correct but there is some issue still?
Please help me with it
Join in the discussion - add comment below:
Usage/Examples