`
Hooopo
  • 浏览: 328964 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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: "你好!"




参考: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
  • 大小: 22.3 KB
  • 大小: 21 KB
0
0
分享到:
评论
1 楼 jinleileiking 2009-08-03  
消灭0回复!怎么把你的文章搞到圈子里。。?

相关推荐

Global site tag (gtag.js) - Google Analytics