Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid value (400) using google translate api

What's wrong with my request?

I have sting in russian: $string = Потенциал, %

I want to translate it to ukrainian with google API:

I urlencode string:

$q = urlencode($string)

And i request google API:

https://www.googleapis.com/language/translate/v2?q=%D0%9F%D0%BE%D1%82%D0%B5%D0%BD%D1%86%D0%B8%D0%B0%D0%BB%2C%20%25&target=ua&source=ru&key=A...

In response I get :

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "invalid",
    "message": "Invalid Value"
   }
  ],
  "code": 400,
  "message": "Invalid Value"
 }
}

What's wrong with my request?

like image 337
Prosto Trader Avatar asked Dec 11 '22 01:12

Prosto Trader


2 Answers

Solution was simple. Google has UK letters for ukrainian instead of UA.

like image 138
Prosto Trader Avatar answered Jan 11 '23 01:01

Prosto Trader


The target should be uk not ua.I think it will resolve the issue.

like image 22
Shobhit Avatar answered Jan 11 '23 02:01

Shobhit