From: Richard Conroy Date: 2010-02-19T06:02:11+09:00 Subject: Re: RTranslate Gem (Open-URI) and Encoding --00032555942aa9d6b2047fe64790 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Thu, Feb 18, 2010 at 7:45 PM, The Chromag wrote: > I'm using the rtranslate gem (sishen-rtranslate) to handle translating > some text. It uses open-uri to scrape Google Translate. If I attempt > to translate text from English to Spanish it outputs some garbage > characters. > > Translating the word "where" returns "d=C3=B3nde" instead of "d=F3nde" > > Any idea why this is happening and what I can do to fix this? > > You need to specify encoding in your ruby script. Ruby (1.8 at least, I am not certain of 1.9) will use your system encoding for strings by default. Set this constant in your script to make Ruby process strings as UTF-8, independently of your machine $KCODE =3D 'u' There is more detail here: http://blog.grayproductions.net/articles/the_kcode_variable_and_jcode_libra= ry Note that Ruby could be processing google translate correctly (i.e. you are doing everything above), but if you are outputting the result to the console/system out (via puts) your machine may still process the UTF-8 text according to the host system. This for instance is a particularly annoying problem on windows systems IME. Output to a file instead if you are seeing this problem. regards, Richard. --=20 http://richardconroy.blogspot.com --00032555942aa9d6b2047fe64790--