google translate problems with spanish accent

118 views
Skip to first unread message

alicia130

unread,
May 21, 2009, 11:58:04 AM5/21/09
to Google AJAX APIs
I am calling google translate with the below code (I used Curl to
allow me to translate more than 500 characters). However, I am having
issues with the Spanish special characters not being returned
correctly.

Here is an example of what is being returned:
í³ instead of ó
ó instead of ó
í¡ instead of á
í± instead of ñ
etc.

Currently, I have to do a string replace in PHP to clean up the
garbage. I'd rather not hard code this though. Has anyone ran into
this issue before?

function translate($transText,$tlang){

define('POSTURL', 'http://ajax.googleapis.com/ajax/services/
language/translate');
// INITIALIZE ALL VARS
$ch='';
$Rec_Data='';

$ch = curl_init(POSTURL);
curl_setopt($ch, CURLOPT_POST ,1);
curl_setopt($ch, CURLOPT_POSTFIELDS ,
'q='. urlencode($transText). '&v=1.0'. '&langpair=%7C' . $tlang);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_HEADER ,0); // DO NOT RETURN
HTTP HEADERS
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1); // RETURN THE
CONTENTS OF THE CALL

$rec_Data = json_decode(curl_exec($ch), true);
return $rec_Data['responseData']['translatedText'];
}

Jeremy Geerdes

unread,
May 21, 2009, 12:09:58 PM5/21/09
to Google-AJAX...@googlegroups.com
I think you need to use the PHP's utf8_decode function on your
response string. The Language API deals in the utf-8 character set;
PHP generally handles ISO-8859-1 character set.

Jeremy R. Geerdes
Effective website design & development
Des Moines, IA

For more information or a project quote:
http://jgeerdes.home.mchsi.com
http://jgeerdes.blogspot.com
http://jgeerdes.wordpress.com
jgee...@mchsi.com

Unless otherwise noted, any price quotes contained within this
communication are given in US dollars.

If you're in the Des Moines, IA, area, check out Debra Heights
Wesleyan Church!

And check out my blog, Adventures in Web Development, at http://jgeerdes.blogspot.com
!

alicia130

unread,
May 21, 2009, 12:27:44 PM5/21/09
to Google AJAX APIs
thanks, i'll give that try!

On May 21, 11:09 am, Jeremy Geerdes <jrgeer...@gmail.com> wrote:
> I think you need to use the PHP's utf8_decode function on your  
> response string.  The Language API deals in the utf-8 character set;  
> PHP generally handles ISO-8859-1 character set.
>
> Jeremy R. Geerdes
> Effective website design & development
> Des Moines, IA
>
> For more information or a project quote:http://jgeerdes.home.mchsi.comhttp://jgeerdes.blogspot.comhttp://jgeerdes.wordpress.com
> jgeer...@mchsi.com
>
> Unless otherwise noted, any price quotes contained within this  
> communication are given in US dollars.
>
> If you're in the Des Moines, IA, area, check out Debra Heights  
> Wesleyan Church!
>
> And check out my blog, Adventures in Web Development, athttp://jgeerdes.blogspot.com

alicia130

unread,
May 27, 2009, 11:24:14 AM5/27/09
to Google AJAX APIs
This worked great on Spanish, but not so great for Chinese Simplified,
Japanese, Russian and Arabic (I get ???? in the fields). Is there
something different that is needed for these languages that contain
symbols?

On May 21, 11:27 am, alicia130 <alicia.williams...@gmail.com> wrote:
> thanks, i'll give that try!
>
> On May 21, 11:09 am, Jeremy Geerdes <jrgeer...@gmail.com> wrote:
>
> > I think you need to use the PHP's utf8_decode function on your  
> > response string.  The Language API deals in the utf-8 character set;  
> > PHP generally handles ISO-8859-1 character set.
>
> > Jeremy R. Geerdes
> > Effective website design & development
> > Des Moines, IA
>
> > For more information or a project quote:http://jgeerdes.home.mchsi.comhttp://jgeerdes.blogspot.comhttp://jgee...
> > jgeer...@mchsi.com
>
> > Unless otherwise noted, any price quotes contained within this  
> > communication are given in US dollars.
>
> > If you're in the Des Moines, IA, area, check out Debra Heights  
> > Wesleyan Church!
>
> > And check out my blog, Adventures in Web Development, athttp://jgeerdes.blogspot.com
> >   !
>
> > On May 21, 2009, at 10:58 AM, alicia130 wrote:
>
> > > I am calling google translate with the below code (I used Curl to
> > > allow me to translate more than 500 characters).  However, I am having
> > > issues with theSpanishspecial characters not being returned

alicia130

unread,
May 27, 2009, 9:16:25 PM5/27/09
to Google AJAX APIs
For Japanese, if I don't use the utf8_decode, I get ???? if I do use
it I get - ��������ゃ����

Have you seen this before?

On May 21, 11:09 am, Jeremy Geerdes <jrgeer...@gmail.com> wrote:
> I think you need to use the PHP's utf8_decode function on your  
> response string.  The Language API deals in the utf-8 character set;  
> PHP generally handles ISO-8859-1 character set.
>
> Jeremy R. Geerdes
> Effective website design & development
> Des Moines, IA
>
> For more information or a project quote:http://jgeerdes.home.mchsi.comhttp://jgeerdes.blogspot.comhttp://jgeerdes.wordpress.com
> jgeer...@mchsi.com
>
> Unless otherwise noted, any price quotes contained within this  
> communication are given in US dollars.
>
> If you're in the Des Moines, IA, area, check out Debra Heights  
> Wesleyan Church!
>
> And check out my blog, Adventures in Web Development, athttp://jgeerdes.blogspot.com
>   !
>
> On May 21, 2009, at 10:58 AM, alicia130 wrote:
>
>
>
> > I am calling google translate with the below code (I used Curl to
> > allow me to translate more than 500 characters).  However, I am having
> > issues with theSpanishspecial characters not being returned

Jeremy Geerdes

unread,
May 28, 2009, 12:41:47 AM5/28/09
to Google-AJAX...@googlegroups.com
It's all about character sets. The utf8_decode function decodes to iso
8859-1, which apparently doesn't support Japanese, Chinese, etc. I
did not know that before now, but I did a quick Google search and
found a number of possible solutions.

Jeremy R. Geerdes
Effective website design & development
Des Moines, IA

For more information or a project quote:
Unless otherwise noted, any price quotes contained within this
communication are given in US dollars.

If you're in the Des Moines, IA, area, check out Debra Heights
Wesleyan Church!

And check out my blog, Adventures in Web Development, at http://jgeerdes.blogspot.com
!


Reply all
Reply to author
Forward
0 new messages