Translation with glossary

641 views
Skip to first unread message

Deepa Dharmit Shah

unread,
Mar 19, 2021, 5:48:34 AM3/19/21
to Google Cloud Translation API
I want to use Translation v3 API in  Cloud workflows. 
Below is what Ive put in the workflow code.   First (createGlossaryResource) is creating the glossary resource and second (translateCall) is translating text using that glossary.  
On executing the cloud workflow - I am getting a  400 error for the second one i.e for  translateCall
Could someone please help. Thanks.


- createGlossaryResource:
        call: http.post
        args:
          headers:
            Content-Type: application/json
          auth:
            type: OAuth2
          body: 
            name: "projects/a/locations/us-central1/glossaries/check-glossary-id"
            languagePair: {
              sourceLanguageCode: "en-US",
              targetLanguageCode: "zh-TW"
            }
            inputConfig: {
              gcsSource: {
                inputUri: "gs://mybucketid/check-glossary-id.csv"
              }
            }
        result: glossResCreated
    
    - translateCall:
        call: http.post
        args:
          headers:
            Content-Type: application/json          
          auth:
            type: OAuth2
          body:
            contents: "Please translate the subtitle"
            sourceLanguageCode: "en-US"
            targetLanguageCode: "zh-TW"
            glossaryConfig: 
              glossary: "projects/a/locations/us-central1/glossaries/check-glossary-id"
            
        result: translationResponse

Music Li

unread,
Mar 19, 2021, 12:21:17 PM3/19/21
to Google Cloud Translation API
I believe 400 is an invalid argument error. What is the error message you got from the response?

Deepa Dharmit Shah

unread,
Mar 19, 2021, 1:24:22 PM3/19/21
to Google Cloud Translation API
That is the problem. In 'Cloud Workflow' all it shows as 400 error and nothing more. Also, nothing comes in the Logs either.  

Music Li

unread,
Mar 19, 2021, 2:08:49 PM3/19/21
to Google Cloud Translation API
I'm not familiar with Cloud Workflow and there might be some issues. Could you please try with curl calls similar to examples here https://cloud.google.com/translate/docs/advanced/quickstart#translate_text_example to test it out?

Kevin

unread,
Mar 22, 2021, 5:11:48 AM3/22/21
to Google Cloud Translation API
Hi,
I agree that you should try with a direct call to the Translation API (curl o libraries) in order to confirm if this issue is more related to the Translation API or to Cloud Workflow.

In any case, please remind that Google Groups are reserved for general product discussion, StackOverflow for technical questions whereas Issue Tracker for product issues (unexpected behaviors) and feature requests, see [1].

Therefore, as you are getting a 400 error message (which means a bad request), your issue could be related to a misconfiguration somewhere in your code, so I suggest that you post a question on Stackoverflow, sharing the related parts of your code/configuration (without any sensitive identifiable information).
On the other hand, if you believe that your config/code is correct and this is an unexpected behavior from one of our of these APIs, you can create an issue report on issue-tracker [2], also sharing the related parts of your code/configuration (without any sensitive identifiable information).

Deepa Dharmit Shah

unread,
Mar 22, 2021, 11:28:37 AM3/22/21
to Google Cloud Translation API
Request for help.

I did the steps in the following link (https://cloud.google.com/translate/docs/advanced/glossary)  on  a compute engine VM  

Step 1) So i created my glossary resource and got success. 

curl -X POST -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) -H "Content-Type: application/json; charset=utf-8" -d @request.json https://translation.googleapis.com/v3/projects/temp-279813/locations/us-central1/glossaries
{
"name": "projects/my-project-number/locations/us-central1/operations/20210322-00291616398144-60500080-0000-2ec8-8d87-001a114eb362", "metadata": 
          "name": "projects/ my-project-number/locations/us-central1/glossaries/my-glossary-id", 
          "state": "RUNNING", 
          "submitTime": "2021-03-22T07:29:04.336303930Z" 
        }
}

Then i wanted to use the glossary to translate my text ---  so i did the Step 2 Scenario 1  which gave error   and then  i tried Step 2 Scenario 2  which also gave error. Details below - 

Step 2) request1.json
 "sourceLanguageCode": "en", 
 "targetLanguageCode": "zh", 
 "contents": "Please translate this. Subtitle.", 
 "glossaryConfig": 
         { "glossary": "projects/my-project-id/locations/us-central1/glossaries/my-glossary-id" }
}


Scenario 1 
curl -X POST -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) -H "Content-Type: application/json; charset=utf-8" -d @request1.json https://translation.googleapis.com/v3/projects/my-project-id/locations/us-central1:translateText

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


Scenario 2 
curl -X POST -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) -H "Content-Type: application/json; charset=utf-8" -d @request1.json https://translation.googleapis.com/v3/projects/my-project-id:translateText

{ "error": { "code": 400, "message": "Locations in model 'global' and in glossary 'us-central1' do not match.", "status": "INVALID_ARGUMENT" }}

Junpei Zhou

unread,
Mar 22, 2021, 1:56:39 PM3/22/21
to Google Cloud Translation API
Hi,

It seems like that the glossary creation is not successful. Could you use ListGlossaries or GetGlossary API to check if your glossary (projects/ my-project-number/locations/us-central1/glossaries/my-glossary-id) exists?

Deepa Dharmit Shah

unread,
Mar 22, 2021, 2:00:21 PM3/22/21
to Google Cloud Translation API
Hello : Thanks. I tried curl and also via python client library. The glossary resource is created and i can see the glossary resource in  Activity and also via curl GET.  
But, on  trying to translate the text using that glossary  via python client library code - I  still get the following error  "  404 Glossary not found.; Failed to initialize a glossary."
I have raised this in stackoverflow .
Thanks

Junpei Zhou

unread,
Mar 22, 2021, 2:41:34 PM3/22/21
to Google Cloud Translation API
For that operation name you provided: "projects/my-project-number/locations/us-central1/operations/20210322-00291616398144-60500080-0000-2ec8-8d87-001a114eb362", the Glossary Creation Failed because of failure to parse the CSV file. Could you please make sure the CSV file format is correct and doesn't have any header?

Deepa Dharmit Shah

unread,
Mar 23, 2021, 5:11:10 AM3/23/21
to Google Cloud Translation API
Thank you. I worked it out using the python client library. Created the glossary resource and used it while translation call. 
Also, from the way it worked for me - header is needed in the glossary csv sheet. 
Reply all
Reply to author
Forward
0 new messages