I tried, but Response Status is 400 on website, so there is error, but console dont say.. PHP: function translate1($from_lan, $to_lan, $text){ $json = json_decode(file_get_contents('http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=' . urlencode($text) . '&langpair=' . $from_lan . '|' . $to_lan)); $translated_text = $json->responseData->translatedText; return $translated_text;}public function onChat11(PlayerChatEvent $e){ $e->getPlayer()->sendMessage($this->translate1("en", "cz", "Hello"));}
It produces the following error, which I think that is fairly self-explanatory. Code: { "responseData": null, "responseDetails": "Please use Translate v2. See http://code.google.com/apis/language/translate/overview.html", "responseStatus": 403 }
try something like this? PHP: public function translate(string $text, string $to_lang = "en"){ $json = json_decode(file_get_contents('https://translation.googleapis.com/language/translate/v2?key=YOUR_LICENSE_KEY_HERE&q=' . urlencode($text) . '&target=' . $to_lang . '&format=text')); $translated_text = $json->data->translations[0]->translatedText; return $translated_text;}
Google's translation API is no longer free... the only API that actually works for free right now is Bing, which allows you to translate 2 million characters (not words) before you need a paid subscription.