I attempted to run this code for my translation web app created from react:
import translate from 'google-translate-api-x';
export async function translateText(text, sourceLang, targetLang) {
try {
const response = await translate(`${text}`, {
from: `${sourceLang}`,
to: `${targetLang}`,
autoCorrect: true
});
// Extract the translated text from the response
return response.text;
} catch (error) {
console.error("Error during translation:", error);
throw error;
}
}
It keeps giving me the error:
Translation failed TypeError: google_translate_api_x__WEBPACK_IMPORTED_MODULE_0__ is not a function
I read the API README and copied the way that they have used the function and didn't get the same result. I think this problem may lie in
export async function
I am a JavaScript/React beginner so I do not have much knowledge on how to solve the issue.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742421505a4440774.html
评论列表(0条)