google api works!

This commit is contained in:
2026-03-16 10:32:11 +01:00
parent 72ac41cac0
commit 56a1495a0b
10 changed files with 46 additions and 72 deletions

View File

@@ -189,7 +189,8 @@ func (s *ProductDescriptionService) TranslateProductDescription(userID uint, pro
"translation_of_product_usage",
}
request := "Translate to " + lang.ISOCode + " without changing the html structure.\n"
// request := "Translate to " + lang.ISOCode + " without changing the html structure.\n"
request := ""
for i := 0; i < len(keys); i++ {
request += "\n<" + keys[i] + ">"
request += *fields[i]
@@ -204,7 +205,7 @@ func (s *ProductDescriptionService) TranslateProductDescription(userID uint, pro
req := &translatepb.TranslateTextRequest{
Parent: fmt.Sprintf("projects/%s/locations/global", s.projectID),
TargetLanguageCode: lang.ISOCode,
MimeType: "text/plain",
MimeType: "text/html",
Contents: []string{request},
}
responseGoogle, err := s.googleCli.TranslateText(s.ctx, req)
@@ -215,18 +216,16 @@ func (s *ProductDescriptionService) TranslateProductDescription(userID uint, pro
// TranslateText returns one Translation per input string.
if len(responseGoogle.GetTranslations()) == 0 {
return nil, responseErrors.ErrOpenAIBadOutput
return nil, responseErrors.ErrAIBadOutput
}
response := responseGoogle.GetTranslations()[0].GetTranslatedText()
for i := 0; i < len(keys); i++ {
success, resolution := resolveResponse(*fields[i], response, keys[i])
if !success {
return nil, responseErrors.ErrOpenAIBadOutput
return nil, responseErrors.ErrAIBadOutput
}
*fields[i] = resolution
fmt.Println("resolution: ", resolution)
}
return &ProductDescription, nil