This project is archived and is in readonly mode.
Error with date_select when a default_locale is set
-
Vincent Isambart
I investigated a little more and there is at least one problem with ActionView::Helpers::DateTimeSelector#translated_date_order. The current code is
def translated_date_order begin I18n.translate(:'date.order', :locale => @options[:locale]) || [] end endHowever, I18n.translate never returns nil/false. If it did not find anything, it will return a "translation missing: xxxx" string. And later calling .include(:symbol) on it will throw an exception. At first I thought about adding :default => [] in the translate()'s options, but the only defaults that can be used are strings (if you give an Array, it looks for the strings in it). To return an empty array if nothing was found you would have to do something like this:
def translated_date_order begin order = I18n.translate(:'date.order', :locale => @options[:locale]) if order.respond_to?(:to_ary) order else [] end end endI tried it and date_select displayed "Some date". A nice error would be better but it's still better than a strange "can't convert Symbol into String" exception.
-
Josh Delsman
Yep, I am having the same problem. I have the default set to "en-US", and I get the same Can't convert Symbol to String error.
-
n3uro5i5
I used your code, but i changed the empty array to a default date order.
module ActionView module Helpers
class DateTimeSelector def translated_date_order begin order = I18n.translate(:'date.order', :locale => @options[:locale]) if order.respond_to?(:to_ary) order else [:year, :month, :day] end end end endend end
-
bruno
Same problem using default_locale= 'en-US'
-
Dwayne Macgowan
I have the same problema.
While the problem is solved what you can do is explicit your :order every time you call date_select. This will avoid the error.
-
Mr.Devin
I had the same problem but found that since this is the datetime selector you need to add :time in your default order. this might be obvious to other but i am a bit dense so it is good to make not of this for other who are like me. :)
@@@RUBY class DateTimeSelector def translated_date_order
begin order = I18n.translate(:'date.order', :locale => @options[:locale]) if order.respond_to?(:to_ary) order else [:year, :month, :day, :time] end endend end
-
Dwayne Macgowan
I found a better solution. You need to define your localization for time formats. You can get some pre-made localization files for many languages at: http://github.com/svenfuchs/rail...
-
Yaroslav Markin
@bruno :'en-US' is not the default locale anymore, did you try :en?
-
DavidBackeus
I solved it by adding a en-US.yml with the formats on this page: http://i18n-demo.phusion.nl/page.... Would be nice if the helpers would be fixed to use rails defaults if no specifics are found.
-
Ryan Bigg
DavidBackeus, could you submit a patch for this? Thanks!
-
Ryan Bigg
- Assigned user set to Sven Fuchs
I have asked Sven Fuchs to take a look at this and give his opinion.
-
Sven Fuchs
- State changed from new to open
Thanks for reporting this.
I guess the implementation is just wrong. It should pass the :raise => true option (so I18n.t would raise a MissingTranslationException) and then rescue from the exception.
Also, it should help to add the locale fallbacks module here which is included in the I18n gem but it apparently is not obvious how to use it. Pratik mentioned that he wanted to enable it by default which should solve the problem with translation data missing for locales other than :en.
http://github.com/svenfuchs/i18n/blob/master/lib/i18n/backend/fallb...
-
Juice
oh, this is about 2 years old bug, I just got it.
-
Draiken
- Importance changed from to
Is this gonna get fixed or should I manually include the fallbacks on my projects?
-
Jean-Baptiste Escoyez
Same problem in rails 3.0.1 ruby 1.9.2
-
Mike Ferrier
+1
-
rails
- Tag changed from 2.2, date, i18n to 22, date, i18n
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
rails
- State changed from open to stale