Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove i18n symbol dependency

date.order is the only key in rails i18n that is required to be a
symbol. This patch allows for symbols or strings which means:

* No requirement for symbol type in .yml files. A future
  YAML.safe_load wouldn't need to load symbols
* Rails could actually use json rather than yml as the backend
  • Loading branch information...
commit 6bb784eab0d286d1966c12e1bacc793113d6fbae 1 parent 038574a
@chrismcg chrismcg authored
View
1  actionpack/lib/action_view/helpers/date_helper.rb
@@ -880,6 +880,7 @@ def date_order
def translated_date_order
date_order = I18n.translate(:'date.order', :locale => @options[:locale], :default => [])
+ date_order.map! { |element| element.to_sym }
forbidden_elements = date_order - [:year, :month, :day]
if forbidden_elements.any?
View
11 actionpack/test/template/date_helper_i18n_test.rb
@@ -117,7 +117,7 @@ def test_date_or_time_select_translates_prompts
I18n.expects(:translate).with(('datetime.prompts.' + key.to_s).to_sym, :locale => 'en').returns prompt
end
- I18n.expects(:translate).with(:'date.order', :locale => 'en', :default => []).returns [:year, :month, :day]
+ I18n.expects(:translate).with(:'date.order', :locale => 'en', :default => []).returns %w(year month day)
datetime_select('post', 'updated_at', :locale => 'en', :include_seconds => true, :prompt => true)
end
@@ -129,15 +129,20 @@ def test_date_or_time_select_given_an_order_options_does_not_translate_order
end
def test_date_or_time_select_given_no_order_options_translates_order
- I18n.expects(:translate).with(:'date.order', :locale => 'en', :default => []).returns [:year, :month, :day]
+ I18n.expects(:translate).with(:'date.order', :locale => 'en', :default => []).returns %w(year month day)
datetime_select('post', 'updated_at', :locale => 'en')
end
def test_date_or_time_select_given_invalid_order
- I18n.expects(:translate).with(:'date.order', :locale => 'en', :default => []).returns [:invalid, :month, :day]
+ I18n.expects(:translate).with(:'date.order', :locale => 'en', :default => []).returns %w(invalid month day)
assert_raise StandardError do
datetime_select('post', 'updated_at', :locale => 'en')
end
end
+
+ def test_date_or_time_select_given_symbol_keys
+ I18n.expects(:translate).with(:'date.order', :locale => 'en', :default => []).returns [:year, :month, :day]
+ datetime_select('post', 'updated_at', :locale => 'en')
+ end
end
View
6 activesupport/lib/active_support/locale/en.yml
@@ -16,9 +16,9 @@ en:
abbr_month_names: [~, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]
# Used in date_select and datetime_select.
order:
- - :year
- - :month
- - :day
+ - year
+ - month
+ - day
time:
formats:
Please sign in to comment.
Something went wrong with that request. Please try again.