diff options
author | Sam Oliver <sam@samoliver.com> | 2008-12-22 11:41:47 +0000 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-12-22 15:13:39 +0000 |
commit | 70456aed31ae64b36563fc5d32ac114e0a095231 (patch) | |
tree | a9adef034cffd3b453602b9c2a33e4955536e922 /actionpack | |
parent | e8de7a67a5ef063164da022845a7cae1753da80e (diff) | |
download | rails-70456aed31ae64b36563fc5d32ac114e0a095231.tar.gz rails-70456aed31ae64b36563fc5d32ac114e0a095231.tar.bz2 rails-70456aed31ae64b36563fc5d32ac114e0a095231.zip |
Use I18n for date/time select helpers prompt text [#561 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view/helpers/date_helper.rb | 8 | ||||
-rw-r--r-- | actionpack/lib/action_view/locale/en.yml | 7 | ||||
-rw-r--r-- | actionpack/test/template/date_helper_i18n_test.rb | 11 |
3 files changed, 20 insertions, 6 deletions
diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 84ba5f0a8c..4305617ac8 100644 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -572,10 +572,6 @@ module ActionView :year => 1, :month => 2, :day => 3, :hour => 4, :minute => 5, :second => 6 }.freeze unless const_defined?('POSITION') - DEFAULT_PROMPTS = { - :year => 'Year', :month => 'Month', :day => 'Day', :hour => 'Hour', :minute => 'Minute', :second => 'Seconds' - }.freeze unless const_defined?('DEFAULT_PROMPTS') - def initialize(datetime, options = {}, html_options = {}) @options = options.dup @html_options = html_options.dup @@ -842,10 +838,10 @@ module ActionView when String prompt = options else - prompt = ActionView::Helpers::DateTimeSelector::DEFAULT_PROMPTS[type.to_sym] + prompt = I18n.translate(('datetime.prompts.' + type.to_s).to_sym, :locale => @options[:locale]) end - prompt ? content_tag(:option, prompt, :value => '') : '' + prompt ? content_tag(:option, prompt, :value => '') : '' end # Builds hidden input tag for date part and value diff --git a/actionpack/lib/action_view/locale/en.yml b/actionpack/lib/action_view/locale/en.yml index 9542b035aa..a880fd83ef 100644 --- a/actionpack/lib/action_view/locale/en.yml +++ b/actionpack/lib/action_view/locale/en.yml @@ -80,6 +80,13 @@ over_x_years: one: "over 1 year" other: "over {{count}} years" + prompts: + year: "Year" + month: "Month" + day: "Day" + hour: "Hour" + minute: "Minute" + second: "Seconds" activerecord: errors: diff --git a/actionpack/test/template/date_helper_i18n_test.rb b/actionpack/test/template/date_helper_i18n_test.rb index dc9616db3b..fac30da128 100644 --- a/actionpack/test/template/date_helper_i18n_test.rb +++ b/actionpack/test/template/date_helper_i18n_test.rb @@ -78,6 +78,8 @@ class DateHelperSelectTagsI18nTests < Test::Unit::TestCase uses_mocha 'date_helper_select_tags_i18n_tests' do def setup + @prompt_defaults = {:year => 'Year', :month => 'Month', :day => 'Day', :hour => 'Hour', :minute => 'Minute', :second => 'Seconds'} + I18n.stubs(:translate).with(:'date.month_names', :locale => 'en').returns Date::MONTHNAMES end @@ -98,6 +100,15 @@ class DateHelperSelectTagsI18nTests < Test::Unit::TestCase select_month(8, :locale => 'en', :use_short_month => true) end + def test_date_or_time_select_translates_prompts + @prompt_defaults.each do |key, prompt| + I18n.expects(:translate).with(('datetime.prompts.' + key.to_s).to_sym, :locale => 'en').returns prompt + end + + I18n.expects(:translate).with(:'date.order', :locale => 'en').returns [:year, :month, :day] + datetime_select('post', 'updated_at', :locale => 'en', :include_seconds => true, :prompt => true) + end + # date_or_time_select def test_date_or_time_select_given_an_order_options_does_not_translate_order |