diff options
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/active_record_helper.rb | 8 | ||||
-rw-r--r-- | actionpack/lib/action_view/locale/en-US.rb | 53 | ||||
-rw-r--r-- | actionpack/lib/action_view/locale/en-US.yml | 91 | ||||
-rw-r--r-- | actionpack/test/template/active_record_helper_i18n_test.rb | 28 | ||||
-rw-r--r-- | actionpack/test/template/date_helper_i18n_test.rb | 22 |
6 files changed, 132 insertions, 72 deletions
diff --git a/actionpack/lib/action_view.rb b/actionpack/lib/action_view.rb index dd555b3792..f13324a9d0 100644 --- a/actionpack/lib/action_view.rb +++ b/actionpack/lib/action_view.rb @@ -35,7 +35,7 @@ require 'action_view/partials' require 'action_view/template_error' I18n.backend.populate do - require 'action_view/locale/en-US.rb' + I18n.load_translations File.dirname(__FILE__) + '/action_view/locale/en-US.yml' end ActionView::Base.class_eval do diff --git a/actionpack/lib/action_view/helpers/active_record_helper.rb b/actionpack/lib/action_view/helpers/active_record_helper.rb index fce03ff605..c339e10701 100644 --- a/actionpack/lib/action_view/helpers/active_record_helper.rb +++ b/actionpack/lib/action_view/helpers/active_record_helper.rb @@ -189,15 +189,15 @@ module ActionView end options[:object_name] ||= params.first - I18n.with_options :locale => options[:locale], :scope => [:active_record, :error] do |locale| + I18n.with_options :locale => options[:locale], :scope => [:activerecord, :errors, :template] do |locale| header_message = if options.include?(:header_message) options[:header_message] else object_name = options[:object_name].to_s.gsub('_', ' ') - object_name = I18n.t(object_name, :default => object_name) - locale.t :header_message, :count => count, :object_name => object_name + object_name = I18n.t(object_name, :default => object_name, :scope => [:activerecord, :models], :count => 1) + locale.t :header, :count => count, :model => object_name end - message = options.include?(:message) ? options[:message] : locale.t(:message) + message = options.include?(:message) ? options[:message] : locale.t(:body) error_messages = objects.sum {|object| object.errors.full_messages.map {|msg| content_tag(:li, msg) } }.join contents = '' diff --git a/actionpack/lib/action_view/locale/en-US.rb b/actionpack/lib/action_view/locale/en-US.rb deleted file mode 100644 index 2c3676dca8..0000000000 --- a/actionpack/lib/action_view/locale/en-US.rb +++ /dev/null @@ -1,53 +0,0 @@ -I18n.backend.store_translations :'en-US', { - :datetime => { - :distance_in_words => { - :half_a_minute => 'half a minute', - :less_than_x_seconds => ['less than 1 second', 'less than {{count}} seconds'], - :x_seconds => ['1 second', '{{count}} seconds'], - :less_than_x_minutes => ['less than a minute', 'less than {{count}} minutes'], - :x_minutes => ['1 minute', '{{count}} minutes'], - :about_x_hours => ['about 1 hour', 'about {{count}} hours'], - :x_days => ['1 day', '{{count}} days'], - :about_x_months => ['about 1 month', 'about {{count}} months'], - :x_months => ['1 month', '{{count}} months'], - :about_x_years => ['about 1 year', 'about {{count}} year'], - :over_x_years => ['over 1 year', 'over {{count}} years'] - } - }, - :number => { - :format => { - :precision => 3, - :separator => '.', - :delimiter => ',' - }, - :currency => { - :format => { - :unit => '$', - :precision => 2, - :format => '%u%n' - } - }, - :human => { - :format => { - :precision => 1, - :delimiter => '' - } - }, - :percentage => { - :format => { - :delimiter => '' - } - }, - :precision => { - :format => { - :delimiter => '' - } - } - }, - :active_record => { - :error => { - :header_message => ["1 error prohibited this {{object_name}} from being saved", "{{count}} errors prohibited this {{object_name}} from being saved"], - :message => "There were problems with the following fields:" - } - } -} diff --git a/actionpack/lib/action_view/locale/en-US.yml b/actionpack/lib/action_view/locale/en-US.yml new file mode 100644 index 0000000000..57987f4e02 --- /dev/null +++ b/actionpack/lib/action_view/locale/en-US.yml @@ -0,0 +1,91 @@ +"en-US": + number: + # Used in number_with_delimiter() + # These are also the defaults for 'currency', 'percentage', 'precision', and 'human' + format: + # Sets the separator between the units, for more precision (e.g. 1.0 / 2.0 == 0.5) + separator: "." + # Delimets thousands (e.g. 1,000,000 is a million) (always in groups of three) + delimiter: "," + # Number of decimals, behind the separator (the number 1 with a precision of 2 gives: 1.00) + precision: 3 + + # Used in number_to_currency() + currency: + format: + # Where is the currency sign? %u is the currency unit, %n the number (default: $5.00) + format: "%u%n" + unit: "$" + # These three are to override number.format and are optional + separator: "." + delimiter: "," + precision: 2 + + # Used in number_to_percentage() + percentage: + format: + # These three are to override number.format and are optional + # separator: + delimiter: "" + # precision: + + # Used in number_to_precision() + precision: + format: + # These three are to override number.format and are optional + # separator: + delimiter: "" + # precision: + + # Used in number_to_human_size() + human: + format: + # These three are to override number.format and are optional + # separator: + delimiter: "" + precision: 1 + + # Used in distance_of_time_in_words(), distance_of_time_in_words_to_now(), time_ago_in_words() + datetime: + distance_in_words: + half_a_minute: "half a minute" + less_than_x_seconds: + one: "less than 1 second" + many: "less than {{count}} seconds" + x_seconds: + one: "1 second" + many: "{{count}} seconds" + less_than_x_minutes: + one: "less than a minute" + many: "less than {{count}} minutes" + x_minutes: + one: "1 minute" + many: "{{count}} minutes" + about_x_hours: + one: "about 1 hour" + many: "about {{count}} hours" + x_days: + one: "1 day" + many: "{{count}} days" + about_x_months: + one: "about 1 month" + many: "about {{count}} months" + x_months: + one: "1 month" + many: "{{count}} months" + about_x_years: + one: "about 1 year" + many: "about {{count}} years" + over_x_years: + one: "over 1 year" + many: "over {{count}} years" + + activerecord: + errors: + template: + header: + one: "1 error prohibited this {{model}} from being saved" + many: "{{count}} errors prohibited this {{model}} from being saved" + # The variable :count is also available + body: "There were problems with the following fields:" + diff --git a/actionpack/test/template/active_record_helper_i18n_test.rb b/actionpack/test/template/active_record_helper_i18n_test.rb index feec64aa30..7ba9659814 100644 --- a/actionpack/test/template/active_record_helper_i18n_test.rb +++ b/actionpack/test/template/active_record_helper_i18n_test.rb @@ -10,37 +10,37 @@ class ActiveRecordHelperI18nTest < Test::Unit::TestCase @object_name = 'book' stubs(:content_tag).returns 'content_tag' - I18n.stubs(:t).with(:'header_message', :locale => 'en-US', :scope => [:active_record, :error], :count => 1, :object_name => '').returns "1 error prohibited this from being saved" - I18n.stubs(:t).with(:'message', :locale => 'en-US', :scope => [:active_record, :error]).returns 'There were problems with the following fields:' + I18n.stubs(:t).with(:'header', :locale => 'en-US', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').returns "1 error prohibited this from being saved" + I18n.stubs(:t).with(:'body', :locale => 'en-US', :scope => [:activerecord, :errors, :template]).returns 'There were problems with the following fields:' end - def test_error_messages_for_given_a_header_message_option_it_does_not_translate_header_message - I18n.expects(:translate).with(:'header_message', :locale => 'en-US', :scope => [:active_record, :error], :count => 1, :object_name => '').never + def test_error_messages_for_given_a_header_option_it_does_not_translate_header_message + I18n.expects(:translate).with(:'header', :locale => 'en-US', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').never error_messages_for(:object => @object, :header_message => 'header message', :locale => 'en-US') end - def test_error_messages_for_given_no_header_message_option_it_translates_header_message - I18n.expects(:t).with(:'header_message', :locale => 'en-US', :scope => [:active_record, :error], :count => 1, :object_name => '').returns 'header message' - I18n.expects(:t).with('', :default => '').once.returns '' + def test_error_messages_for_given_no_header_option_it_translates_header_message + I18n.expects(:t).with(:'header', :locale => 'en-US', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').returns 'header message' + I18n.expects(:t).with('', :default => '', :count => 1, :scope => [:activerecord, :models]).once.returns '' error_messages_for(:object => @object, :locale => 'en-US') end def test_error_messages_for_given_a_message_option_it_does_not_translate_message - I18n.expects(:t).with(:'message', :locale => 'en-US', :scope => [:active_record, :error]).never - I18n.expects(:t).with('', :default => '').once.returns '' + I18n.expects(:t).with(:'body', :locale => 'en-US', :scope => [:activerecord, :errors, :template]).never + I18n.expects(:t).with('', :default => '', :count => 1, :scope => [:activerecord, :models]).once.returns '' error_messages_for(:object => @object, :message => 'message', :locale => 'en-US') end def test_error_messages_for_given_no_message_option_it_translates_message - I18n.expects(:t).with(:'message', :locale => 'en-US', :scope => [:active_record, :error]).returns 'There were problems with the following fields:' - I18n.expects(:t).with('', :default => '').once.returns '' + I18n.expects(:t).with(:'body', :locale => 'en-US', :scope => [:activerecord, :errors, :template]).returns 'There were problems with the following fields:' + I18n.expects(:t).with('', :default => '', :count => 1, :scope => [:activerecord, :models]).once.returns '' error_messages_for(:object => @object, :locale => 'en-US') end def test_error_messages_for_given_object_name_it_translates_object_name - I18n.expects(:t).with(:header_message, :locale => 'en-US', :scope => [:active_record, :error], :count => 1, :object_name => @object_name).returns "1 error prohibited this #{@object_name} from being saved" - I18n.expects(:t).with(@object_name, :default => @object_name).once.returns @object_name + I18n.expects(:t).with(:header, :locale => 'en-US', :scope => [:activerecord, :errors, :template], :count => 1, :model => @object_name).returns "1 error prohibited this #{@object_name} from being saved" + I18n.expects(:t).with(@object_name, :default => @object_name, :count => 1, :scope => [:activerecord, :models]).once.returns @object_name error_messages_for(:object => @object, :locale => 'en-US', :object_name => @object_name) end end -end
\ No newline at end of file +end diff --git a/actionpack/test/template/date_helper_i18n_test.rb b/actionpack/test/template/date_helper_i18n_test.rb index 2b40074498..bf3b2588c8 100644 --- a/actionpack/test/template/date_helper_i18n_test.rb +++ b/actionpack/test/template/date_helper_i18n_test.rb @@ -47,6 +47,28 @@ class DateHelperDistanceOfTimeInWordsI18nTests < Test::Unit::TestCase I18n.expects(:t).with(key, options) distance_of_time_in_words(@from, to, include_seconds, :locale => 'en-US') end + + def test_distance_of_time_pluralizations + { [:'less_than_x_seconds', 1] => 'less than 1 second', + [:'less_than_x_seconds', 2] => 'less than 2 seconds', + [:'less_than_x_minutes', 1] => 'less than a minute', + [:'less_than_x_minutes', 2] => 'less than 2 minutes', + [:'x_minutes', 1] => '1 minute', + [:'x_minutes', 2] => '2 minutes', + [:'about_x_hours', 1] => 'about 1 hour', + [:'about_x_hours', 2] => 'about 2 hours', + [:'x_days', 1] => '1 day', + [:'x_days', 2] => '2 days', + [:'about_x_years', 1] => 'about 1 year', + [:'about_x_years', 2] => 'about 2 years', + [:'over_x_years', 1] => 'over 1 year', + [:'over_x_years', 2] => 'over 2 years' + + }.each do |args, expected| + key, count = *args + assert_equal expected, I18n.t(key, :count => count, :scope => 'datetime.distance_in_words') + end + end end end |