In Rails <=2.3 i18n internationalization does not include translation of form labels. However, this can be easily fixed by installing the patch i18n_label by iain. For your Rails project, just install plugin:
ruby script/plugin install git://github.com/iain/i18n_label.git
Now you should just add appropriate entries to your locale file. I’d explain it in the example below.
I have the following form to the model Post:
<% form_for :post do |f| -%> <%= f.error_messages %> <p><%= f.label :name %></p> <p><%= f.text_field :name %></p> <p><%= f.submit "Wyślij" %></p> <% end -%>
I want the label :name to be automatically translated according to the entry in locales. Taking as an example polish locale pl.yml, we have to create new entry:
pl:
activerecord:
models:
post: "Wiadomości"
attributes:
post:
name: "Nazwa"
…and that’s all! After restarting the project, the form labels are successfully tanslated according to locale entries!
Related Posts
- Ruby on Rails + Formtastic + jQuery UI datepicker
- Ruby on Rails CMS
- Alternative strings’s delimiter for Ruby (on Rails)
- RoR: Railroad plugin with Rails 2.3.5 on Windows error
- PIK: Multiple Ruby versions for Windows
Lipiec 25th, 2010



Home