#138 I18n
Internationalization is one of the biggest additions in Rails 2.2. See how the basics work in this episode.
- Download:
- source codeProject Files in Zip (94.3 KB)
- mp4Full Size H.264 Video (15.3 MB)
- m4vSmaller H.264 Video (9.06 MB)
- webmFull Size VP8 Video (19.9 MB)
- ogvFull Size Theora Video (19.5 MB)
There is a newer version of this episode, see the revised episode.
Resources
users/new.html.erb
<p>
<%= f.label :language, "Language" %><br />
<%= f.select :language, [['English', 'en'], ['Wookieespeak', 'wk']] %>
</p>
<p> <%= f.label :language, "Language" %><br /> <%= f.select :language, [['English', 'en'], ['Wookieespeak', 'wk']] %> </p>
products/index.html.erb
<% title t('welcome.title') %>
<p><%= t 'welcome.paragraph' %></p>
<h2><%= t 'products.title' %></h2>
<% for product in @products %>
<h3>
<%= link_to h(product.name), product %>
<%= number_to_currency(product.price) %>
</h3>
<div class="date_released">
<em><%= t 'products.released' %>: <%= product.created_at.strftime("%m/%d/%Y") %></em>
</div>
<% end %>
<% title t('welcome.title') %> <p><%= t 'welcome.paragraph' %></p> <h2><%= t 'products.title' %></h2> <% for product in @products %> <h3> <%= link_to h(product.name), product %> <%= number_to_currency(product.price) %> </h3> <div class="date_released"> <em><%= t 'products.released' %>: <%= product.created_at.strftime("%m/%d/%Y") %></em> </div> <% end %>
sessions_controller.rb
flash[:notice] = t('flash.login')
flash[:notice] = t('flash.login')
controllers/application.rb
before_filter :set_user_language
def set_user_language
I18n.locale = current_user.language if logged_in?
end
before_filter :set_user_language def set_user_language I18n.locale = current_user.language if logged_in? end
config/locales/en.yml
en:
welcome:
title: "Welcome"
paragraph: "Thank you for visiting our store. Please browse through the products below and buy some stuff. You'll love the unique quality and workmanship put into these items."
products:
title: "Products"
released: "Released"
flash:
login: "Logged in successfully."
en: welcome: title: "Welcome" paragraph: "Thank you for visiting our store. Please browse through the products below and buy some stuff. You'll love the unique quality and workmanship put into these items." products: title: "Products" released: "Released" flash: login: "Logged in successfully."
config/locales/wk.yml
wk:
welcome:
title: "Wyah"
paragraph: "Wyaaaaaa. Ruh ruh. Huwaa muaa mumwa. Wyogg, ur oh. Wua ga ma uma ahuma ooma. Ruh gwyaaaag. Youw."
products:
title: "Mauhwaa"
released: "Ruhhha"
flash:
login: "Wohooohaaa"
number:
format:
precision: 3
separator: '|'
delimiter: '-'
currency:
format:
unit: '$'
precision: 2
format: '%u%n'
wk: welcome: title: "Wyah" paragraph: "Wyaaaaaa. Ruh ruh. Huwaa muaa mumwa. Wyogg, ur oh. Wua ga ma uma ahuma ooma. Ruh gwyaaaag. Youw." products: title: "Mauhwaa" released: "Ruhhha" flash: login: "Wohooohaaa" number: format: precision: 3 separator: '|' delimiter: '-' currency: format: unit: '$' precision: 2 format: '%u%n'

