google api works!
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user