Hello everyone, I''m trying to get Rails (v2.2.2) to print dates in Dutch but it won''t pick up the formats I specify. :( I tried the following: 1) created a ''nl.yml'' file under ''config/locales'' 2) copied over the English defaults for dates from activesupport/.../ en.yml 3) added Dutch activerecord error messages and number and currency formats (euro sign) 4) changed the default locale in ''environment.rb'' The AR error messages are shown in Dutch just fine so Rails is loading the translation file and setting the locale correctly but when I do Date.today.to_s I always get the English versions, no matter what format I pass to the to_s() method. Also numbers and currencies are working fine. I just can''t get dates to behave! Been hunting down documentation and blog posts on the subject for hours now and I''m going crazy. Any ideas? Ronald --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
They didn''t worke for me either, so I rewrote the to_s method for
dates and times:
Date.class_eval do
def to_s( format_name = :default )
format = case format_name
when String
self.strftime( format )
when Symbol
I18n.localize( self, :format => format_name)
end
end
end
Time.class_eval do
def to_s( format_name = :default )
format = case format_name
when String
self.strftime( format )
when Symbol
I18n.localize( self, :format => format_name)
end
end
end
I did also search for reasons why it doesn''t work (from the I18N docs
it seemed that it should work), but this method at the Date object
shows that it has no idea about I18N:
def to_formatted_s(format = :default)
if formatter = DATE_FORMATS[format]
if formatter.respond_to?(:call)
formatter.call(self).to_s
else
strftime(formatter)
end
else
to_default_s
end
end
-
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en)
On Sat, Feb 28, 2009 at 7:03 PM, Ronald
<ronaldpaulusevers-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> Hello everyone,
>
> I''m trying to get Rails (v2.2.2) to print dates in Dutch but it
won''t
> pick up the formats I specify. :(
>
> I tried the following:
>
> 1) created a ''nl.yml'' file under
''config/locales''
> 2) copied over the English defaults for dates from activesupport/.../
> en.yml
> 3) added Dutch activerecord error messages and number and currency
> formats (euro sign)
> 4) changed the default locale in ''environment.rb''
>
> The AR error messages are shown in Dutch just fine so Rails is loading
> the translation file and setting the locale correctly but when I do
> Date.today.to_s I always get the English versions, no matter what
> format I pass to the to_s() method. Also numbers and currencies are
> working fine. I just can''t get dates to behave!
>
> Been hunting down documentation and blog posts on the subject for
> hours now and I''m going crazy. Any ideas?
>
> Ronald
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On Feb 28, 11:58 pm, Maurício Linhares <mauricio.linha...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> They didn''t worke for me either, so I rewrote the to_s method for > dates and times: > > Date.class_eval do > > def to_s( format_name = :default ) > format = case format_name > when String > self.strftime( format ) > when Symbol > I18n.localize( self, :format => format_name) > end > end > > end > > Time.class_eval do > > def to_s( format_name = :default ) > format = case format_name > when String > self.strftime( format ) > when Symbol > I18n.localize( self, :format => format_name) > end > end > > endGreat! Thanks, this works for me. (Small bug: parameter to strftime should be format_name, not format).> I did also search for reasons why it doesn''t work (from the I18N docs > it seemed that it should work), but this method at the Date object > shows that it has no idea about I18N: > > def to_formatted_s(format = :default) > if formatter = DATE_FORMATS[format] > if formatter.respond_to?(:call) > formatter.call(self).to_s > else > strftime(formatter) > end > else > to_default_s > end > endYeah I dug up this piece of source code as well. Guess I was too tired to compare this with for instance number_to_currency''s source and come to this conclusion myself ;) Anyway, thanks again! Ronald --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---