<?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/"
		xmlns:xhtml="http://www.w3.org/1999/xhtml"
>

<channel>
	<title>imishin.com &#187; i18n</title>
	<atom:link href="http://blog.imishin.com/tag/i18n/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.imishin.com</link>
	<description></description>
	<lastBuildDate>Thu, 05 May 2011 16:30:31 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://blog.imishin.com/tag/i18n/feed/" />
		<item>
		<title>Rails 2.2 の i18n を使ってみた</title>
		<link>http://blog.imishin.com/2009/01/09/rails-2-2-i18n/</link>
		<comments>http://blog.imishin.com/2009/01/09/rails-2-2-i18n/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 08:49:32 +0000</pubDate>
		<dc:creator>kusakari</dc:creator>
				<category><![CDATA[RubyOnRails]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.imishin.com/?p=330</guid>
		<description><![CDATA[Rails 2.2.2 で i18n を使ってみました。 前評判はイマイチだったので、どんな感じなのかなと思っていたけど、個人的には GetText より好きです。 手順としてはプロジェクトを作成して、scaffold  [...]]]></description>
			<content:encoded><![CDATA[<p>Rails 2.2.2 で i18n を使ってみました。</p>
<p>前評判はイマイチだったので、どんな感じなのかなと思っていたけど、個人的には GetText より好きです。</p>
<p><span id="more-330"></span></p>
<p>手順としてはプロジェクトを作成して、scaffold を実行した後、以下を実行します。</p>
<pre name="code" class="ruby">gem so -a http://gems.github.com
gem install amatsuda-i18n_generators
ruby script/generate i18n ja</pre>
<p>ただ、これだけでは、一部問題がありエラーメッセージが日本語化されないようです。（amatsuda-i18n_generators v0.4）</p>
<p>ということで、生成後の yml を3行消します。</p>
<h3>config/locales/ja.yml</h3>
<pre name="code" class="ruby">ja:
（省略）
  activerecord:
    errors:
      template:
        header:
          one:   "{{model}}にエラーが発生しました。"
          other: "{{model}}に{{count}}つのエラーが発生しました。"
-  activerecord:
-    errors:
-      template:
        body: "次の項目を確認してください。"

      messages:
（省略）</pre>
<p>
これで日本語化できました。簡単ですね。
</p>
<h3>label の日本語化</h3>
<p>これだけでは label は日本語化されないみたいなので、label の日本語化を作ってみた。<br />
config/initializers/libs.rb</p>
<pre name="code" class="ruby">
require 'active_record_helper'
</pre>
<p>lib/active_record_helper.rb</p>
<pre name="code" class="ruby">
module ActionView
  module Helpers
    module FormHelper
      def label_with_ja(object_name, method, text = nil, options = {})
        if text.nil?
          text = I18n.t(method, :default => method, :scope => [:activerecord, :attributes, object_name])
        end
        label_without_ja(object_name, method, text, options)
      end
      alias_method_chain :label, :ja  #:nodoc:
    end
  end
end
</pre>
<p>これで label も translation_ja.yml で指定した attributes 名が表示されます。</p>
<h3>参考</h3>
<ul>
<li><a href="http://blog.dio.jp/2008/11/22/japanizing-rails-2-2-by-i18n-generators" target="_blank">Close to the EDGE Rails 2.2の I18nによる日本語化を最も簡単に行う方法</a></li>
<li><a href="http://ukstudio.jp/2008/11/26/rails_22_i18n/" target="_blank">UK STUDIO &#8211; Rails2.2のi18n(国際化)を簡単に試してみた</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.imishin.com/2009/01/09/rails-2-2-i18n/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://blog.imishin.com/2009/01/09/rails-2-2-i18n/" />
	</item>
	</channel>
</rss>

