I have an application where i am using google Tranlastion api. Now for the customization of some keywords I have created google glossary which is setup successfully. Now i am planning to use it in my application which has below code :-
string apikey = ConfigurationManager.AppSettings["GoogleTranslateApiKey"].ToString();
try
{
var client = TranslationClient.CreateFromApiKey(apikey);
var result = client.TranslateText(Text, TranslateTo, LanguageCodes.English);
List<string> lstData = new List<string>();
foreach (var item in result)
{
lstData.Add(item.TranslatedText);
}
response.KEY = "SUCCESS";
response.MESSAGE = JsonConvert.SerializeObject(lstData);
}
Now the issue is like where i have to involve my glossary configurations? below is my postman request details :-
Request URL:- https://translation.googleapis.com/v3/projects/mywebapp-translate/locations/us-central1:translateText
Request:-
{
"sourceLanguageCode": "en",
"targetLanguageCode": "hi",
"contents": "my language is hindi",
"glossaryConfig": {
"glossary": "projects/661824000002/locations/us-central1/glossaries/my-glossary",
"ignoreCase": "true"
}
}
Do I need to change my whole code or just including above configuration somewhere in my code will work? Can someone help
The glossary configuration is not directly supported in the TranslateText method. Instead, you need to use the
TranslateTextmethod with aTranslateTextRequestobject, which allows you to specify the glossary configuration.Here's a modified version of your code:
This modification uses the
TranslateTextRequestobject to set the glossary configuration. Make sure to adjust the error handling and further processing logic based on your application's requirements.