I need to translate a part of my wordpress site content using google translate, For example,
$text="translate this content"
to
$translated_text="traduci questo contenuto"
I do not need to find the browser language, etc,. Just direct translation I need. Tried this, seems like it is deprecated. Got it from another question answered here.
function translate($from_lan, $to_lan, $text){
$json = json_decode(file_get_contents('https://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;
}
I don't mind paying for the google API, I need to know how to handle the translation in php code.