<?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>Moki Systems Blog</title>
	<atom:link href="http://www.mokisystems.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mokisystems.com/blog</link>
	<description>Addressing such topics as: web programming, design, ruby on rails, cake php, postgresql, linux, seo</description>
	<lastBuildDate>Wed, 30 Sep 2009 16:34:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>We&#8217;re Hiring</title>
		<link>http://www.mokisystems.com/blog/were-hiring/</link>
		<comments>http://www.mokisystems.com/blog/were-hiring/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 16:34:57 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mokisystems.com/blog/?p=65</guid>
		<description><![CDATA[Moki Systems is seeking a full-time Ruby on Rails developer. The person should be a self starter, willing and able to figure things out on their own. Applicant should have experience with Ruby on Rails, MVC programming concepts, MySQL and/or PostgreSQL experience and the ability to learn new technologies. Any additional programming experience is a [...]]]></description>
			<content:encoded><![CDATA[<p>Moki Systems is seeking a full-time <strong>Ruby on Rails developer</strong>. The person should be a self starter, willing and able to figure things out on their own. Applicant should have experience with Ruby on Rails, MVC programming concepts, MySQL and/or PostgreSQL experience and the ability to learn new technologies. Any additional programming experience is a plus.</p>
<p>This is a full-time position with a 90-day probationary period after which medical benefits and paid holidays are available. Salary is competitive and depends on experience.</p>
<p>Send a resumé to:</p>
<p>Kelli Valadez</p>
<p>Contact Phone:<br />
435-674-3571</p>
<p>Contact Email:<br />
hr@mokisystems.com</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mokisystems.com/blog/were-hiring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux Clipboard Snippets</title>
		<link>http://www.mokisystems.com/blog/linux-clipboard-snippets/</link>
		<comments>http://www.mokisystems.com/blog/linux-clipboard-snippets/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 18:13:34 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.mokisystems.com/blog/?p=63</guid>
		<description><![CDATA[Whenever I find myself typing the same thing over and over again, I have to come up with some way to avoid the repetition. And one thing I do a lot is fill out web forms that require things like credit card numbers and unique email addresses. For a while I tried using Parcellite (a [...]]]></description>
			<content:encoded><![CDATA[<p>Whenever I find myself typing the same thing over and over again, I have to come up with some way to avoid the repetition. And one thing I do a lot is fill out web forms that require things like credit card numbers and unique email addresses. For a while I tried using Parcellite (a clipboard manager) but it wasn&#8217;t really designed for what I wanted to use it for. Finally with the inspiration of <a href="http://bbs.archlinux.org/viewtopic.php?id=71938">this thread</a> I was able to cobble together a solution that does just what I want.<br />
<span id="more-63"></span><br />
First I created a snippets directory and filled it with files that contained the text to insert or scripts to generate the desired text:</p>

<div class="wp_syntax"><div class="code"><pre>$ cd ~/.snippets
$ ls -1
credit_card
email
@example.com
phone
RAILS_ENV=test
sql_create
sql_permissions
$ cat credit_card 
4111111111111111
$ cat sql_permissions 
GRANT ALL PRIVILEGES ON .* TO ''@'localhost' IDENTIFIED BY ''<SEMI>
$ cat phone 
#!/usr/bin/env ruby
print (1..12).map {<PIPE>i<PIPE> i == 4 <PIPE><PIPE> i == 8 ? '-' : rand(10).to_s}.join</pre></div></div>

<p>Then I put this little script in ~/bin:</p>

<div class="wp_syntax"><div class="code"><pre class="bash"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;"># http://bbs.archlinux.org/viewtopic.php?id=71938</span>
<span style="color: #007800;">DIR=</span><span style="color: #800000;">${HOME}</span><span style="color: #000000; font-weight: bold;">/</span>.snippets
<span style="color: #007800;">DMENU_ARGS=</span><span style="color: #ff0000;">&quot;-i -fn -*-terminal-*-*-*-*-18-*-*-*-*-*-*-*&quot;</span> <span style="color: #666666; font-style: italic;"># xfontsel to select font</span>
&nbsp;
<span style="color: #007800;">FILE=</span><span style="color: #000000; font-weight: bold;">`/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #007800;">$DIR</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>dmenu <span style="color: #800000;">${DMENU_ARGS}</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> -x <span style="color: #800000;">${DIR}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${FILE}</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span> <span style="color: #666666; font-style: italic;">#executable</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> -n <span style="color: #000000; font-weight: bold;">`</span><span style="color: #800000;">${DIR}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${FILE}</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">|</span> xsel -b -i
<span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> -f <span style="color: #800000;">${DIR}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${FILE}</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #800000;">${DIR}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${FILE}</span> <span style="color: #000000; font-weight: bold;">|</span> xsel -b -i
<span style="color: #000000; font-weight: bold;">fi</span>
xdotool key ctrl+v <span style="color: #666666; font-style: italic;"># for non-console</span>
xdotool key ctrl+<span style="color: #7a0874; font-weight: bold;">shift</span>+v <span style="color: #666666; font-style: italic;"># for console</span></pre></div></div>

<p>And then I mapped that script to a handy key combination in compiz. So now whenever I need a test credit card number, phone number, or email address I can just do <ctrl><alt>c, type the first few characters to select the right snippet, hit return and it gets pasted in to whatever I&#8217;m working on.</p>
<p>Notes and caveats:</p>
<ul>
<li>I had to aptitude install some packages to get dmenu and xdotool to work.</li>
<li>dmenu is ugly and has no mouse support.</li>
<li>Pasting into vim has occasional issues.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.mokisystems.com/blog/linux-clipboard-snippets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Savings records that fail validation.</title>
		<link>http://www.mokisystems.com/blog/savings-records-that-fail-validation/</link>
		<comments>http://www.mokisystems.com/blog/savings-records-that-fail-validation/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 19:39:15 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mokisystems.com/blog/?p=62</guid>
		<description><![CDATA[So I had this problem with a record that was being saved even though it failed validation:

cc = CreditCard.new&#40;:card_number =&#62; 'invalid'&#41;
&#62;&#62; cc.save
=&#62; false
&#62;&#62; cc.id
=&#62; 3

That one had me stumped for a while until I realized I was carelessly using update_attribute in my custom writer:

def card_number=&#40;num&#41;
  update_attribute&#40;:crypted_card_number, encrypt&#40;num&#41;&#41;
end

And we all know that update_attribute &#8220;saves the [...]]]></description>
			<content:encoded><![CDATA[<p>So I had this problem with a record that was being saved even though it failed validation:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby">cc = CreditCard.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:card_number</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'invalid'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> cc.<span style="color:#9900CC;">save</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> cc.<span style="color:#9900CC;">id</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">3</span></pre></div></div>

<p>That one had me stumped for a while until I realized I was carelessly using update_attribute in my custom writer:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">def</span> card_number=<span style="color:#006600; font-weight:bold;">&#40;</span>num<span style="color:#006600; font-weight:bold;">&#41;</span>
  update_attribute<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:crypted_card_number</span>, encrypt<span style="color:#006600; font-weight:bold;">&#40;</span>num<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>And we all know that <a href="http://apidock.com/rails/ActiveRecord/Base/update_attribute">update_attribute</a> &#8220;saves the record without going through the normal validation procedure.&#8221;</p>
<p>Everything worked much nicer after I changed the code to:</p>
<pre code="ruby">
def card_number=(num)
  self.crypted_card_number = encrypt(num)
end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.mokisystems.com/blog/savings-records-that-fail-validation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby thinks (19.99 * 100).to_i = 1998</title>
		<link>http://www.mokisystems.com/blog/ruby-thinks-1999-100to_i-1998/</link>
		<comments>http://www.mokisystems.com/blog/ruby-thinks-1999-100to_i-1998/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 15:25:42 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.mokisystems.com/blog/?p=60</guid>
		<description><![CDATA[
&#62;&#62; &#40;19.99 * 100&#41;.to_i
=&#62; 1998
&#62;&#62; &#40;9.99 * 100&#41;.to_i
=&#62; 999

Someone please tell me what&#8217;s up with that!
In the meantime:

&#62;&#62; &#40;19.99 * 100&#41;.to_s.to_i
=&#62; 1999

]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">19.99</span> <span style="color:#006600; font-weight:bold;">*</span> <span style="color:#006666;">100</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_i</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1998</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">9.99</span> <span style="color:#006600; font-weight:bold;">*</span> <span style="color:#006666;">100</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_i</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">999</span></pre></div></div>

<p>Someone please tell me what&#8217;s up with that!</p>
<p>In the meantime:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">19.99</span> <span style="color:#006600; font-weight:bold;">*</span> <span style="color:#006666;">100</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_s</span>.<span style="color:#9900CC;">to_i</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1999</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.mokisystems.com/blog/ruby-thinks-1999-100to_i-1998/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>A Couple Rails Find Gotchas</title>
		<link>http://www.mokisystems.com/blog/a-couple-rails-find-gotchas/</link>
		<comments>http://www.mokisystems.com/blog/a-couple-rails-find-gotchas/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 16:07:22 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.mokisystems.com/blog/?p=59</guid>
		<description><![CDATA[We ran into a few little gotchas with ActiveRecord&#8217;s find method when upgrading from Rails 2.1.1 to 2.2.2. The solutions are pretty trivial, so the main lesson here is to test your code so things like this get caught by your test suite and not the client.

Gotcha #1

>> Rails.version
=> "2.1.1"
>> Client.find_all_by_notify_by(%w(email txt both)).size
=> 2


>> Rails.version
=> [...]]]></description>
			<content:encoded><![CDATA[<p>We ran into a few little gotchas with ActiveRecord&#8217;s find method when upgrading from Rails 2.1.1 to 2.2.2. The solutions are pretty trivial, so the main lesson here is to test your code so things like this get caught by your test suite and not the client.</p>
<p><span id="more-59"></span></p>
<h3>Gotcha #1</h3>
<p><code><br />
>> Rails.version<br />
=> "2.1.1"<br />
>> Client.find_all_by_notify_by(%w(email txt both)).size<br />
=> 2<br />
</code></p>
<p><code><br />
>> Rails.version<br />
=> "2.2.2"<br />
>> Client.find_all_by_notify_by(%w(email txt both)).size<br />
ActiveRecord::StatementInvalid: Mysql::Error: Operand should contain 1 column(s): SELECT * FROM `clients` WHERE (notify_by = 'email','txt','both' AND clients.deleted_at IS NULL)<br />
>> Client.find(:all, :conditions => ["notify_by = ? OR notify_by = ? OR notify_by = ?", *%w(email txt both)]).size<br />
=> 2<br />
</code></p>
<h3>Gotcha #2</h3>
<p><code><br />
>> Rails.version<br />
=> "2.1.1"<br />
>> Client.find_all_by_agent_id(nil).size<br />
=> 26<br />
</code></p>
<p><code><br />
>> Rails.version<br />
=> "2.2.2"<br />
>> Client.find_all_by_agent_id(nil).size<br />
=> 0<br />
>> Client.find(:all, :conditions => "agent_id IS NULL").size<br />
=> 26<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mokisystems.com/blog/a-couple-rails-find-gotchas/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How large is an individual table in Microsoft SQL Server</title>
		<link>http://www.mokisystems.com/blog/how-large-is-an-individual-table-in-microsoft-sql-server/</link>
		<comments>http://www.mokisystems.com/blog/how-large-is-an-individual-table-in-microsoft-sql-server/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 20:38:35 +0000</pubDate>
		<dc:creator>james</dc:creator>
				<category><![CDATA[Database Administration]]></category>
		<category><![CDATA[Microsoft SQL Server]]></category>

		<guid isPermaLink="false">http://www.mokisystems.com/blog/?p=58</guid>
		<description><![CDATA[Some time ago I had a situation where a clients SQL database was about 70GB larger than they expected it to be. That is like 10 times larger than they expected.
They asked me to trouble shoot the problem; with no clue as to what the problem should be.
To begin with I decided to find out [...]]]></description>
			<content:encoded><![CDATA[<p>Some time ago I had a situation where a clients SQL database was about 70GB larger than they expected it to be. That is like 10 times larger than they expected.</p>
<p>They asked me to trouble shoot the problem; with no clue as to what the problem should be.</p>
<p>To begin with I decided to find out the size of each individual table to determine if it was any particular table that was the problem.</p>
<p>To calculate the table sizes I wrote a query to put all of the table sizes into a table that could easily be read and shared with the client as follows:<br />
<code><br />
create table temp_tablesizes (</p>
<p>name varchar(250),</p>
<p>rows int,</p>
<p>reserved varchar(20),</p>
<p>data varchar(20),</p>
<p>index_size varchar(20),</p>
<p>unused varchar(20)</p>
<p>)</p>
<p>DECLARE @table_name varchar(250)</p>
<p>declare @res_name varchar(250)</p>
<p>DECLARE table_list CURSOR read_only</p>
<p>FOR SELECT TABLE_SCHEMA + '.' + TABLE_NAME AS Expr1</p>
<p>FROM         information_schema.tables                                                                                                                                              WHERE     (table_type = 'BASE TABLE')</p>
<p>ORDER BY TABLE_NAME OPEN table_list FETCH next</p>
<p>FROM         table_list</p>
<p>INTO @table_name</p>
<p>WHILE @@fetch_status = 0</p>
<p>BEGIN</p>
<p>insert into temp_tablesizes EXEC sp_spaceused @table_name</p>
<p>PRINT @table_name</p>
<p>FETCH next</p>
<p>FROM         table_list</p>
<p>INTO            @table_name END CLOSE table_list DEALLOCATE table_list</p>
<p></code></p>
<p>Looking at the table sizes in the temp_tablesizes database we discovered that 90% of the size was allocated to a table which was suppose to have a maximum of two records per account each record being a large sound file.  We discovered that the tool which deleted old recordings wasn&#8217;t working and where able to resolve the problem of an excessively large Microsoft SQL Server database.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mokisystems.com/blog/how-large-is-an-individual-table-in-microsoft-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vim as a Ruby on Rails IDE</title>
		<link>http://www.mokisystems.com/blog/vim-as-a-ruby-on-rails-ide/</link>
		<comments>http://www.mokisystems.com/blog/vim-as-a-ruby-on-rails-ide/#comments</comments>
		<pubDate>Mon, 29 Dec 2008 17:47:11 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.mokisystems.com/blog/?p=56</guid>
		<description><![CDATA[In the words of Tim Pope &#8220;TextMate may be the latest craze for developing Ruby on Rails applications, but Vim is forever&#8221;
Here&#8217;s how I use vim (and gnome-terminal) to program in Rails on Ubuntu.

I have a ruby script that opens two gnome-terminals each with 9 tabs each. That may seem like a lot, but each [...]]]></description>
			<content:encoded><![CDATA[<p>In the words of <a href="http://www.vim.org/scripts/script.php?script_id=1567">Tim Pope</a> &#8220;TextMate may be the latest craze for developing Ruby on Rails applications, but Vim is forever&#8221;</p>
<p>Here&#8217;s how I use vim (and gnome-terminal) to program in Rails on Ubuntu.</p>
<p><!-- More --></p>
<p>I have a <a href="http://github.com/eremite/binfiles/tree/master/zvim_rails_ide">ruby script</a> that opens two gnome-terminals each with 9 tabs each. That may seem like a lot, but each one is assigned a specific purpose and by now my fingers know just where to go depending on the task at hand. For example, models, views and controllers each get their own tab. So if I need to edit a model my fingers will do an <Alt-1>vim model_name.rb (or :e model_name.rb if I&#8217;m already in vim). And of course <a href="http://github.com/eremite/dotfiles/tree/master/bashrc">bash aliases</a> and tab_completion minimizes the actual number of keystrokes required. In the same way, I know exactly where to go to watch the log, play in the console, use the SCM or anything else.</p>
<p><a href='http://www.mokisystems.com/blog/wp-content/uploads/2008/12/zvim_rails_ide.png'><img src="http://www.mokisystems.com/blog/wp-content/uploads/2008/12/zvim_rails_ide-300x174.png" alt="My Vim Rails IDE" title="vim_rails_ide" width="300" height="174" class="alignnone size-medium wp-image-57" /></a></p>
<p>So that&#8217;s what it actually looks like. Notice how I have Gmail in the background so I can know immediately when I get a new email or IM (and ignore it at my leisure). Not shown is a separate Firefox window running on my other monitor so that I can see both the code and the running application at the same time.</p>
<p>Now, I have some doubts as to how well my solution would work for other people as it requires a bit of discipline to make sure <a href="http://www.google.com/search?hl=en&#038;q=%22A+place+for+everything+and+everything+in+its+place%22&#038;btnG=Search">everything has a place</a> and to train yourself to always do things in the right place. It seems <a href="http://weblog.jamisbuck.org/2008/10/10/coming-home-to-vim">most people</a> prefer to have only a few windows (or tabs or buffers or whatever) open and use some sort of <a href="http://github.com/jamis/fuzzyfinder_textmate/tree/master">fuzzy finder</a> or <a href="http://www.vim.org/scripts/script.php?script_id=1658">file explorer</a> to find the file they want to work on next. But that&#8217;s what I love about vim. I can come up with a custom workflow that works for me instead of conforming to the whims of some dictatorial IDE. True, the learning curve was quite steep at first, and I still occasionally invest some of my time in learning how to use additional features and <a href="http://github.com/eremite/dotfiles/tree/master/vimrc">customizations</a>, but now contemplating using another text editor is like going back to riding tricycles after learning to fly jet planes.</p>
<p>Here&#8217;s the current version of the ruby script in case anyone&#8217;s interested. I call it zvim_rails_ide so I can use it with a quick zv&lt;tab&gt;.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">if</span> ARGV.<span style="color:#9900CC;">size</span>.<span style="color:#9900CC;">zero</span>?
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Usage: #{File.basename($0)} name_of_project&quot;</span>
  <span style="color:#CC0066; font-weight:bold;">exit</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
RAILS_ROOT = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">pwd</span>, ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
RAILS_ROOT <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">'/'</span> <span style="color:#9966CC; font-weight:bold;">unless</span> RAILS_ROOT<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span> =~ <span style="color:#006600; font-weight:bold;">%</span>r<span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">/</span>$<span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exists</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>RAILS_ROOT<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;#{RAILS_ROOT}: No such file or directory&quot;</span>
  <span style="color:#CC0066; font-weight:bold;">exit</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
ls = <span style="color:#996600;">&quot;ls --color&quot;</span>
scm = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exists</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'.git'</span><span style="color:#006600; font-weight:bold;">&#41;</span> ? <span style="color:#996600;">'git status'</span> : <span style="color:#996600;">'svn status'</span>
test_dir = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exists</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#{RAILS_ROOT}spec&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> ? <span style="color:#996600;">'spec'</span> : <span style="color:#996600;">'test'</span>
&nbsp;
<span style="color:#006600; font-weight:bold;">&#91;</span>
  <span style="color:#006600; font-weight:bold;">&#123;</span>
    <span style="color:#ff3333; font-weight:bold;">:geometry</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;140x38+90+270&quot;</span>,
    <span style="color:#ff3333; font-weight:bold;">:tabs</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span>
      <span style="color:#006600; font-weight:bold;">&#123;</span>:path <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;app/models&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:command</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> ls<span style="color:#006600; font-weight:bold;">&#125;</span>,
      <span style="color:#006600; font-weight:bold;">&#123;</span>:path <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;app/views&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:command</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> ls<span style="color:#006600; font-weight:bold;">&#125;</span>,
      <span style="color:#006600; font-weight:bold;">&#123;</span>:path <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;app/controllers&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:command</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> ls<span style="color:#006600; font-weight:bold;">&#125;</span>,
      <span style="color:#006600; font-weight:bold;">&#123;</span>:path <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;app/helpers&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:command</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> ls<span style="color:#006600; font-weight:bold;">&#125;</span>,
      <span style="color:#006600; font-weight:bold;">&#123;</span>:path <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;public&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:command</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> ls<span style="color:#006600; font-weight:bold;">&#125;</span>,
      <span style="color:#006600; font-weight:bold;">&#123;</span>:path <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;vendor&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:command</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> ls<span style="color:#006600; font-weight:bold;">&#125;</span>,
      <span style="color:#006600; font-weight:bold;">&#123;</span>:path <span style="color:#006600; font-weight:bold;">=&gt;</span> test_dir, <span style="color:#ff3333; font-weight:bold;">:command</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> ls<span style="color:#006600; font-weight:bold;">&#125;</span>,
      <span style="color:#006600; font-weight:bold;">&#123;</span>:path <span style="color:#006600; font-weight:bold;">=&gt;</span> test_dir, <span style="color:#ff3333; font-weight:bold;">:command</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> ls<span style="color:#006600; font-weight:bold;">&#125;</span>,
      <span style="color:#006600; font-weight:bold;">&#123;</span>:path <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:command</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> ls<span style="color:#006600; font-weight:bold;">&#125;</span>
    <span style="color:#006600; font-weight:bold;">&#93;</span>
  <span style="color:#006600; font-weight:bold;">&#125;</span>,
  <span style="color:#006600; font-weight:bold;">&#123;</span>
    <span style="color:#ff3333; font-weight:bold;">:geometry</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;141x32+185+110&quot;</span>,
    <span style="color:#ff3333; font-weight:bold;">:tabs</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span>
      <span style="color:#006600; font-weight:bold;">&#123;</span>:path <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:command</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> scm<span style="color:#006600; font-weight:bold;">&#125;</span>,
      <span style="color:#006600; font-weight:bold;">&#123;</span>:path <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:command</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> ls<span style="color:#006600; font-weight:bold;">&#125;</span>,
      <span style="color:#006600; font-weight:bold;">&#123;</span>:path <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;lib&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:command</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> ls<span style="color:#006600; font-weight:bold;">&#125;</span>,
      <span style="color:#006600; font-weight:bold;">&#123;</span>:path <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:command</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;ruby script/console&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>,
      <span style="color:#006600; font-weight:bold;">&#123;</span>:path <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:command</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> ls<span style="color:#006600; font-weight:bold;">&#125;</span>,
      <span style="color:#006600; font-weight:bold;">&#123;</span>:path <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;config/locales&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:command</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> ls<span style="color:#006600; font-weight:bold;">&#125;</span>,
      <span style="color:#006600; font-weight:bold;">&#123;</span>:path <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:command</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> ls<span style="color:#006600; font-weight:bold;">&#125;</span>,
      <span style="color:#006600; font-weight:bold;">&#123;</span>:path <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:command</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> ls<span style="color:#006600; font-weight:bold;">&#125;</span>,
      <span style="color:#006600; font-weight:bold;">&#123;</span>:path <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:command</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> ls<span style="color:#006600; font-weight:bold;">&#125;</span>
    <span style="color:#006600; font-weight:bold;">&#93;</span>
  <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>window<span style="color:#006600; font-weight:bold;">|</span>
  tabs = window<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:tabs</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">map</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>tab<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#996600;">&quot;--tab-with-profile=DEFAULT --working-directory='#{RAILS_ROOT}#{tab[:path]}' -e <span style="color:#000099;">\&quot;</span>bash -c '#{tab[:command]}; bash'<span style="color:#000099;">\&quot;</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">' '</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#CC0066; font-weight:bold;">system</span> <span style="color:#996600;">&quot;gnome-terminal --geometry #{window[:geometry]} #{tabs}&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.mokisystems.com/blog/vim-as-a-ruby-on-rails-ide/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Rails’ New I18n Support in Real Life: Part the Fourth</title>
		<link>http://www.mokisystems.com/blog/using-rails-new-i18n-support-in-real-life-part-the-fourth/</link>
		<comments>http://www.mokisystems.com/blog/using-rails-new-i18n-support-in-real-life-part-the-fourth/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 15:35:00 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.mokisystems.com/blog/?p=54</guid>
		<description><![CDATA[So after tediously going through your entire site and extracting all displayed strings to a separate translation file, how do you know you didn&#8217;t miss something somewhere? My solution was to create a quick rake task that machine translates my English yaml file to something else. A quick sudo aptitude install bsdgames and I had [...]]]></description>
			<content:encoded><![CDATA[<p>So after tediously going through your entire site and extracting all displayed strings to a separate translation file, how do you know you didn&#8217;t miss something somewhere? My solution was to create a quick rake task that machine translates my English yaml file to something else. A quick <em>sudo aptitude install bsdgames</em> and I had pig latin at my fingertips. So I switched to that and browsed through the site and looked for anything that hadn&#8217;t changed. And I found quite a bit of stuff that I had missed.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#008000; font-style:italic;"># lib/tasks/pig.rake</span>
desc <span style="color:#996600;">&quot;Creates a config/locales/pig-US.yml from config/locales/en-US.yml&quot;</span>
task <span style="color:#ff3333; font-weight:bold;">:pig</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:environment</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  DEFAULT_LOCALE = <span style="color:#996600;">'en-US'</span>
  <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>RAILS_ROOT, <span style="color:#996600;">'config'</span>, <span style="color:#996600;">'locales'</span>, <span style="color:#996600;">'pig-US.yml'</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#996600;">&quot;w&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>fout<span style="color:#006600; font-weight:bold;">|</span>
    <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">readlines</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>RAILS_ROOT, <span style="color:#996600;">'config'</span>, <span style="color:#996600;">'locales'</span>, <span style="color:#996600;">&quot;#{DEFAULT_LOCALE}.yml&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>line<span style="color:#006600; font-weight:bold;">|</span>
      <span style="color:#9966CC; font-weight:bold;">unless</span> line =~ <span style="color:#006600; font-weight:bold;">/</span><span style="color:#996600;">&quot;/
        fout.puts line.sub(DEFAULT_LOCALE, 'pig-US')
      else
        key, *translation = line.split(':')
        translation = translation.join(':')
        translation.split(/(&quot;</span>.<span style="color:#9900CC;">*</span>?<span style="color:#996600;">&quot;)/).each do |quote|
          if quote =~ /&quot;</span><span style="color:#006600; font-weight:bold;">/</span>
            quote.<span style="color:#CC0066; font-weight:bold;">gsub</span>!<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'&quot;'</span>, <span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>
            <span style="color:#CC0066; font-weight:bold;">string</span> = quote.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#40;</span>\<span style="color:#006600; font-weight:bold;">&#123;</span>\<span style="color:#006600; font-weight:bold;">&#123;</span>.<span style="color:#9900CC;">*</span>?\<span style="color:#006600; font-weight:bold;">&#125;</span>\<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">map</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>s<span style="color:#006600; font-weight:bold;">|</span>
              <span style="color:#006600; font-weight:bold;">&#40;</span>s =~ <span style="color:#006600; font-weight:bold;">/</span>\<span style="color:#006600; font-weight:bold;">&#123;</span>\<span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span> ? s : <span style="color:#996600;">`echo &quot;#{s.gsub('$', '<span style="color:#000099;">\$</span>')}&quot; | pig`</span>.<span style="color:#CC0066; font-weight:bold;">chomp</span>
            <span style="color:#9966CC; font-weight:bold;">end</span>
            translation.<span style="color:#CC0066; font-weight:bold;">sub</span>!<span style="color:#006600; font-weight:bold;">&#40;</span>quote, <span style="color:#CC0066; font-weight:bold;">string</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#41;</span>
          <span style="color:#9966CC; font-weight:bold;">end</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
        fout.<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;#{key}:#{translation}&quot;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>P.S. Note to anyone that actually tries to use this: This is just a quick and dirty script and will probably require some modification to work in your situation. In particular it requires all the strings you want translated to be within double quotes.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mokisystems.com/blog/using-rails-new-i18n-support-in-real-life-part-the-fourth/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Rails’ New I18n Support in Real Life: Part the Third</title>
		<link>http://www.mokisystems.com/blog/using-rails-new-i18n-support-in-real-life-part-the-third/</link>
		<comments>http://www.mokisystems.com/blog/using-rails-new-i18n-support-in-real-life-part-the-third/#comments</comments>
		<pubDate>Mon, 15 Dec 2008 15:14:58 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.mokisystems.com/blog/?p=53</guid>
		<description><![CDATA[What happens when you add a new string to your default locale file and forget about the other languages? Well, by default it&#8217;ll raise a MissingTranslationData and your users will see an ugly string the likes of &#8220;es-MX, marketing_interface, index, title&#8220;. Wouldn&#8217;t it be better to at least try and default to English? My guess [...]]]></description>
			<content:encoded><![CDATA[<p>What happens when you add a new string to your default locale file and forget about the other languages? Well, by default it&#8217;ll raise a MissingTranslationData and your users will see an ugly string the likes of &#8220;<em>es-MX, marketing_interface, index, title</em>&#8220;. Wouldn&#8217;t it be better to at least try and default to English? My guess is that most people would prefer to see the message in another language than some cryptic error message. And while we&#8217;re wishing, don&#8217;t you think the <em>localize</em> method shouldn&#8217;t die a noisy death when you happen to pass it a nil?</p>
<p>My solution? A custom I18n backend. I simply copy/pasted the code from the default &#8220;Simple&#8221; backend, tweaked a few lines and I was good to go!</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#008000; font-style:italic;"># In some file that gets sourced on startup, like maybe in your config/initializers directory</span>
<span style="color:#9966CC; font-weight:bold;">module</span> I18n
  <span style="color:#9966CC; font-weight:bold;">module</span> Backend
    <span style="color:#9966CC; font-weight:bold;">class</span> Moki <span style="color:#006600; font-weight:bold;">&lt;</span> Simple
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">def</span> translate<span style="color:#006600; font-weight:bold;">&#40;</span>locale, key, options = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#CC0066; font-weight:bold;">raise</span> InvalidLocale.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>locale<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> locale.<span style="color:#0000FF; font-weight:bold;">nil</span>?
        <span style="color:#0000FF; font-weight:bold;">return</span> key.<span style="color:#9900CC;">map</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>k<span style="color:#006600; font-weight:bold;">|</span> translate<span style="color:#006600; font-weight:bold;">&#40;</span>locale, k, options<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#9966CC; font-weight:bold;">if</span> key.<span style="color:#9900CC;">is_a</span>? <span style="color:#CC0066; font-weight:bold;">Array</span>
        reserved = <span style="color:#ff3333; font-weight:bold;">:scope</span>, <span style="color:#ff3333; font-weight:bold;">:default</span>
        count, scope, default = options.<span style="color:#9900CC;">values_at</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:count</span>, <span style="color:#006600; font-weight:bold;">*</span>reserved<span style="color:#006600; font-weight:bold;">&#41;</span>
        options.<span style="color:#9900CC;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:default</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        values = options.<span style="color:#9900CC;">reject</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>name, value<span style="color:#006600; font-weight:bold;">|</span> reserved.<span style="color:#9966CC; font-weight:bold;">include</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>name<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
        entry = lookup<span style="color:#006600; font-weight:bold;">&#40;</span>locale, key, scope<span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#9966CC; font-weight:bold;">if</span> entry.<span style="color:#0000FF; font-weight:bold;">nil</span>?
          entry = default<span style="color:#006600; font-weight:bold;">&#40;</span>locale, default, options<span style="color:#006600; font-weight:bold;">&#41;</span>
          entry <span style="color:#006600; font-weight:bold;">||</span>= lookup<span style="color:#006600; font-weight:bold;">&#40;</span>I18n.<span style="color:#9900CC;">default_locale</span>, key, scope<span style="color:#006600; font-weight:bold;">&#41;</span>
          <span style="color:#CC0066; font-weight:bold;">raise</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#6666ff; font-weight:bold;">I18n::MissingTranslationData</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>locale, key, options<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> entry.<span style="color:#0000FF; font-weight:bold;">nil</span>?
        <span style="color:#9966CC; font-weight:bold;">end</span>
        entry = pluralize<span style="color:#006600; font-weight:bold;">&#40;</span>locale, entry, count<span style="color:#006600; font-weight:bold;">&#41;</span>
        entry = interpolate<span style="color:#006600; font-weight:bold;">&#40;</span>locale, entry, values<span style="color:#006600; font-weight:bold;">&#41;</span>
        entry
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">def</span> localize<span style="color:#006600; font-weight:bold;">&#40;</span>locale, object, <span style="color:#CC0066; font-weight:bold;">format</span> = <span style="color:#ff3333; font-weight:bold;">:default</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">nil</span> <span style="color:#9966CC; font-weight:bold;">if</span> object.<span style="color:#0000FF; font-weight:bold;">nil</span>?
        <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#CC00FF; font-weight:bold;">ArgumentError</span>, <span style="color:#996600;">&quot;Object must be a Date, DateTime or Time object. #{object.inspect} given.&quot;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> object.<span style="color:#9900CC;">respond_to</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:strftime</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        type = object.<span style="color:#9900CC;">respond_to</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:sec</span><span style="color:#006600; font-weight:bold;">&#41;</span> ? <span style="color:#996600;">'time'</span> : <span style="color:#996600;">'date'</span>
        formats = translate<span style="color:#006600; font-weight:bold;">&#40;</span>locale, <span style="color:#996600;">&quot;#{type}.formats&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#CC0066; font-weight:bold;">format</span> = formats<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">to_sym</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">if</span> formats <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> formats<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">to_sym</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        <span style="color:#CC0066; font-weight:bold;">format</span> = <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">to_s</span>.<span style="color:#9900CC;">dup</span>
        <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#CC0066; font-weight:bold;">gsub</span>!<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/%</span>a<span style="color:#006600; font-weight:bold;">/</span>, translate<span style="color:#006600; font-weight:bold;">&#40;</span>locale, <span style="color:#996600;">&quot;date.abbr_day_names&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span>object.<span style="color:#9900CC;">wday</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#CC0066; font-weight:bold;">gsub</span>!<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/%</span>A<span style="color:#006600; font-weight:bold;">/</span>, translate<span style="color:#006600; font-weight:bold;">&#40;</span>locale, <span style="color:#996600;">&quot;date.day_names&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span>object.<span style="color:#9900CC;">wday</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#CC0066; font-weight:bold;">gsub</span>!<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/%</span>b<span style="color:#006600; font-weight:bold;">/</span>, translate<span style="color:#006600; font-weight:bold;">&#40;</span>locale, <span style="color:#996600;">&quot;date.abbr_month_names&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span>object.<span style="color:#9900CC;">mon</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#CC0066; font-weight:bold;">gsub</span>!<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/%</span>B<span style="color:#006600; font-weight:bold;">/</span>, translate<span style="color:#006600; font-weight:bold;">&#40;</span>locale, <span style="color:#996600;">&quot;date.month_names&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span>object.<span style="color:#9900CC;">mon</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#CC0066; font-weight:bold;">gsub</span>!<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/%</span><span style="color:#CC0066; font-weight:bold;">p</span><span style="color:#006600; font-weight:bold;">/</span>, translate<span style="color:#006600; font-weight:bold;">&#40;</span>locale, <span style="color:#996600;">&quot;time.#{object.hour &lt; 12 ? :am : :pm}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> object.<span style="color:#9900CC;">respond_to</span>? <span style="color:#ff3333; font-weight:bold;">:hour</span>
        object.<span style="color:#9900CC;">strftime</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">format</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
I18n.<span style="color:#9900CC;">backend</span> = <span style="color:#6666ff; font-weight:bold;">I18n::Backend::Moki</span>.<span style="color:#9900CC;">new</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.mokisystems.com/blog/using-rails-new-i18n-support-in-real-life-part-the-third/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Rails’ New I18n Support in Real Life: Part the Second</title>
		<link>http://www.mokisystems.com/blog/using-rails-new-i18n-support-in-real-life-part-the-second/</link>
		<comments>http://www.mokisystems.com/blog/using-rails-new-i18n-support-in-real-life-part-the-second/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 16:36:01 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.mokisystems.com/blog/?p=52</guid>
		<description><![CDATA[A few more thoughts on handling I18n for real projects.

Images
The way I handled images was pretty simple. Just added this application_helper:

  # Translated image tag
  def timage_tag&#40;source, options = &#123;&#125;&#41;
    image_tag&#40;&#34;#{I18n.locale}/#{source}&#34;, options&#41;
  end

Then I created a directory in public/images for each of the supported locales (e.g. public/images/en-US), put all [...]]]></description>
			<content:encoded><![CDATA[<p>A few more thoughts on handling I18n for real projects.</p>
<p><span id="more-52"></span></p>
<p><strong>Images</strong></p>
<p>The way I handled images was pretty simple. Just added this application_helper:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby">  <span style="color:#008000; font-style:italic;"># Translated image tag</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> timage_tag<span style="color:#006600; font-weight:bold;">&#40;</span>source, options = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    image_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#{I18n.locale}/#{source}&quot;</span>, options<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Then I created a directory in public/images for each of the supported locales (e.g. public/images/en-US), put all the images with text in there and I was good to go.</p>
<hr />
<p><strong>Pagination</strong></p>
<p>Pagination was handled similarly with a helper to wrap the call to <a href="http://github.com/mislav/will_paginate/wikis">mislav&#8217;s will_paginate gem</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby">  <span style="color:#008000; font-style:italic;"># Translated will_paginate</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> twill_paginate<span style="color:#006600; font-weight:bold;">&#40;</span>collection = <span style="color:#0000FF; font-weight:bold;">nil</span>, options = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    will_paginate collection, <span style="color:#006600; font-weight:bold;">&#123;</span>:previous_label <span style="color:#006600; font-weight:bold;">=&gt;</span> t<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'constants.will_paginate.previous'</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#ff3333; font-weight:bold;">:next_label</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> t<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'constants.will_paginate.next'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">merge</span><span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre># config/locales/en-US.yml
en-US:
  constants:
    will_paginate:
      previous: &quot;« Previous&quot;
      next: &quot;Next »&quot;</pre></div></div>

<hr />
<p><strong>activerecord</strong></p>
<p>Oh and another thing that really helped was using the human_name stuff <a href="http://iain.nl/2008/09/translating-activerecord/">built in</a> to activerecord. So, for example, everywhere I found an &#8220;Agent&#8221; in the text instead of an explicit call to <em>translate</em> I could just do <em>Agent.human_name</em>. And for each of Agent&#8217;s attributes I could do <em>Agent.human_attribute_name(&#8217;name&#8217;)</em>. And that even works when it&#8217;s not a real attribute, but just one of Agent&#8217;s public methods (or anything else for that matter). Plus it&#8217;ll work for your form labels too, once you install the <a href="git://github.com/iain/i18n_label.git">i18n label plugin</a>. (One caveat though: <em>label User, :username</em> won&#8217;t work. It has to be a <em>form_for(@user) do |f|</em> and then your <em>f.label :username</em> will show the human_attribute_name).</p>

<div class="wp_syntax"><div class="code"><pre>#config/locales/en-US.yml
en-US:
  activerecord:
    models:
      agent: &quot;Agent&quot;
    attributes:
      agent:
        name: &quot;Name&quot;
        some_calculated_value: &quot;Some Calculated Value&quot;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.mokisystems.com/blog/using-rails-new-i18n-support-in-real-life-part-the-second/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
