I18n for Rails之hello world

平台:rails 2.3.2 ruby 1.8.6
1.
rails i18n -d mysql

2.
rake db:create

3.
ruby script/generate controller Home index

4.在浏览器http://localhost:3000/ ,基本坏境搭建完成,下面折腾I18n
5.编辑application.rb,加上这句:

before_filter :set_locale
def set_locale
  # if params[:locale] is nil then I18n.default_locale will be used
  I18n.locale = params[:locale]
end

6.views/home/index.html.erb:
<h1><%= t(:hello) %></h1>
<p><%= flash[:notice] %></p>




7.home_controller.rb
class HomeController < ApplicationController
  def index
    flash[:notice] = t(:hello)
  end

end



8.environment.rb
 config.i18n.default_locale = :cn


9.config/locales/en.yml
en:
  hello: "Hello world"


10.config/locales/cn.yml
cn:
  hello: "你好!"

I18n for Rails之hello world
I18n for Rails之hello world

参考: http://guides.rubyonrails.org/i18n.html
http://rails-i18n.org/wiki/wikipages/i18n-rails-guide
http://guides.rubyonrails.org/testing.html
http://www.iteye.com/topic/408107

你可能感兴趣的:(java,mysql,Flash,Ruby,Rails)