I am trying to translate domain-specific English (en-US) text to Chinese simplified (zh). I have created a glossary, however, it looks like CloudTranslate gives precedence to other translations over the glossary.
For example, the word “fabric” has many translations to Chinese, so the glossary has an entry “the fabric,交换网”, but the API returns “面料”, which is the same translation as I get from Google Translate website.
Question 1: Since I didn’t get any error, is it true to assume that the glossary was found and used?
Question 2: I expected that the glossary will get strict precedence over other translations. Is there a way to force it?
When you have created your glossary, you should now then call glossary_translation instead of translation so that glossaries will override the results for the terms used in the model.
You may refer to this documentation https://cloud.google.com/translate/docs/advanced/glossary#use_glossaries
Thanks, this is the same reference that I used. As I understand it is the same function as translating without a glossary, but I need to populate the “glossary_config” in the request.
Did I miss anything?
This is my code:
def my_translate(self, text):
response = self.client.translate_text(
request={
"parent": self.parent,
"contents": [text],
"mime_type": "text/plain", # mime types: text/plain, text/html
"source_language_code": self.source_language,
"target_language_code": self.target_language,
"glossary_config": self.glossary_config,
}
)
# Display the translation for each input text provided
translated_text = ""
for translation in response.translations:
translated_text += translation.translated_text
return translated_text
I also tried to provide a non-valid glossary and received an exception, which means that the “glossary_config” is not ignored.