Difficulty Applying Glossaries to Translations in Translation AI

Dear Google Cloud Support,

I’m reaching out regarding an issue I’ve encountered with the Translation AI service. Specifically, I’m experiencing difficulty when attempting to apply glossaries to my translations.

Below is the code I’ve been using to make the translation request:

const { TranslationServiceClient } = require('@google-cloud/translate')
const translationClient = new TranslationServiceClient()
const text = 'Use the cabinet'

async function translateText () {
const glossaryConfig = {
glossary: 'projects/burnished-craft-395319/locations/us-central1/glossaries/my-en-to-it-glossary',
}
const request = {
parent: `projects/burnished-craft-395319/locations/us-central1`,
contents: [text],
mimeType: 'text/plain', // mime types: text/plain, text/html
sourceLanguageCode: 'en',
targetLanguageCode: 'it',
glossaryConfig: glossaryConfig,
}

// Run request
const [response] = await translationClient.translateText(request)

for (const translation of response.translations) {
console.log(`Translation: ${translation.translatedText}`)
}
}

translateText()

When using the above code, the translation I get back for the text “Use the cabinet” is “Usa l’armadietto”, but based on my glossary, I expected it to return “Usa il cabinato”.

I’d like to mention that I’ve already come across a support post (Link here), which essentially advised to read the documentation. However, I didn’t find the solution to my problem there.

Furthermore, I’ve observed that when I deliberately modify the glossary string, it produces an error. This indicates to me that the glossary is being loaded correctly, but either it’s not being applied or I’m misunderstanding what the glossary’s role should be in this process.

While I can successfully retrieve the list of terms from the glossary by calling the API, as shown below:

{
  "glossaryEntries": [
    {
      "name": "projects/911989802358/locations/us-central1/glossaries/my-en-to-it-glossary/glossaryEntries/2074252526884577479",
      "termsPair": {
        "sourceTerm": {
          "languageCode": "en",
          "text": "cabinet"
        },
        "targetTerm": {
          "languageCode": "it",
          "text": "cabinato"
        }
      }
    },
    {
      "name": "projects/911989802358/locations/us-central1/glossaries/my-en-to-it-glossary/glossaryEntries/2074252526884579120",
      "termsPair": {
        "sourceTerm": {
          "languageCode": "en",
          "text": "console"
        },
        "targetTerm": {
          "languageCode": "it",
          "text": "consòle"
        }
      }
    },
    {
      "name": "projects/911989802358/locations/us-central1/glossaries/my-en-to-it-glossary/glossaryEntries/2074252526884580761",
      "termsPair": {
        "sourceTerm": {
          "languageCode": "en",
          "text": "referees"
        },
        "targetTerm": {
          "languageCode": "it",
          "text": "àrbitri"
        }
      }
    }
  ]
}

Any guidance or clarification on how to properly use and apply the glossaries would be immensely appreciated.

Thank you for your time and consideration.

Warm regards,

Marco Dal Borgo

Hi @dalborgo ,

Thank you for reaching out to the community for your concern.

I understand that you are having challenges applying glossaries with your translations and I want to assist you by providing resources that you can use as guidance.

Let’s first understand the things to consider in setting up your translation for us not to miss anything. The translation has 2 available editions, the basics and your use case will fall under the advanced category wherein we can use glossaries when translating.

You can also review the Cloud Translation - Advanced details for more information.

Hope this helps.