Skip to content

Commit

Permalink
Fix google translator
Browse files Browse the repository at this point in the history
  • Loading branch information
xwjdsh committed Jun 9, 2021
1 parent fb8a02f commit 6fae1ff
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion google.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ func (g *googleTranslator) translate(ctx context.Context, req Request) (resp *Re
resp.Err = fmt.Errorf("sendRequest error: %v", err)
return
}

resp.Result, resp.Err = g.getResult(string(data))
return
}

func (g *googleTranslator) getResult(dataStr string) (string, error) {
result := regexp.MustCompile(`(?U),null,null,null,\[\[\\"(?P<result>\S+)\\",\[\\"`).FindStringSubmatch(dataStr)
result := regexp.MustCompile(`(?U),\[\[\\"(?P<result>\S+)\\",\[\\"`).FindStringSubmatch(dataStr)
if len(result) != 2 {
return "", fmt.Errorf("cannot get result")
}
Expand Down

0 comments on commit 6fae1ff

Please sign in to comment.