Locos x Rails

50 %
50 %
Information about Locos x Rails
Technology

Published on April 7, 2009

Author: akitaonrails

Source: slideshare.net

Description

My talk at Locos x Rails, in Argentina, about Rails I18n (internationalization) support, tips and tricks.

I18n Rails Globalization Tuesday, April 7, 2009

Fabio Akita AkitaOnRails.com Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tutorial-like Tuesday, April 7, 2009

Tuesday, April 7, 2009

I18n Before 2.2 Tuesday, April 7, 2009

Chaos Tuesday, April 7, 2009

Monkey Patch Approach Tuesday, April 7, 2009

Many incompatible projects Tuesday, April 7, 2009

Reinventing the Wheel all the time Tuesday, April 7, 2009

September 2007 Tuesday, April 7, 2009

Rails I18n Project Tuesday, April 7, 2009

Lead from Sven Fuchs adva-cms.org Tuesday, April 7, 2009

Every plugin creator gathered Tuesday, April 7, 2009

Common Goals: Tuesday, April 7, 2009

100% swappable Tuesday, April 7, 2009

The Least Denominator Tuesday, April 7, 2009

Not a full blown L10n solution Tuesday, April 7, 2009

Common, Powerful API Tuesday, April 7, 2009

Simple Backend (en_US only) Tuesday, April 7, 2009

Getting Started ... Tuesday, April 7, 2009

rails locos Tuesday, April 7, 2009

rails locos ./script/generate nifty_layout Tuesday, April 7, 2009

rails locos ./script/generate nifty_layout Tuesday, April 7, 2009

rails locos ./script/generate nifty_layout ./script/generate nifty_scaffold Contact name:string email:string phone:string mobile:string Tuesday, April 7, 2009

rails locos ./script/generate nifty_layout ./script/generate nifty_scaffold Contact name:string email:string phone:string mobile:string Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Getting i18n files Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

config/locales/pt-BR_rails.yml Tuesday, April 7, 2009

config/locales/pt-BR.rb Tuesday, April 7, 2009

>> I18n.locale = :en Tuesday, April 7, 2009

>> I18n.locale = :en >> I18n.translate quot;helloquot; => quot;Hello worldquot; Tuesday, April 7, 2009

>> I18n.locale = :en >> I18n.translate quot;helloquot; => quot;Hello worldquot; >> I18n.localize Time.now => quot;Wed, 01 Apr 2009 22:52:08 -0300quot; Tuesday, April 7, 2009

>> I18n.locale = :en >> I18n.translate quot;helloquot; => quot;Hello worldquot; >> I18n.localize Time.now => quot;Wed, 01 Apr 2009 22:52:08 -0300quot; Tuesday, April 7, 2009

>> I18n.locale = :en >> I18n.translate quot;helloquot; => quot;Hello worldquot; >> I18n.localize Time.now => quot;Wed, 01 Apr 2009 22:52:08 -0300quot; Tuesday, April 7, 2009

>> I18n.locale = :en >> I18n.t quot;helloquot; => quot;Hello worldquot; >> I18n.l Time.now => quot;Wed, 01 Apr 2009 22:52:08 -0300quot; Tuesday, April 7, 2009

>> I18n.locale = :quot;pt-BRquot; Tuesday, April 7, 2009

>> I18n.locale = :quot;pt-BRquot; >> I18n.t quot;helloquot; => quot;Alo Mundoquot; Tuesday, April 7, 2009

>> I18n.locale = :quot;pt-BRquot; >> I18n.t quot;helloquot; => quot;Alo Mundoquot; >> I18n.l Time.now => quot;Quarta, 01 de Abril de 2009, 22:49 hsquot; Tuesday, April 7, 2009

>> I18n.locale = :quot;pt-BRquot; >> I18n.t quot;helloquot; => quot;Alo Mundoquot; >> I18n.l Time.now => quot;Quarta, 01 de Abril de 2009, 22:49 hsquot; >> I18n.l Time.now, :format => :short => quot;01/04, 22:52 hsquot; Tuesday, April 7, 2009

>> I18n.locale = :quot;pt-BRquot; >> I18n.t quot;helloquot; => quot;Alo Mundoquot; >> I18n.l Time.now => quot;Quarta, 01 de Abril de 2009, 22:49 hsquot; >> I18n.l Time.now, :format => :short => quot;01/04, 22:52 hsquot; Tuesday, April 7, 2009

>> time_ago_in_words(1.month.ago) => quot;about 1 monthquot; >> time_ago_in_words(1.5.hours.ago) => quot;about 2 hoursquot; Tuesday, April 7, 2009

>> time_ago_in_words(1.month.ago) => quot;about 1 monthquot; >> time_ago_in_words(1.5.hours.ago) => quot;about 2 hoursquot; >> I18n.locale = :quot;pt-BRquot; >> time_ago_in_words(1.month.ago) => quot;aproximadamente 1 mêsquot; >> time_ago_in_words(1.5.hours.ago) => quot;aproximadamente 2 horasquot; Tuesday, April 7, 2009

>> I18n.t [:hello, :world] => [quot;aloquot;, quot;mundoquot;] Tuesday, April 7, 2009

>> I18n.t [:hello, :world] => [quot;aloquot;, quot;mundoquot;] >> I18n.t :brazil, :defaults => [:argentina, quot;Chilequot;] => quot;Argentinaquot; Tuesday, April 7, 2009

message: quot;Hello, {{name}}!quot; Tuesday, April 7, 2009

message: quot;Hello, {{name}}!quot; I18n.t :message, :name => quot;Johnquot; # => quot;Hello John!quot; Tuesday, April 7, 2009

message: quot;Hello, {{name}}!quot; I18n.t :message, :name => quot;Johnquot; # => quot;Hello John!quot; # en-US :days => { :one => quot;one dayquot; :other => quot;{{count}} daysquot; } Tuesday, April 7, 2009

message: quot;Hello, {{name}}!quot; I18n.t :message, :name => quot;Johnquot; # => quot;Hello John!quot; # en-US :days => { :one => quot;one dayquot; :other => quot;{{count}} daysquot; } I18n.t :days, :count => 1 # => quot;one dayquot; I18n.t :days, :count => 2 # => quot;2 daysquot; Tuesday, April 7, 2009

Extracting Strings Tuesday, April 7, 2009

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

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

app/views/contacts/views/index.html.erb config/locales/pt-BR.rb { :quot;pt-BRquot; => { :hello => quot;Alô Mundoquot;, :contacts => { :index => { <tr> :name => quot;Nomequot;, <th>Name</th> :email => quot;Emailquot;, <th>Email</th> :phone => quot;Telefonequot;, <th>Phone</th> :mobile => quot;Celularquot; <th>Mobile</th> } </tr> } } } Tuesday, April 7, 2009

app/views/contacts/views/index.html.erb <tr> <th><%= t(quot;contacts.index.namequot;) %></th> <th><%= t(quot;index.emailquot;, :scope => quot;contactsquot;) %></th> <th><%= t(quot;phonequot;, :scope => quot;contacts.indexquot;) %></th> <th><%= t(quot;.mobilequot;) %></th> </tr> Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

config/locales/en.yml en: hello: quot;Hello worldquot; contacts: index: name: Name email: Email phone: Phone mobile: Mobile Tuesday, April 7, 2009

Tuesday, April 7, 2009

Setting Locale Tuesday, April 7, 2009

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

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

Tuesday, April 7, 2009

Tuesday, April 7, 2009

More strings Tuesday, April 7, 2009

app/views/contacts/views/index.html.erb <td><%= link_to t(quot;common.showquot;), contact %></td> <td><%= link_to t(quot;common.editquot;), edit_contact_path(contact) %></td> <td><%= link_to t(quot;common.destroyquot;), contact, :confirm => t('common.destroy_confirm'), :method => :delete %></td> Tuesday, April 7, 2009

config/locales/pt-BR.rb { :quot;pt-BRquot; => { :hello => quot;Alô Mundoquot;, :common => { :show => quot;Mostrarquot;, :edit => quot;Editarquot;, :destroy => quot;Apagarquot;, :destroy_confirm => quot;Tem certeza?quot; }, ... } } Tuesday, April 7, 2009

config/locales/en.yml en: hello: quot;Hello worldquot; common: show: Show edit: Edit destroy: Destroy destroy_confirm: Are you sure? ... Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

ActiveRecord Tuesday, April 7, 2009

<% 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(quot;common.submitquot;) %></p> <% end %> Tuesday, April 7, 2009

<% 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(quot;common.submitquot;) %></p> <% end %> Tuesday, April 7, 2009

... :activerecord => { :models => { :contact => quot;Contatoquot; }, :attributes => { :contact => { :name => quot;Nomequot;, :email => quot;Emailquot;, :phone => quot;Telefonequot;, :mobile => quot;Celularquot; } } } ... Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

./script/plugin install git://github.com/iain/i18n_label.git Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

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

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

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

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

Tuesday, April 7, 2009

app/controllers/contacts_controller.rb flash[:notice] = quot;Successfully created contact.quot; flash[:notice] = t(quot;contacts.messages.successful_createquot;) messages: successful_create: Successfully created contact. successful_update: Successfully updated contact. successful_destroy: Successfully destroyed contact. :messages => { :successful_create => quot;Contato criado com sucesso.quot;, :successful_update => quot;Contato atualizado com sucesso.quot;, :successful_destroy => quot;Contato apagado com sucesso.quot;, }, Tuesday, April 7, 2009

app/models/contact.rb class Contact < ActiveRecord::Base validates_presence_of :name end Tuesday, April 7, 2009

Tuesday, April 7, 2009

Routing Tuesday, April 7, 2009

http://localhost:3000/pt-BR/contacts/new { :locale => :quot;pt-BRquot;, :controller => quot;contactsquot;, :action => quot;newquot;} Tuesday, April 7, 2009

http://localhost:3000/pt-BR/contacts/new { :locale => :quot;pt-BRquot;, :controller => quot;contactsquot;, :action => quot;newquot;} ./script/plugin install git://github.com/svenfuchs/routing-filter.git Tuesday, April 7, 2009

http://localhost:3000/pt-BR/contacts/new { :locale => :quot;pt-BRquot;, :controller => quot;contactsquot;, :action => quot;newquot;} ./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

http://localhost:3000/pt-BR/contacts/new { :locale => :quot;pt-BRquot;, :controller => quot;contactsquot;, :action => quot;newquot;} ./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

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Views Tuesday, April 7, 2009

./script/generate controller page Tuesday, April 7, 2009

./script/generate controller page class PageController < ApplicationController def show render :template => params[:id] end end Tuesday, April 7, 2009

./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

Tuesday, April 7, 2009

app/views/page/_header.pt-BR.html.erb app/views/page/about.pt-BR.html.erb Tuesday, April 7, 2009

app/views/page/_header.pt-BR.html.erb app/views/page/about.pt-BR.html.erb Tuesday, April 7, 2009

app/views/page/about.html.erb <%= render :partial => quot;headerquot; %> <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

app/views/page/about.html.erb <%= render :partial => quot;headerquot; %> <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 => quot;headerquot; %> <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

app/views/page/about.html.erb <%= render :partial => quot;headerquot; %> <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 => quot;headerquot; %> <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

app/views/page/about.html.erb <%= render :partial => quot;headerquot; %> <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 => quot;headerquot; %> <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

app/views/page/_header.html.erb <% title quot;Official Rails I18n Project Hymnquot; %> <h3>Judas Priest - Painkiller</h3> app/views/page/_header.pt-BR.erb <% title quot;Hino Oficial do Projeto Rails I18nquot; %> <h3>Judas Priest - Painkiller</h3> Tuesday, April 7, 2009

Tuesday, April 7, 2009

Browser Languages Tuesday, April 7, 2009

Tuesday, April 7, 2009

./script/plugin install git://github.com/iain/http_accept_language.git Tuesday, April 7, 2009

./script/plugin install git://github.com/iain/http_accept_language.git app/controllers/application_controller.rb Tuesday, April 7, 2009

./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

./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

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Fast Backend Tuesday, April 7, 2009

./script/plugin install git://github.com/thedarkone/i18n.git Tuesday, April 7, 2009

./script/plugin install git://github.com/thedarkone/i18n.git I18n.backend = I18n::Backend::Fast.new Tuesday, April 7, 2009

./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

Globalize 2 Tuesday, April 7, 2009

./script/plugin install git://github.com/joshmh/globalize2.git Tuesday, April 7, 2009

./script/generate migration AddDescriptionFieldForContact Tuesday, April 7, 2009

./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

app/models/contact.rb class Contact < ActiveRecord::Base translates :description validates_presence_of :name end Tuesday, April 7, 2009

app/models/contact.rb class Contact < ActiveRecord::Base translates :description validates_presence_of :name end Tuesday, April 7, 2009

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(quot;common.submitquot;) %></p> Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

config/initializers/globalize.rb I18n.fallbacks[:en] Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Tuesday, April 7, 2009

Globalize2 • Model Translation • Custom Pluralization • Locale Fallbacks • Globalize::LoadPath • Globalize::Translation classes • Missing Translation Log Handler Tuesday, April 7, 2009

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

git clone git://github.com/akitaonrails/locosxrails_i18n_demo.git Tuesday, April 7, 2009

Muchas Gracias! www.akitaonrails.com fabioakita@gmail.com Tuesday, April 7, 2009

Add a comment

Related presentations

Presentación que realice en el Evento Nacional de Gobierno Abierto, realizado los ...

In this presentation we will describe our experience developing with a highly dyna...

Presentation to the LITA Forum 7th November 2014 Albuquerque, NM

Un recorrido por los cambios que nos generará el wearabletech en el futuro

Um paralelo entre as novidades & mercado em Wearable Computing e Tecnologias Assis...

Microsoft finally joins the smartwatch and fitness tracker game by introducing the...

Related pages

Locos X Rails Conference - Eventioz - Software para ...

Locos X Rails Conference. viernes, 3 de Abril de 2009, 10:00 hs - sábado, 4 de Abril de 2009, 17:45 hs Universidad de Palermo Almagro
Read more

Locos x Rails - YouTube

Argentina Ruby and Rails event, Locos x Rails. It was an awesome event with lots of fun and 2 full days of Ruby frenzy. Many thanks to the ...
Read more

Locos x Rails Wrap up | AkitaOnRails.com

Locos x Rails Wrap up. 2009 April 07, 13:55 h - tags: locosrails2009. Brasileiros: tradução abaixo. This last weekend I had a wonderful time in Buenos ...
Read more

Commits · tomaadland/locos-x-rails-conference · GitHub

locos-x-rails-conference - Conference site pages ... Switch branches/tags. Branches; Tags
Read more

GitHub - miloops/locos-x-rails-conference: Conference site ...

locos-x-rails-conference - Conference site pages ... HTTPS (recommended) Clone with Git or checkout with SVN ...
Read more

eventioz.com.ar

SUMMARY:Locos X Rails Conference DESCRIPTION:Mas información en: https://eventioz.com.ar/e/locos-x-rails-conference LOCATION:Universidad de Palermo Almagro
Read more

Conferencia Locos X Rails tomorrow, | Old Emmanuel Oga's ...

Tomorrow starts Locos X Rails conference in Buenos Aires, Argentina. I’m very exited about it! Yesterday I met Desi McAdam, of DevChix fame, and also the ...
Read more

Locos x Rails - Seminario sobre Ruby on Rails - RedUSERS

El viernes 3 y el sábado 4 de abril de 2009 se desarrollará en la Ciudad de Buenos Aires, Argentina, "Locos x Rails" una conferencia alrededor de Ruby on ...
Read more