Google translate go api giving an error: "language: tag is not well-formed"

Written by
Link to Post by 

Has anyone ever encountered this error? I am able to set up the client using my API key it doesn’t give me any error but when I try to translate some text this error is what I get

This is my method

func (c *googleTranslateClient) TranslateText(targetLang string, sourceText string) (string, error) { ctx := context.Background() lang, err := language.Parse(targetLang) fmt.Println(lang, err) if err != nil { return "", err } resp, err := c.translate.Translate(ctx, []string{sourceText}, lang, nil) if err != nil { return "", err } return resp[0].Text, nil } 

This is my function call jaText, err := h.service.GoogleTranslate.TranslateText("apple", "ja")

submitted by /u/fenster25
[link] [comments]

Article Tags:
· ·
Article Categories:

Leave a Reply