.js 代码返回与“请求”相关的错误 [关闭]

问题描述 投票:0回答:0

我创建了一个 .js 程序,用于将 .docx 文件从源语言翻译成目标语言的 .docx 文件,这两个文件都位于 Google Storage(我存储桶的子目录)中。在解决了代码的其他问题后,当我运行它时,我收到以下错误消息:

(node:4896) UnhandledPromiseRejectionWarning: Error: 3 INVALID_ARGUMENT:
   Target language code is required.

因为在到达代码的“请求”部分之前,我已经在正确设置的 const 中指定了源语言和目标语言,所以我怀疑我形成请求的方式和/或其与调用 use 的关系一定有问题的词汇表。这是我这部分代码的相关代码片段:

// Set the glossary config for the `enter code here`translation request
const glossaryConfig = {
    glossary: {
      languageCodesSet: {
        languageCodes: [sourceLanguage, targetLanguage],
      },
      inputConfig: {
        gcsSource: {
          inputUri: `gs://${bucketName}/${glossaryFileName}`,
        },
      },
    },
};

// Construct request
const request = {
  parent: `projects/${projectId}/locations/${location}`,
  sourceLanguageCode: 'ar',
  targetLanguageCode: 'en',
  inputConfigs: [inputConfig],
  outputConfig: outputConfig,
}; 

我在这里出错的任何想法以及如何修复我的代码?问候

javascript node.js translation
© www.soinside.com 2019 - 2024. All rights reserved.