Skip to content

Instantly share code, notes, and snippets.



Created May 21, 2020
What would you like to do?
Translate text with google api for free
Upload this file to your php app and run like this:
OR with translating parameters http://localhost/translate-text-google-api-free.php?tl=ru
Also there is limit with 5000 simbols, and the google api can ban your ip if you will abise to much.
$language_from = 'en';
$text_to_translate = "Building in Algiros area, the property has a built area of 434M2 &amp; plot area of 718 m2 in Valencia city. Year of construction 1998.
Currently the use is of a social-cultural, educational building on an urban plot without horizontal division.
<strong>The property has a ground floor, plus one additional floor.</strong>
Do not hesitate to contact us for further information.
<h3>THE AREA:</h3>
The property, located in one of the youngest and most active areas of the city, the district of Algirós, stands out for being a few minutes away from the beaches of La Malvarrosa, Las Arenas and La Patacona. Similarly, it can be said that services such as supermarkets, pharmacies, health centres, petrol stations and so many others are diverse and easily accessible. It has wide avenues and streets that give access to several parts of the city, as well as to other cities. The most outstanding educational centres are located in this area, as well as the universities of Valencia and the Polytechnic. In addition, the area has a wide variety of commercial establishments with an exquisite gastronomic offer.
if (isset($_GET['tl']) and !empty($_GET['tl'])) {
$language_to = $_GET['tl'];
$encoded_text = urlencode(strip_tags($text_to_translate));
$url = '' . $language_from . '&tl=' . $language_to . '&dt=t&q=' . $encoded_text;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
curl_setopt($ch, CURLOPT_USERAGENT, 'AndroidTranslate/5.3.0.RC02.130475354-53000263 5.1 phone TRANSLATE_OPM5_TEST_1');
$output = curl_exec($ch);
$response_a = json_decode($output);
echo '<hr><h2>Translated</h2>';
foreach ($response_a[0] as $text_block) {
echo '<p>' . $text_block[0] . '</p>';
echo '<hr><h2>Original</h2>';
foreach ($response_a[0] as $text_block) {
echo '<p>' . $text_block[1] . '</p>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment