From 6da0f42bb4f1852d7c0f4c9eb0c2edafd0149665 Mon Sep 17 00:00:00 2001 From: Sam Oliver Date: Mon, 22 Dec 2008 11:41:47 +0000 Subject: [PATCH] Use I18n for default prompts --- actionpack/lib/action_view/helpers/date_helper.rb | 12 ++++-------- actionpack/lib/action_view/locale/en.yml | 9 ++++++++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 84ba5f0..75addd4 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 @@ -835,17 +831,17 @@ module ActionView # => "" def prompt_option_tag(type, options) default_options = {:year => false, :month => false, :day => false, :hour => false, :minute => false, :second => false} - + case options when Hash prompt = default_options.merge(options)[type.to_sym] 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 9542b03..f287483 100644 --- a/actionpack/lib/action_view/locale/en.yml +++ b/actionpack/lib/action_view/locale/en.yml @@ -80,7 +80,14 @@ 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: template: -- 1.6.0.2 From e5cdbb7befc9282c862e753bc8af259de826385d Mon Sep 17 00:00:00 2001 From: Sam Oliver Date: Mon, 22 Dec 2008 14:57:25 +0000 Subject: [PATCH] Added tests for I18n translations --- actionpack/test/template/date_helper_i18n_test.rb | 12 +++++++++++- 1 files changed, 11 insertions(+), 1 deletions(-) diff --git a/actionpack/test/template/date_helper_i18n_test.rb b/actionpack/test/template/date_helper_i18n_test.rb index dc9616d..d89cb69 100644 --- a/actionpack/test/template/date_helper_i18n_test.rb +++ b/actionpack/test/template/date_helper_i18n_test.rb @@ -75,9 +75,11 @@ end class DateHelperSelectTagsI18nTests < Test::Unit::TestCase include ActionView::Helpers::DateHelper attr_reader :request - + 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 @@ -97,6 +99,14 @@ class DateHelperSelectTagsI18nTests < Test::Unit::TestCase I18n.expects(:translate).with(:'date.abbr_month_names', :locale => 'en').returns Date::ABBR_MONTHNAMES 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 -- 1.6.0.2 From eee829aed6f3970a87a0e5835104bdacf215f210 Mon Sep 17 00:00:00 2001 From: Sam Oliver Date: Mon, 22 Dec 2008 15:00:42 +0000 Subject: [PATCH] Added tests for I18n translations --- actionpack/test/template/date_helper_i18n_test.rb | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/actionpack/test/template/date_helper_i18n_test.rb b/actionpack/test/template/date_helper_i18n_test.rb index d89cb69..dbfac7d 100644 --- a/actionpack/test/template/date_helper_i18n_test.rb +++ b/actionpack/test/template/date_helper_i18n_test.rb @@ -75,7 +75,7 @@ end class DateHelperSelectTagsI18nTests < Test::Unit::TestCase include ActionView::Helpers::DateHelper attr_reader :request - + 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'} -- 1.6.0.2