javascript - Translation failed TypeError: google_translate_api_x__WEBPACK_IMPORTED_MODULE_0__ is not a function - Stack Overflo

I attempted to run this code for my translation web app created from react:import translate from '

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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信