Google Translation V3 API-术语表资源错误



创建了词汇表资源--步骤1(在GCS中保存一份词汇表csv表。步骤2(request.json如下-

{
"name":"projects/my-project-id/locations/us-central1/glossaries/my-glossary-id",
"languagePair": {
"sourceLanguageCode": "en",
"targetLanguageCode": "ru"
},
"inputConfig": {
"gcsSource": {
"inputUri": "gs://my-bucket-id/my-glossary-id.csv"
}
}
}

步骤3(卷曲-X POST-H〃;授权:Bearer"$(gcloud auth应用程序默认打印访问令牌(-H";内容类型:application/json;charset=utf-8"-d@request.jsonhttps://translation.googleapis.com/v3/projects/my-project-id/locations/us-central1/glossaries

收到以下回复-

{
"name": "projects/my-project-id/locations/us-central1/operations/20210322-02431616406238-605596c9-0000-21a9-91e6-94eb2c045d66",
"metadata": {
"@type": "type.googleapis.com/google.cloud.translation.v3.CreateGlossaryMetadata",
"name": "projects/my-project-id/locations/us-central1/glossaries/my-glossary-id",
"state": "RUNNING",
"submitTime": "2021-03-22T09:43:58.973617420Z"
}
}

但当我想列出词汇表时,它会返回一个空白:-

curl-X GET-H";授权:Bearer"$(gcloud auth应用程序默认打印访问令牌(https://translation.googleapis.com/v3/projects/my-project-id/locations/us-central1/glossaries

响应如下-{}

此外,当我使用这个词汇表翻译我的文本时,它会出现以下错误-

{
"error": {
"code": 404,
"message": "Glossary not found.; Failed to initialize a glossary.",
"status": "NOT_FOUND"
}
}

一些需要验证的东西:

  • 检查您的bucket是否仅在uscentral-1中。它不可能是多区域或其他任何东西它必须是uscentral-1。https://cloud.google.com/translate/docs/migrate-to-v3#resources_projects_and_locations:~:text=对于%20all%20custom%20resources%E2%80%94AutoML%20models%2C%20glossary%2C%20%long%2Runing%2Operations%E2%80%94you%2must%20use%20us%2central1
  • 发送创建资源的请求后,是否可以尝试轮询长期运行的请求以确保它已完成
  • 请尝试删除词汇表资源,然后重试
  • 你能仔细检查一下你的词汇表csv文件名为my-glossary-id.csv

我写了一个演练,并用示例代码制作了一个repo,如果你觉得这也有帮助的话:

https://medium.com/@swekage/the-ultimate-guide-to-setting-up-google-translates-glossaries-in-javascript-d9cdff41d9ed

https://github.com/swekage/google-translate-glossary

最新更新