Jan
Google Translate API – GTranslate PHP Library
Just finished a PHP Library that implements Google Translate API.
How it works ?
The Library allows you to translate any phrase from one original language to another.
Usage
GTranslate library allows you to translate any language to another, the usage is fairly simple.
How to
You can call the translation with any country you want, altough there are an available list of translatable coutries, on the languages.ini file. You can tanslate using the abreviation of the country or the full name.
$gt->english_to_german(“Hello”);
or
$gt->en_to_de(“Hello”);
Wil give you the same result.
Download
You can download the GTranslate PHP library at Google Code Page
http://code.google.com/p/gtranslate-api-php/
Example
require("GTranslate.php"); try{ $gt = new Gtranslate; echo "Translating [Hello World] from English to German =>".$gt->english_to_german("hello world").""; echo "Translating [Ciao mondo] Italian to English => ".$gt->it_to_en("Ciao mondo").""; } catch (GTranslateException $ge) { echo $ge->getMessage(); }
Related posts:




Dear Mr Da Silva
I am a student from Moroccco.
I wanted to thank you very much for providing us with teh Google translate API. I am working on an application that needs to use Google’s translation services and I needed the API in PHP.
So thank you very much!
You’re welcome Hakima ,
I hope that the API helps you to achieve your goals. Any doubts feel free to contact me.
Olá José.
Eu utilizei sua classe, mas estive vendo que o processo limita a quantidade de texto por que é enviado via GET.
teria alguma forma de driblar isto?
Olá Gilberto
Infelizmente a documentação do Google apenas disponibiliza passagem de parametros usando o protocolo GET, e aí terá sempre o problema dos caracteres. A única forma que vejo como possível de passar ao lado do limite, é jogar as regras do jogo.
No texto que deseja traduzir, separe o texto em N textos, talvez partindo a string por frases e efectue vários pedido à API de tradução.
Espero ter ajudado
Sim, eu fiz um esquema interessante em ajax José!
Bem simples! Eu coloquei uma classe CSS nas partes que desejo traduzir. E está funcionando perfeitamente.
De qualquer forma, me desculpe por não ter lhe agradecido por ter disponibilizado sua classe.
Hi, sorry about the comment from above.
Tfirst, tnx for you software it works.
Unfortunately Im getting something like this from my ES to CS translation:"Tyto otázky dnes musÃm udÄ›lat s vámi, osobnost, charakter, fyzickou Äást. Impulsivity iniciativ. Je Äas na zmÄ›nu duchovnÃ. ÄŒasté pÅ™ÃÄiny movilizarn vás."
I got charset=iso-8859-1 and it should wok but it doesnt, also happens with chinese, I also added: <html dir="ltr" lang="cs" xmlns="http://www.w3.org/1999/xhtml">
Do you have any clue why is this happening?
Tnx!!
Hello,
Thank you for your kind words about the class. About your issue, i am seeing this as a encoding issue, the issue that i am seeing is that you are using ISO instead of UTF-8 on the message sent to the class.
Try to make a utf8_encode()/decode() on the string. Let me know if it worked out!
what an informative posts, I will bookmark this site to digg. Regards, Reader.
Hi, thanks for this API. It works and it`s a time saving to see this API here.
Boas noites,
Grande classe José!
Um pequeno pormenor … estava aqui a testá-la e ela não me traduz palavras com acentos (por ex. maçã), alguma sugestão??
Cumps
Olá Miguel,
Efectuei um teste com a seguinte string:
"o antónio que também é conceição comeu a maçã no reino da rússia" e a resposta da tradução de português para inglês foi "Anthony is also the Conception ate the apple in the realm of russia".
A classe parece ter funcionado bem, ou está a traduzir para uma outra língua que não inglês?
De qualquer forma, verifique qual o encoding da string que está a passar para tradução, o problema pode estar relacionado com isso.
Excellent, apart from one thing! How do i see the tranlated text into a variable; it does seem to return any value?
Olá from Brasil ! Excelent post !
Olá José, achei este trabalho espectacular e tem facilitado em muito a minha vida. No entanto tenho uma duvida que poderá ser interessante para toda a gente que se interessa pelo google translate, que é quando não queremos que uma palavra seja traduzida.
Ora vejamos, em Portugal existe uma praia que se chama "praia da consolação", se traduzir de PT para Inglês obtenho o seguinte resultado óbvio: "Consolation Beach", mas a finalidade é que a tradução fosse "Consolação Beach".
Será que existe alguma forma de colocar algum caractere especial na palavra que não queremos que traduza?
De qualquer forma muito obrigado pelo seu trabalho.
João Chagas
Please Help…
I would like to use this library but I’m must be doing something wrong.
OI get a printout of every url call to the service and then the page shows up but the values on the table are the english ones, what am I doing wrong?
Thanks in advance!
The code did not show up in the previous post, had to remove the php open/close tags:
// lang is early array defined as $lang['foo'] = "this is english";
require("../GTranslate.php");
$gt = new Gtranslate;
foreach($lang as $key => $value) {
try {
$gt->english_to_spanish($value);
} catch (GTranslateException $ge) {
$lang[$key] = $ge->getMessage();
}
}
unset($value);
Tghis is error? You can help me fix it? pl PM to my email, thanks
http://truongthehoa.com/translate/index.php
gTranslate most used Add-on.
simple and fast.
Video about time for installation and translation.
http://www.youtube.com/watch?v=gGB2Wecu-CE
Hi Richard
Thank you for the suggestion.
Hi Jose Dasilva,
I’ve been tryin’ to implement your code, but since I couldn’t make it work on my server, I decided to simply try your example, and even that won’t work.
Does the web server has to be configured in any way to make it work?
Any settings that should be made etc?
Hope you have time for a quick answer. I have downloaded and up loaded:
example.php
GTranslate.php
on http://www.buchardt.it/test/example.php
Thanks,
Peter
Hi Jose,
thanks for this nice work
Is there any limit in terms of the text size? I have an error on line 179 with long texts.
Any idea?
Thanks, Julien
I’ve updated to the latest version, I now have an error at line 192
What the error says ?
This code can only be used locally but not online.
any idea
Hi all. Using Gtranlate and Simplehtmldom I wrote a class for easy translate of the entire site into other languages. Here’s a link to the draft http://code.google.com/p/globaltranslate please evaluate my work ) Jose da Silva thanks for Gtranlate
Hi
It’s true, although is not a code problem, google translate api only supports translations until 5000 characters.
You can use for bigger texts, but you have to be creative, splitting the text into chunks and making several calls.
Hi,
I am Anil Kumar Panigrahi , translate API is very good, thank you for sharing. I have small doubt in that.
When i have text in english it is easily converted in to french. But converted french data to english it is converted. I never got the exact text.
eg: Google’s translation API – ( in English, original text )
Google API de traduction – ( in French Converted English into french)
Google Translation API – ( in English Converted French into English)
Please suggest me.
Hello Anil
Thank you for the comment. About you doubt, there are many cases were you will not get the expected result, meaning, the exact original data, that’s mainly because of some specific language glitches.
That’s why computer translation is not the same as human translation.
What were you trying to perform with this ? Just a curiosity or other?
Jose