Locos x Rails

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    4 Favorites

    Locos x Rails - Presentation Transcript

    1. I18n Rails Globalization Tuesday, April 7, 2009
    2. Fabio Akita AkitaOnRails.com Tuesday, April 7, 2009
    3. Tuesday, April 7, 2009
    4. Tuesday, April 7, 2009
    5. Tuesday, April 7, 2009
    6. Tuesday, April 7, 2009
    7. Tuesday, April 7, 2009
    8. Tuesday, April 7, 2009
    9. Tutorial-like Tuesday, April 7, 2009
    10. Tuesday, April 7, 2009
    11. I18n Before 2.2 Tuesday, April 7, 2009
    12. Chaos Tuesday, April 7, 2009
    13. Monkey Patch Approach Tuesday, April 7, 2009
    14. Many incompatible projects Tuesday, April 7, 2009
    15. Reinventing the Wheel all the time Tuesday, April 7, 2009
    16. September 2007 Tuesday, April 7, 2009
    17. Rails I18n Project Tuesday, April 7, 2009
    18. Lead from Sven Fuchs adva-cms.org Tuesday, April 7, 2009
    19. Every plugin creator gathered Tuesday, April 7, 2009
    20. Common Goals: Tuesday, April 7, 2009
    21. 100% swappable Tuesday, April 7, 2009
    22. The Least Denominator Tuesday, April 7, 2009
    23. Not a full blown L10n solution Tuesday, April 7, 2009
    24. Common, Powerful API Tuesday, April 7, 2009
    25. Simple Backend (en_US only) Tuesday, April 7, 2009
    26. Getting Started ... Tuesday, April 7, 2009
    27. rails locos Tuesday, April 7, 2009
    28. rails locos ./script/generate nifty_layout Tuesday, April 7, 2009
    29. rails locos ./script/generate nifty_layout Tuesday, April 7, 2009
    30. rails locos ./script/generate nifty_layout ./script/generate nifty_scaffold Contact name:string email:string phone:string mobile:string Tuesday, April 7, 2009
    31. rails locos ./script/generate nifty_layout ./script/generate nifty_scaffold Contact name:string email:string phone:string mobile:string Tuesday, April 7, 2009
    32. Tuesday, April 7, 2009
    33. Tuesday, April 7, 2009
    34. Tuesday, April 7, 2009
    35. Tuesday, April 7, 2009
    36. Getting i18n files Tuesday, April 7, 2009
    37. Tuesday, April 7, 2009
    38. Tuesday, April 7, 2009
    39. Tuesday, April 7, 2009
    40. config/locales/pt-BR_rails.yml Tuesday, April 7, 2009
    41. config/locales/pt-BR.rb Tuesday, April 7, 2009
    42. >> I18n.locale = :en Tuesday, April 7, 2009
    43. >> I18n.locale = :en >> I18n.translate \"hello\" => \"Hello world\" Tuesday, April 7, 2009
    44. >> I18n.locale = :en >> I18n.translate \"hello\" => \"Hello world\" >> I18n.localize Time.now => \"Wed, 01 Apr 2009 22:52:08 -0300\" Tuesday, April 7, 2009
    45. >> I18n.locale = :en >> I18n.translate \"hello\" => \"Hello world\" >> I18n.localize Time.now => \"Wed, 01 Apr 2009 22:52:08 -0300\" Tuesday, April 7, 2009
    46. >> I18n.locale = :en >> I18n.translate \"hello\" => \"Hello world\" >> I18n.localize Time.now => \"Wed, 01 Apr 2009 22:52:08 -0300\" Tuesday, April 7, 2009
    47. >> I18n.locale = :en >> I18n.t \"hello\" => \"Hello world\" >> I18n.l Time.now => \"Wed, 01 Apr 2009 22:52:08 -0300\" Tuesday, April 7, 2009
    48. >> I18n.locale = :\"pt-BR\" Tuesday, April 7, 2009
    49. >> I18n.locale = :\"pt-BR\" >> I18n.t \"hello\" => \"Alo Mundo\" Tuesday, April 7, 2009
    50. >> 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
    51. >> 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
    52. >> 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
    53. >> 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
    54. >> 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
    55. >> I18n.t [:hello, :world] => [\"alo\", \"mundo\"] Tuesday, April 7, 2009
    56. >> I18n.t [:hello, :world] => [\"alo\", \"mundo\"] >> I18n.t :brazil, :defaults => [:argentina, \"Chile\"] => \"Argentina\" Tuesday, April 7, 2009
    57. message: \"Hello, {{name}}!\" Tuesday, April 7, 2009
    58. message: \"Hello, {{name}}!\" I18n.t :message, :name => \"John\" # => \"Hello John!\" Tuesday, April 7, 2009
    59. message: \"Hello, {{name}}!\" I18n.t :message, :name => \"John\" # => \"Hello John!\" # en-US :days => { :one => \"one day\" :other => \"{{count}} days\" } Tuesday, April 7, 2009
    60. 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
    61. Extracting Strings Tuesday, April 7, 2009
    62. app/views/contacts/views/index.html.erb <tr> <th>Name</th> <th>Email</th> <th>Phone</th> <th>Mobile</th> </tr> Tuesday, April 7, 2009
    63. app/views/contacts/views/index.html.erb config/locales/pt-BR.rb <tr> <th>Name</th> <th>Email</th> <th>Phone</th> <th>Mobile</th> </tr> Tuesday, April 7, 2009
    64. app/views/contacts/views/index.html.erb config/locales/pt-BR.rb { :\"pt-BR\" => { :hello => \"Alô Mundo\", :contacts => { :index => { <tr> :name => \"Nome\", <th>Name</th> :email => \"Email\", <th>Email</th> :phone => \"Telefone\", <th>Phone</th> :mobile => \"Celular\" <th>Mobile</th> } </tr> } } } Tuesday, April 7, 2009
    65. app/views/contacts/views/index.html.erb <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> Tuesday, April 7, 2009
    66. Tuesday, April 7, 2009
    67. Tuesday, April 7, 2009
    68. config/locales/en.yml en: hello: \"Hello world\" contacts: index: name: Name email: Email phone: Phone mobile: Mobile Tuesday, April 7, 2009
    69. Tuesday, April 7, 2009
    70. Setting Locale Tuesday, April 7, 2009
    71. app/controllers/application_controller.rb class ApplicationController < ActionController::Base helper :all protect_from_forgery before_filter :set_locale private def set_locale I18n.locale = params[:locale] if params[:locale] end end Tuesday, April 7, 2009
    72. app/controllers/application_controller.rb class ApplicationController < ActionController::Base helper :all protect_from_forgery before_filter :set_locale private def set_locale I18n.locale = params[:locale] if params[:locale] end end Tuesday, April 7, 2009
    73. Tuesday, April 7, 2009
    74. Tuesday, April 7, 2009
    75. More strings Tuesday, April 7, 2009
    76. app/views/contacts/views/index.html.erb <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> Tuesday, April 7, 2009
    77. config/locales/pt-BR.rb { :\"pt-BR\" => { :hello => \"Alô Mundo\", :common => { :show => \"Mostrar\", :edit => \"Editar\", :destroy => \"Apagar\", :destroy_confirm => \"Tem certeza?\" }, ... } } Tuesday, April 7, 2009
    78. config/locales/en.yml en: hello: \"Hello world\" common: show: Show edit: Edit destroy: Destroy destroy_confirm: Are you sure? ... Tuesday, April 7, 2009
    79. Tuesday, April 7, 2009
    80. Tuesday, April 7, 2009
    81. ActiveRecord Tuesday, April 7, 2009
    82. <% 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
    83. <% 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
    84. ... :activerecord => { :models => { :contact => \"Contato\" }, :attributes => { :contact => { :name => \"Nome\", :email => \"Email\", :phone => \"Telefone\", :mobile => \"Celular\" } } } ... Tuesday, April 7, 2009
    85. Tuesday, April 7, 2009
    86. Tuesday, April 7, 2009
    87. Tuesday, April 7, 2009
    88. ./script/plugin install git://github.com/iain/i18n_label.git Tuesday, April 7, 2009
    89. Tuesday, April 7, 2009
    90. Tuesday, April 7, 2009
    91. Tuesday, April 7, 2009
    92. app/views/contacts/views/show.html.erb <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> Tuesday, April 7, 2009
    93. app/views/contacts/views/show.html.erb <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> Tuesday, April 7, 2009
    94. app/views/contacts/views/show.html.erb <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> Tuesday, April 7, 2009
    95. app/views/contacts/views/show.html.erb <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> Tuesday, April 7, 2009
    96. Tuesday, April 7, 2009
    97. app/controllers/contacts_controller.rb 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.\", }, Tuesday, April 7, 2009
    98. app/models/contact.rb class Contact < ActiveRecord::Base validates_presence_of :name end Tuesday, April 7, 2009
    99. Tuesday, April 7, 2009
    100. Routing Tuesday, April 7, 2009
    101. http://localhost:3000/pt-BR/contacts/new { :locale => :\"pt-BR\", :controller => \"contacts\", :action => \"new\"} Tuesday, April 7, 2009
    102. http://localhost:3000/pt-BR/contacts/new { :locale => :\"pt-BR\", :controller => \"contacts\", :action => \"new\"} ./script/plugin install git://github.com/svenfuchs/routing-filter.git Tuesday, April 7, 2009
    103. http://localhost:3000/pt-BR/contacts/new { :locale => :\"pt-BR\", :controller => \"contacts\", :action => \"new\"} ./script/plugin install git://github.com/svenfuchs/routing-filter.git ActionController::Routing::Routes.draw do |map| map.filter 'locale' map.resources :contacts end Tuesday, April 7, 2009
    104. http://localhost:3000/pt-BR/contacts/new { :locale => :\"pt-BR\", :controller => \"contacts\", :action => \"new\"} ./script/plugin install git://github.com/svenfuchs/routing-filter.git ActionController::Routing::Routes.draw do |map| map.filter 'locale' map.resources :contacts end Tuesday, April 7, 2009
    105. Tuesday, April 7, 2009
    106. Tuesday, April 7, 2009
    107. Tuesday, April 7, 2009
    108. Tuesday, April 7, 2009
    109. Views Tuesday, April 7, 2009
    110. ./script/generate controller page Tuesday, April 7, 2009
    111. ./script/generate controller page class PageController < ApplicationController def show render :template => params[:id] end end Tuesday, April 7, 2009
    112. ./script/generate controller page class PageController < ApplicationController def show render :template => params[:id] end end app/views/page/_header.html.erb app/views/page/about.html.erb Tuesday, April 7, 2009
    113. Tuesday, April 7, 2009
    114. app/views/page/_header.pt-BR.html.erb app/views/page/about.pt-BR.html.erb Tuesday, April 7, 2009
    115. app/views/page/_header.pt-BR.html.erb app/views/page/about.pt-BR.html.erb Tuesday, April 7, 2009
    116. app/views/page/about.html.erb <%= 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> Tuesday, April 7, 2009
    117. app/views/page/about.html.erb <%= 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.pt-BR.html.erb <%= 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> Tuesday, April 7, 2009
    118. app/views/page/about.html.erb <%= 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.pt-BR.html.erb <%= 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> Tuesday, April 7, 2009
    119. app/views/page/about.html.erb <%= 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.pt-BR.html.erb <%= 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> Tuesday, April 7, 2009
    120. app/views/page/_header.html.erb <% title \"Official Rails I18n Project Hymn\" %> <h3>Judas Priest - Painkiller</h3> app/views/page/_header.pt-BR.erb <% title \"Hino Oficial do Projeto Rails I18n\" %> <h3>Judas Priest - Painkiller</h3> Tuesday, April 7, 2009
    121. Tuesday, April 7, 2009
    122. Browser Languages Tuesday, April 7, 2009
    123. Tuesday, April 7, 2009
    124. ./script/plugin install git://github.com/iain/http_accept_language.git Tuesday, April 7, 2009
    125. ./script/plugin install git://github.com/iain/http_accept_language.git app/controllers/application_controller.rb Tuesday, April 7, 2009
    126. ./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
    127. ./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
    128. Tuesday, April 7, 2009
    129. Tuesday, April 7, 2009
    130. Tuesday, April 7, 2009
    131. Tuesday, April 7, 2009
    132. Tuesday, April 7, 2009
    133. Fast Backend Tuesday, April 7, 2009
    134. ./script/plugin install git://github.com/thedarkone/i18n.git Tuesday, April 7, 2009
    135. ./script/plugin install git://github.com/thedarkone/i18n.git I18n.backend = I18n::Backend::Fast.new Tuesday, April 7, 2009
    136. ./script/plugin install git://github.com/thedarkone/i18n.git I18n.backend = I18n::Backend::Fast.new 6 ~ 20x faster at lookups Slightly less memory efficient Slower to reload Faster for production Tuesday, April 7, 2009
    137. Globalize 2 Tuesday, April 7, 2009
    138. ./script/plugin install git://github.com/joshmh/globalize2.git Tuesday, April 7, 2009
    139. ./script/generate migration AddDescriptionFieldForContact Tuesday, April 7, 2009
    140. ./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! end end Tuesday, April 7, 2009
    141. app/models/contact.rb class Contact < ActiveRecord::Base translates :description validates_presence_of :name end Tuesday, April 7, 2009
    142. app/models/contact.rb class Contact < ActiveRecord::Base translates :description validates_presence_of :name end Tuesday, April 7, 2009
    143. app/models/contact.rb class Contact < ActiveRecord::Base translates :description validates_presence_of :name end app/views/contacts/views/_form.html.erb ... <p> <%= f.label :description %><br /> <%= f.text_area :description %> </p> <p><%= f.submit t(\"common.submit\") %></p> Tuesday, April 7, 2009
    144. Tuesday, April 7, 2009
    145. Tuesday, April 7, 2009
    146. Tuesday, April 7, 2009
    147. Tuesday, April 7, 2009
    148. Tuesday, April 7, 2009
    149. Tuesday, April 7, 2009
    150. Tuesday, April 7, 2009
    151. Tuesday, April 7, 2009
    152. Tuesday, April 7, 2009
    153. config/initializers/globalize.rb I18n.fallbacks[:en] Tuesday, April 7, 2009
    154. Tuesday, April 7, 2009
    155. Tuesday, April 7, 2009
    156. Tuesday, April 7, 2009
    157. Tuesday, April 7, 2009
    158. Tuesday, April 7, 2009
    159. Globalize2 • Model Translation • Custom Pluralization • Locale Fallbacks • Globalize::LoadPath • Globalize::Translation classes • Missing Translation Log Handler Tuesday, April 7, 2009
    160. 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
    161. git clone git://github.com/akitaonrails/locosxrails_i18n_demo.git Tuesday, April 7, 2009
    162. Muchas Gracias! www.akitaonrails.com fabioakita@gmail.com Tuesday, April 7, 2009

    + Fabio AkitaFabio Akita, 7 months ago

    custom

    1432 views, 4 favs, 4 embeds more stats

    My talk at Locos x Rails, in Argentina, about Rails more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 1432
      • 1341 on SlideShare
      • 91 from embeds
    • Comments 0
    • Favorites 4
    • Downloads 28
    Most viewed embeds
    • 56 views on http://www.akitaonrails.com
    • 31 views on http://akitaonrails.com
    • 3 views on http://www.slideshare.net
    • 1 views on http://www.rubyonrails.pro.br

    more

    All embeds
    • 56 views on http://www.akitaonrails.com
    • 31 views on http://akitaonrails.com
    • 3 views on http://www.slideshare.net
    • 1 views on http://www.rubyonrails.pro.br

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories