locos x rails
DESCRIPTION
My talk at Locos x Rails, in Argentina, about Rails I18n (internationalization) support, tips and tricks.TRANSCRIPT
![Page 1: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/1.jpg)
I18nRails Globalization
Tuesday, April 7, 2009
![Page 2: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/2.jpg)
Fabio Akita
AkitaOnRails.com
Tuesday, April 7, 2009
![Page 3: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/3.jpg)
Tuesday, April 7, 2009
![Page 4: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/4.jpg)
Tuesday, April 7, 2009
![Page 5: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/5.jpg)
Tuesday, April 7, 2009
![Page 6: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/6.jpg)
Tuesday, April 7, 2009
![Page 7: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/7.jpg)
Tuesday, April 7, 2009
![Page 8: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/8.jpg)
Tuesday, April 7, 2009
![Page 9: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/9.jpg)
Tutorial-like
Tuesday, April 7, 2009
![Page 10: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/10.jpg)
Tuesday, April 7, 2009
![Page 11: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/11.jpg)
I18n Before 2.2
Tuesday, April 7, 2009
![Page 12: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/12.jpg)
Chaos
Tuesday, April 7, 2009
![Page 13: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/13.jpg)
Monkey Patch Approach
Tuesday, April 7, 2009
![Page 14: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/14.jpg)
Many incompatible
projects
Tuesday, April 7, 2009
![Page 15: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/15.jpg)
Reinventing the Wheel all the time
Tuesday, April 7, 2009
![Page 16: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/16.jpg)
September 2007
Tuesday, April 7, 2009
![Page 17: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/17.jpg)
Rails I18n Project
Tuesday, April 7, 2009
![Page 18: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/18.jpg)
Lead fromSven Fuchs
adva-cms.org
Tuesday, April 7, 2009
![Page 19: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/19.jpg)
Every plugin creator gathered
Tuesday, April 7, 2009
![Page 20: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/20.jpg)
Common Goals:
Tuesday, April 7, 2009
![Page 21: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/21.jpg)
100% swappable
Tuesday, April 7, 2009
![Page 22: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/22.jpg)
The Least Denominator
Tuesday, April 7, 2009
![Page 23: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/23.jpg)
Not a full blown L10n solution
Tuesday, April 7, 2009
![Page 24: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/24.jpg)
Common, Powerful API
Tuesday, April 7, 2009
![Page 25: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/25.jpg)
Simple Backend(en_US only)
Tuesday, April 7, 2009
![Page 26: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/26.jpg)
Getting Started ...
Tuesday, April 7, 2009
![Page 27: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/27.jpg)
rails locos
Tuesday, April 7, 2009
![Page 28: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/28.jpg)
rails locos
./script/generate nifty_layout
Tuesday, April 7, 2009
![Page 29: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/29.jpg)
rails locos
./script/generate nifty_layout
Tuesday, April 7, 2009
![Page 30: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/30.jpg)
rails locos
./script/generate nifty_layout
./script/generate nifty_scaffold Contact name:string email:string phone:string mobile:string
Tuesday, April 7, 2009
![Page 31: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/31.jpg)
rails locos
./script/generate nifty_layout
./script/generate nifty_scaffold Contact name:string email:string phone:string mobile:string
Tuesday, April 7, 2009
![Page 32: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/32.jpg)
Tuesday, April 7, 2009
![Page 33: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/33.jpg)
Tuesday, April 7, 2009
![Page 34: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/34.jpg)
Tuesday, April 7, 2009
![Page 35: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/35.jpg)
Tuesday, April 7, 2009
![Page 36: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/36.jpg)
Getting i18n files
Tuesday, April 7, 2009
![Page 37: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/37.jpg)
Tuesday, April 7, 2009
![Page 38: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/38.jpg)
Tuesday, April 7, 2009
![Page 39: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/39.jpg)
Tuesday, April 7, 2009
![Page 40: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/40.jpg)
config/locales/pt-BR_rails.yml
Tuesday, April 7, 2009
![Page 41: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/41.jpg)
config/locales/pt-BR.rb
Tuesday, April 7, 2009
![Page 42: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/42.jpg)
>> I18n.locale = :en
Tuesday, April 7, 2009
![Page 43: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/43.jpg)
>> I18n.locale = :en
>> I18n.translate "hello"=> "Hello world"
Tuesday, April 7, 2009
![Page 44: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/44.jpg)
>> I18n.locale = :en
>> I18n.translate "hello"=> "Hello world"
>> I18n.localize Time.now=> "Wed, 01 Apr 2009 22:52:08 -0300"
Tuesday, April 7, 2009
![Page 45: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/45.jpg)
>> I18n.locale = :en
>> I18n.translate "hello"=> "Hello world"
>> I18n.localize Time.now=> "Wed, 01 Apr 2009 22:52:08 -0300"
Tuesday, April 7, 2009
![Page 46: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/46.jpg)
>> I18n.locale = :en
>> I18n.translate "hello"=> "Hello world"
>> I18n.localize Time.now=> "Wed, 01 Apr 2009 22:52:08 -0300"
Tuesday, April 7, 2009
![Page 47: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/47.jpg)
>> I18n.locale = :en
>> I18n.t "hello"=> "Hello world"
>> I18n.l Time.now=> "Wed, 01 Apr 2009 22:52:08 -0300"
Tuesday, April 7, 2009
![Page 48: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/48.jpg)
>> I18n.locale = :"pt-BR"
Tuesday, April 7, 2009
![Page 49: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/49.jpg)
>> I18n.locale = :"pt-BR"
>> I18n.t "hello"=> "Alo Mundo"
Tuesday, April 7, 2009
![Page 50: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/50.jpg)
>> I18n.locale = :"pt-BR"
>> I18n.t "hello"=> "Alo Mundo"
>> I18n.l Time.now=> "Quarta, 01 de Abril de 2009, 22:49 hs"
Tuesday, April 7, 2009
![Page 51: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/51.jpg)
>> I18n.locale = :"pt-BR"
>> I18n.t "hello"=> "Alo Mundo"
>> I18n.l Time.now=> "Quarta, 01 de Abril de 2009, 22:49 hs"
>> I18n.l Time.now, :format => :short=> "01/04, 22:52 hs"
Tuesday, April 7, 2009
![Page 52: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/52.jpg)
>> I18n.locale = :"pt-BR"
>> I18n.t "hello"=> "Alo Mundo"
>> I18n.l Time.now=> "Quarta, 01 de Abril de 2009, 22:49 hs"
>> I18n.l Time.now, :format => :short=> "01/04, 22:52 hs"
Tuesday, April 7, 2009
![Page 53: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/53.jpg)
>> time_ago_in_words(1.month.ago)=> "about 1 month">> time_ago_in_words(1.5.hours.ago)=> "about 2 hours"
Tuesday, April 7, 2009
![Page 54: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/54.jpg)
>> time_ago_in_words(1.month.ago)=> "about 1 month">> time_ago_in_words(1.5.hours.ago)=> "about 2 hours"
>> I18n.locale = :"pt-BR"
>> time_ago_in_words(1.month.ago)=> "aproximadamente 1 mês">> time_ago_in_words(1.5.hours.ago)=> "aproximadamente 2 horas"
Tuesday, April 7, 2009
![Page 55: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/55.jpg)
>> I18n.t [:hello, :world]=> ["alo", "mundo"]
Tuesday, April 7, 2009
![Page 56: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/56.jpg)
>> I18n.t [:hello, :world]=> ["alo", "mundo"]
>> I18n.t :brazil, :defaults => [:argentina, "Chile"]=> "Argentina"
Tuesday, April 7, 2009
![Page 57: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/57.jpg)
message: "Hello, {{name}}!"
Tuesday, April 7, 2009
![Page 58: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/58.jpg)
message: "Hello, {{name}}!"
I18n.t :message, :name => "John" # => "Hello John!"
Tuesday, April 7, 2009
![Page 59: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/59.jpg)
message: "Hello, {{name}}!"
I18n.t :message, :name => "John" # => "Hello John!"
# en-US :days => { :one => "one day" :other => "{{count}} days" }
Tuesday, April 7, 2009
![Page 60: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/60.jpg)
message: "Hello, {{name}}!"
I18n.t :message, :name => "John" # => "Hello John!"
# en-US :days => { :one => "one day" :other => "{{count}} days" }
I18n.t :days, :count => 1 # => "one day" I18n.t :days, :count => 2 # => "2 days"
Tuesday, April 7, 2009
![Page 61: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/61.jpg)
Extracting Strings
Tuesday, April 7, 2009
![Page 62: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/62.jpg)
<tr> <th>Name</th> <th>Email</th> <th>Phone</th> <th>Mobile</th></tr>
app/views/contacts/views/index.html.erb
Tuesday, April 7, 2009
![Page 63: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/63.jpg)
<tr> <th>Name</th> <th>Email</th> <th>Phone</th> <th>Mobile</th></tr>
app/views/contacts/views/index.html.erb
config/locales/pt-BR.rb
Tuesday, April 7, 2009
![Page 64: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/64.jpg)
<tr> <th>Name</th> <th>Email</th> <th>Phone</th> <th>Mobile</th></tr>
app/views/contacts/views/index.html.erb
config/locales/pt-BR.rb{ :"pt-BR" => { :hello => "Alô Mundo", :contacts => { :index => { :name => "Nome", :email => "Email", :phone => "Telefone", :mobile => "Celular" } } }}
Tuesday, April 7, 2009
![Page 65: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/65.jpg)
<tr> <th><%= t("contacts.index.name") %></th> <th><%= t("index.email", :scope => "contacts") %></th> <th><%= t("phone", :scope => "contacts.index") %></th> <th><%= t(".mobile") %></th></tr>
app/views/contacts/views/index.html.erb
Tuesday, April 7, 2009
![Page 66: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/66.jpg)
Tuesday, April 7, 2009
![Page 67: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/67.jpg)
Tuesday, April 7, 2009
![Page 68: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/68.jpg)
en: hello: "Hello world" contacts: index: name: Name email: Email phone: Phone mobile: Mobile
config/locales/en.yml
Tuesday, April 7, 2009
![Page 69: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/69.jpg)
Tuesday, April 7, 2009
![Page 70: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/70.jpg)
Setting Locale
Tuesday, April 7, 2009
![Page 71: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/71.jpg)
class ApplicationController < ActionController::Base helper :all protect_from_forgery before_filter :set_locale private def set_locale I18n.locale = params[:locale] if params[:locale] endend
app/controllers/application_controller.rb
Tuesday, April 7, 2009
![Page 72: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/72.jpg)
class ApplicationController < ActionController::Base helper :all protect_from_forgery before_filter :set_locale private def set_locale I18n.locale = params[:locale] if params[:locale] endend
app/controllers/application_controller.rb
Tuesday, April 7, 2009
![Page 73: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/73.jpg)
Tuesday, April 7, 2009
![Page 74: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/74.jpg)
Tuesday, April 7, 2009
![Page 75: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/75.jpg)
More strings
Tuesday, April 7, 2009
![Page 76: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/76.jpg)
<td><%= link_to t("common.show"), contact %></td><td><%= link_to t("common.edit"), edit_contact_path(contact) %></td><td><%= link_to t("common.destroy"), contact, :confirm => t('common.destroy_confirm'), :method => :delete %></td>
app/views/contacts/views/index.html.erb
Tuesday, April 7, 2009
![Page 77: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/77.jpg)
{ :"pt-BR" => { :hello => "Alô Mundo", :common => { :show => "Mostrar", :edit => "Editar", :destroy => "Apagar", :destroy_confirm => "Tem certeza?" }, ... }}
config/locales/pt-BR.rb
Tuesday, April 7, 2009
![Page 78: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/78.jpg)
en: hello: "Hello world"
common: show: Show edit: Edit destroy: Destroy destroy_confirm: Are you sure? ...
config/locales/en.yml
Tuesday, April 7, 2009
![Page 79: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/79.jpg)
Tuesday, April 7, 2009
![Page 80: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/80.jpg)
Tuesday, April 7, 2009
![Page 81: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/81.jpg)
ActiveRecord
Tuesday, April 7, 2009
![Page 82: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/82.jpg)
<% form_for @contact do |f| %> <%= f.error_messages %> <p> <%= f.label :name %><br /> <%= f.text_field :name %> </p> <p> <%= f.label :email %><br /> <%= f.text_field :email %> </p> <p> <%= f.label :phone %><br /> <%= f.text_field :phone %> </p> <p> <%= f.label :mobile %><br /> <%= f.text_field :mobile %> </p> <p><%= f.submit t("common.submit") %></p><% end %>
Tuesday, April 7, 2009
![Page 83: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/83.jpg)
<% form_for @contact do |f| %> <%= f.error_messages %> <p> <%= f.label :name %><br /> <%= f.text_field :name %> </p> <p> <%= f.label :email %><br /> <%= f.text_field :email %> </p> <p> <%= f.label :phone %><br /> <%= f.text_field :phone %> </p> <p> <%= f.label :mobile %><br /> <%= f.text_field :mobile %> </p> <p><%= f.submit t("common.submit") %></p><% end %>
Tuesday, April 7, 2009
![Page 84: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/84.jpg)
...:activerecord => { :models => { :contact => "Contato" }, :attributes => { :contact => { :name => "Nome", :email => "Email", :phone => "Telefone", :mobile => "Celular" } }}...
Tuesday, April 7, 2009
![Page 85: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/85.jpg)
Tuesday, April 7, 2009
![Page 86: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/86.jpg)
Tuesday, April 7, 2009
![Page 87: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/87.jpg)
Tuesday, April 7, 2009
![Page 88: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/88.jpg)
./script/plugin install git://github.com/iain/i18n_label.git
Tuesday, April 7, 2009
![Page 89: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/89.jpg)
Tuesday, April 7, 2009
![Page 90: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/90.jpg)
Tuesday, April 7, 2009
![Page 91: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/91.jpg)
Tuesday, April 7, 2009
![Page 92: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/92.jpg)
<p> <strong>Name:</strong> <%=h @contact.name %></p><p> <strong>Email:</strong> <%=h @contact.email %></p><p> <strong>Phone:</strong> <%=h @contact.phone %></p><p> <strong>Mobile:</strong> <%=h @contact.mobile %></p>
app/views/contacts/views/show.html.erb
Tuesday, April 7, 2009
![Page 93: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/93.jpg)
<p> <strong>Name:</strong> <%=h @contact.name %></p><p> <strong>Email:</strong> <%=h @contact.email %></p><p> <strong>Phone:</strong> <%=h @contact.phone %></p><p> <strong>Mobile:</strong> <%=h @contact.mobile %></p>
app/views/contacts/views/show.html.erb
Tuesday, April 7, 2009
![Page 94: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/94.jpg)
<p> <strong><%= Contact.human_attribute_name('name') %>:</strong> <%=h @contact.name %></p><p> <strong><%= Contact.human_attribute_name('email') %>:</strong> <%=h @contact.email %></p><p> <strong><%= Contact.human_attribute_name('phone') %>:</strong> <%=h @contact.phone %></p><p> <strong><%= Contact.human_attribute_name('mobile') %>:</strong> <%=h @contact.mobile %></p>
app/views/contacts/views/show.html.erb
Tuesday, April 7, 2009
![Page 95: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/95.jpg)
<p> <strong><%= Contact.human_attribute_name('name') %>:</strong> <%=h @contact.name %></p><p> <strong><%= Contact.human_attribute_name('email') %>:</strong> <%=h @contact.email %></p><p> <strong><%= Contact.human_attribute_name('phone') %>:</strong> <%=h @contact.phone %></p><p> <strong><%= Contact.human_attribute_name('mobile') %>:</strong> <%=h @contact.mobile %></p>
app/views/contacts/views/show.html.erb
Tuesday, April 7, 2009
![Page 96: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/96.jpg)
Tuesday, April 7, 2009
![Page 97: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/97.jpg)
flash[:notice] = "Successfully created contact."
flash[:notice] = t("contacts.messages.successful_create")
messages: successful_create: Successfully created contact. successful_update: Successfully updated contact. successful_destroy: Successfully destroyed contact.
:messages => { :successful_create => "Contato criado com sucesso.", :successful_update => "Contato atualizado com sucesso.", :successful_destroy => "Contato apagado com sucesso.",},
app/controllers/contacts_controller.rb
Tuesday, April 7, 2009
![Page 98: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/98.jpg)
class Contact < ActiveRecord::Base validates_presence_of :nameend
app/models/contact.rb
Tuesday, April 7, 2009
![Page 99: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/99.jpg)
Tuesday, April 7, 2009
![Page 100: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/100.jpg)
Routing
Tuesday, April 7, 2009
![Page 101: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/101.jpg)
http://localhost:3000/pt-BR/contacts/new
{ :locale => :"pt-BR", :controller => "contacts", :action => "new"}
Tuesday, April 7, 2009
![Page 102: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/102.jpg)
./script/plugin install git://github.com/svenfuchs/routing-filter.git
http://localhost:3000/pt-BR/contacts/new
{ :locale => :"pt-BR", :controller => "contacts", :action => "new"}
Tuesday, April 7, 2009
![Page 103: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/103.jpg)
./script/plugin install git://github.com/svenfuchs/routing-filter.git
ActionController::Routing::Routes.draw do |map| map.filter 'locale' map.resources :contactsend
http://localhost:3000/pt-BR/contacts/new
{ :locale => :"pt-BR", :controller => "contacts", :action => "new"}
Tuesday, April 7, 2009
![Page 104: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/104.jpg)
./script/plugin install git://github.com/svenfuchs/routing-filter.git
ActionController::Routing::Routes.draw do |map| map.filter 'locale' map.resources :contactsend
http://localhost:3000/pt-BR/contacts/new
{ :locale => :"pt-BR", :controller => "contacts", :action => "new"}
Tuesday, April 7, 2009
![Page 105: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/105.jpg)
Tuesday, April 7, 2009
![Page 106: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/106.jpg)
Tuesday, April 7, 2009
![Page 107: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/107.jpg)
Tuesday, April 7, 2009
![Page 108: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/108.jpg)
Tuesday, April 7, 2009
![Page 109: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/109.jpg)
Views
Tuesday, April 7, 2009
![Page 110: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/110.jpg)
./script/generate controller page
Tuesday, April 7, 2009
![Page 111: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/111.jpg)
./script/generate controller page
class PageController < ApplicationController def show render :template => params[:id] endend
Tuesday, April 7, 2009
![Page 112: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/112.jpg)
./script/generate controller page
class PageController < ApplicationController def show render :template => params[:id] endend
app/views/page/_header.html.erbapp/views/page/about.html.erb
Tuesday, April 7, 2009
![Page 113: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/113.jpg)
Tuesday, April 7, 2009
![Page 114: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/114.jpg)
app/views/page/_header.pt-BR.html.erbapp/views/page/about.pt-BR.html.erb
Tuesday, April 7, 2009
![Page 115: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/115.jpg)
app/views/page/_header.pt-BR.html.erbapp/views/page/about.pt-BR.html.erb
Tuesday, April 7, 2009
![Page 116: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/116.jpg)
<%= render :partial => "header" %>
<p>Faster than a bullet<br/>Terrifying scream<br/>Enraged and full of anger<br/>He’s half man and half machine</p>
app/views/page/about.html.erb
Tuesday, April 7, 2009
![Page 117: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/117.jpg)
<%= render :partial => "header" %>
<p>Faster than a bullet<br/>Terrifying scream<br/>Enraged and full of anger<br/>He’s half man and half machine</p>
<%= render :partial => "header" %>
<p>Mais rápido que uma bala<br/>Um grito apavorante<br/>Enfurecido e cheio de raiva<br/>Ele é metade homem, metade máquina</p>
app/views/page/about.html.erb
app/views/page/about.pt-BR.html.erb
Tuesday, April 7, 2009
![Page 118: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/118.jpg)
<%= render :partial => "header" %>
<p>Faster than a bullet<br/>Terrifying scream<br/>Enraged and full of anger<br/>He’s half man and half machine</p>
<%= render :partial => "header" %>
<p>Mais rápido que uma bala<br/>Um grito apavorante<br/>Enfurecido e cheio de raiva<br/>Ele é metade homem, metade máquina</p>
app/views/page/about.html.erb
app/views/page/about.pt-BR.html.erb
Tuesday, April 7, 2009
![Page 119: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/119.jpg)
<%= render :partial => "header" %>
<p>Faster than a bullet<br/>Terrifying scream<br/>Enraged and full of anger<br/>He’s half man and half machine</p>
<%= render :partial => "header" %>
<p>Mais rápido que uma bala<br/>Um grito apavorante<br/>Enfurecido e cheio de raiva<br/>Ele é metade homem, metade máquina</p>
app/views/page/about.html.erb
app/views/page/about.pt-BR.html.erb
Tuesday, April 7, 2009
![Page 120: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/120.jpg)
<% title "Hino Oficial do Projeto Rails I18n" %><h3>Judas Priest - Painkiller</h3>
<% title "Official Rails I18n Project Hymn" %><h3>Judas Priest - Painkiller</h3>
app/views/page/_header.html.erb
app/views/page/_header.pt-BR.erb
Tuesday, April 7, 2009
![Page 121: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/121.jpg)
Tuesday, April 7, 2009
![Page 122: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/122.jpg)
Browser Languages
Tuesday, April 7, 2009
![Page 123: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/123.jpg)
Tuesday, April 7, 2009
![Page 124: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/124.jpg)
./script/plugin install git://github.com/iain/http_accept_language.git
Tuesday, April 7, 2009
![Page 125: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/125.jpg)
./script/plugin install git://github.com/iain/http_accept_language.git
app/controllers/application_controller.rb
Tuesday, April 7, 2009
![Page 126: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/126.jpg)
./script/plugin install git://github.com/iain/http_accept_language.git
app/controllers/application_controller.rb
def set_locale # comment the next line to disable http_accept_language recognition params[:locale] = request.compatible_language_from( I18n.available_locales) unless params[:locale] I18n.locale = params[:locale] if params[:locale]end
Tuesday, April 7, 2009
![Page 127: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/127.jpg)
./script/plugin install git://github.com/iain/http_accept_language.git
app/controllers/application_controller.rb
def set_locale # comment the next line to disable http_accept_language recognition params[:locale] = request.compatible_language_from( I18n.available_locales) unless params[:locale] I18n.locale = params[:locale] if params[:locale]end
Tuesday, April 7, 2009
![Page 128: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/128.jpg)
Tuesday, April 7, 2009
![Page 129: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/129.jpg)
Tuesday, April 7, 2009
![Page 130: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/130.jpg)
Tuesday, April 7, 2009
![Page 131: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/131.jpg)
Tuesday, April 7, 2009
![Page 132: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/132.jpg)
Tuesday, April 7, 2009
![Page 133: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/133.jpg)
Fast Backend
Tuesday, April 7, 2009
![Page 134: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/134.jpg)
./script/plugin install git://github.com/thedarkone/i18n.git
Tuesday, April 7, 2009
![Page 135: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/135.jpg)
./script/plugin install git://github.com/thedarkone/i18n.git
I18n.backend = I18n::Backend::Fast.new
Tuesday, April 7, 2009
![Page 136: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/136.jpg)
./script/plugin install git://github.com/thedarkone/i18n.git
6 ~ 20x faster at lookups
Slightly less memory efficient
Slower to reload
Faster for production
I18n.backend = I18n::Backend::Fast.new
Tuesday, April 7, 2009
![Page 137: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/137.jpg)
Globalize 2
Tuesday, April 7, 2009
![Page 138: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/138.jpg)
./script/plugin install git://github.com/joshmh/globalize2.git
Tuesday, April 7, 2009
![Page 139: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/139.jpg)
./script/generate migration AddDescriptionFieldForContact
Tuesday, April 7, 2009
![Page 140: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/140.jpg)
./script/generate migration AddDescriptionFieldForContact
class AddDescriptionFieldForContact < ActiveRecord::Migration def self.up add_column :contacts, :description, :text Contact.create_translation_table! :description => :text end
def self.down remove_column :contacts, :description Contact.drop_translation_table! endend
Tuesday, April 7, 2009
![Page 141: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/141.jpg)
class Contact < ActiveRecord::Base translates :description validates_presence_of :nameend
app/models/contact.rb
Tuesday, April 7, 2009
![Page 142: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/142.jpg)
class Contact < ActiveRecord::Base translates :description validates_presence_of :nameend
app/models/contact.rb
Tuesday, April 7, 2009
![Page 143: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/143.jpg)
class Contact < ActiveRecord::Base translates :description validates_presence_of :nameend
...<p> <%= f.label :description %><br /> <%= f.text_area :description %></p><p><%= f.submit t("common.submit") %></p>
app/models/contact.rb
app/views/contacts/views/_form.html.erb
Tuesday, April 7, 2009
![Page 144: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/144.jpg)
Tuesday, April 7, 2009
![Page 145: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/145.jpg)
Tuesday, April 7, 2009
![Page 146: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/146.jpg)
Tuesday, April 7, 2009
![Page 147: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/147.jpg)
Tuesday, April 7, 2009
![Page 148: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/148.jpg)
Tuesday, April 7, 2009
![Page 149: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/149.jpg)
Tuesday, April 7, 2009
![Page 150: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/150.jpg)
Tuesday, April 7, 2009
![Page 151: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/151.jpg)
Tuesday, April 7, 2009
![Page 152: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/152.jpg)
Tuesday, April 7, 2009
![Page 153: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/153.jpg)
I18n.fallbacks[:en]
config/initializers/globalize.rb
Tuesday, April 7, 2009
![Page 154: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/154.jpg)
Tuesday, April 7, 2009
![Page 155: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/155.jpg)
Tuesday, April 7, 2009
![Page 156: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/156.jpg)
Tuesday, April 7, 2009
![Page 157: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/157.jpg)
Tuesday, April 7, 2009
![Page 158: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/158.jpg)
Tuesday, April 7, 2009
![Page 159: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/159.jpg)
Globalize2
• Model Translation
• Custom Pluralization
• Locale Fallbacks
• Globalize::LoadPath
• Globalize::Translation classes
• Missing Translation Log Handler
Tuesday, April 7, 2009
![Page 160: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/160.jpg)
More Resources• Gettext
• Masao’s Mutoh
• http://github.com/mutoh/gettext
• Fernando Blat
• http://github.com/ferblape/i18n_gettext
• http://guides.rails.info/i18n.html
• http://rails-i18n.org/
Tuesday, April 7, 2009
![Page 161: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/161.jpg)
git clone git://github.com/akitaonrails/locosxrails_i18n_demo.git
Tuesday, April 7, 2009
![Page 162: Locos x Rails](https://reader034.vdocuments.net/reader034/viewer/2022042601/54bd17994a7959ff308b4649/html5/thumbnails/162.jpg)
Muchas Gracias!
Tuesday, April 7, 2009