Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails i18n and yml structure for form labels

According to the ActionView documentation. Quote:

The text of label will default to the attribute name unless a translation is found in the current I18n locale (through views.labels.<modelname>.<attribute>) or you specify it explicitly.

I have a "user" model and a registration form. Here's a snippet of the relevant part:

<% form_for(@user) do |f| %>     ...     <p>     <%= f.label :username %>     <%= f.text_field :username, :class => 'full_width' %>     </p>     ... <% end %> 

Dots hide unimportant code.

As I understand the documentation, if I provide a translation in my locale file, in this case :dk, my dk.yml looking like so:

dk:     views:         labels:             user:                 username:                     "blahblah" 

Rails should translate the label text and insert "blahblah" instead of "Username".

This is not happening, so I must have missed something. Any help appreciated.

like image 323
rhardih Avatar asked Aug 18 '10 20:08

rhardih


1 Answers

In Rails 3.1 that is a little bit changed.

<% form_for @post do |f| %>   <%= f.label :title %>   <%= f.text_field :title %>   <%= f.submit %> <% end %>  en:   helpers:     label:       post:         title: 'Customized title' 
like image 88
Voldy Avatar answered Sep 21 '22 13:09

Voldy