How to apply locale translations for a Date field?

412 views
Skip to first unread message

Per Spilling

unread,
Nov 10, 2011, 11:52:38 AM11/10/11
to plataformate...@googlegroups.com
Hi, 

The subject says it all; how can I apply locale translations for a Date-field in SimleForm?

Regards,
Per

Per Spilling

unread,
Nov 10, 2011, 2:55:22 PM11/10/11
to plataformate...@googlegroups.com
Btw, the SimpleForm statement that I want to localize is as follows:

<%= f.input :visit_date, :label => 'Besøksdato', :as => :string, :input_html => { :class => 'date_picker', :size => 10 } %>

-Per

Rafael Mendonça França

unread,
Nov 10, 2011, 8:45:40 PM11/10/11
to plataformate...@googlegroups.com
In the same way that you localize the dafault Rails date input.

Per Spilling

unread,
Nov 11, 2011, 3:29:00 AM11/11/11
to SimpleForm
On Nov 11, 2:45 am, Rafael Mendonça França <rafaelmfra...@gmail.com>
wrote:
> In the same way that you localize the dafault Rails date input.
>
> See this file:https://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/nn.yml

No, that doesn't help for this date field in the SimpleForm. Maybe I
should restate the question. For nomal date fields I use the standard
Rails i18n localize mechanism way like so:

<%= l @company_visit.finalization_date %></p>

How do you apply the localize function in a SimpleForm date field like
this?

<%= f.input :visit_date, :label => 'Besøksdato', :as
=> :string, :input_html => { :class => 'date_picker', :size => 10 }
%>

Btw. I'm quite new to Ruby/Rails, so I apologize if this is a silly
question.

-Per

Rafael Mendonça França

unread,
Nov 11, 2011, 7:28:34 AM11/11/11
to plataformate...@googlegroups.com
You can't. The only way is using the Rails i18n API.

Carlos Antonio da Silva

unread,
Nov 14, 2011, 5:36:53 PM11/14/11
to plataformate...@googlegroups.com
Per, to show a formatted value with string inputs, you have to give the :value option to :input_html, using the i18n API as Rafael said:

 f.input :visit_date, :label => 'Besøksdato', :as => :string, :input_html => { :class => 'date_picker', :size => 10, :value => l(f.object.visit_date) }

Or something like that. Remember that this is only the output, it does not mean Rails will allow the same input from your user, that's up to you to do.
--
At.
Carlos Antonio
Reply all
Reply to author
Forward
0 new messages