<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sarah Mei &#187; rtranslate</title>
	<atom:link href="http://www.sarahmei.com/blog/tag/rtranslate/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sarahmei.com/blog</link>
	<description></description>
	<lastBuildDate>Sun, 22 Jan 2012 20:16:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Travails with readline</title>
		<link>http://www.sarahmei.com/blog/2010/01/08/travails-with-readlin/</link>
		<comments>http://www.sarahmei.com/blog/2010/01/08/travails-with-readlin/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 03:59:05 +0000</pubDate>
		<dc:creator>sarahmei</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[irb]]></category>
		<category><![CDATA[japanese]]></category>
		<category><![CDATA[readline]]></category>
		<category><![CDATA[rtranslate]]></category>

		<guid isPermaLink="false">http://www.sarahmei.com/blog/?p=239</guid>
		<description><![CDATA[Applies to: Ruby 1.8.7, compiled from source, on OS X 10.6 (Snow Leopard). I&#8217;ve been working on a side project that deals with Japanese text in Ruby. I installed rtranslate, a gem that gives me programmatic access to Google Translate. I wanted to try it out in irb. >> require 'rtranslate' => true So far [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Applies to:</strong> Ruby 1.8.7, compiled from source, on OS X 10.6 (Snow Leopard).</p>
<p>I&#8217;ve been working on a side project that deals with Japanese text in Ruby. I installed <a href="http://github.com/sishen/rtranslate">rtranslate</a>, a gem that gives me programmatic access to Google Translate. I wanted to try it out in irb.</p>
<p><code>>> require 'rtranslate'<br />
=> true</code></p>
<p>So far so good.<br />
<code><br />
>> Translate.t("<br />
</code><br />
Here&#8217;s where I started to run into problems. I changed the input mode to Japanese and tried to enter はい (hai). All I got was beeping &#8211; irb wouldn&#8217;t let me enter any Japanese characters at all. I tried pasting from somewhere else &#8211; also a no go. </p>
<p>Long story short: by default, Ruby links against <a href="http://thrysoee.dk/editline/">editline</a> instead of GNU <a href="http://tiswww.case.edu/php/chet/readline/rltop.html">readline</a>, and editline doesn&#8217;t support multi-byte characters. If I started irb with the &#8211;noreadline option, it worked fine, but then none of the arrow keys worked. Highly annoying. </p>
<p>I read five different articles [<a href="http://www.jorgebernal.info/development/fixing-snow-leopard-ruby-readline">1</a>] [<a href="http://blogs.law.harvard.edu/hoanga/2009/09/08/getting-ruby-191p243-to-work-on-os-x-1058-with-japanese-input-support-on-irb/">2</a>] [<a href="http://wonko.com/post/how-to-compile-ruby-191">3</a>] [<a href="http://henrik.nyh.se/2008/03/irb-readline">4</a>] [<a href="http://www.michaelhamrah.com/blog/index.php/2009/12/getting-ruby-1-9-readline-rails-and-mysql-all-running-on-snow-leopard/">5</a>] that fixed variants of the problem; none of the solutions worked fully for me. My machine is running Snow Leopard, and I had installed Ruby 1.8.7 from source following the <a href="http://hivelogic.com/articles/compiling-ruby-rubygems-and-rails-on-snow-leopard/">Hivelogic directions</a>. So if you&#8217;re in the same boat, here&#8217;s how you get multi-byte input working:</p>
<p>1. Install GNU readline.</p>
<p><code>cd ~/src<br />
curl -O ftp://ftp.gnu.org/gnu/readline/readline-6.0.tar.gz<br />
tar xzvf readline-6.0.tar.gz<br />
cd readline-6.0<br />
./configure --prefix=/usr/local<br />
make<br />
sudo make install<br />
</code></p>
<p>The &#8211;prefix in the configure line is crucial.</p>
<p>2. Recompile Ruby, pointing at the new readline. I still had the Ruby source directory in ~/src from when I compiled it the first time (this is a relatively new laptop). If you don&#8217;t, you can just download it again.</p>
<p><code>cd ~/src<br />
curl -O ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p174.tar.gz<br />
tar xzvf ruby-1.8.7-p174.tar.gz<br />
cd ruby-1.8.7-p174<br />
make clean<br />
autoconf<br />
./configure --enable-shared --with-readline-dir=/usr/local<br />
make<br />
sudo make install<br />
</code></p>
<p>3. My profile had gotten out of whack, so I had to add this line (again) to ~/.bash_profile:</p>
<p><code>export PATH=/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH<br />
</code></p>
<p>Now I can enter multi-byte characters into irb, or copy them in from elsewhere. Now I can get on with what I was actually going to do. <img src='http://www.sarahmei.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><code>>> require "rtranslate"<br />
=> true<br />
>> Translate.t("はい", "JAPANESE", "ENGLISH")<br />
=> "Yes"<br />
</code> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.sarahmei.com/blog/2010/01/08/travails-with-readlin/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

