Permalink
Browse files

align with changes in i18n

  • Loading branch information...
1 parent c9ed2c9 commit 84816ae981a8598e5e401eb1b9b805de840fefc9 Sven Fuchs committed Jul 6, 2008
@@ -504,7 +504,6 @@ def select_day(date, options = {}, html_options = {})
#
def select_month(date, options = {}, html_options = {})
locale = options[:locale]
- locale ||= self.locale if respond_to?(:locale)
val = date ? (date.kind_of?(Fixnum) ? date : date.month) : ''
if options[:use_hidden]
@@ -513,7 +512,7 @@ def select_month(date, options = {}, html_options = {})
month_options = []
month_names = options[:use_month_names] || begin
key = options[:use_short_month] ? :'date.abbr_month_names' : :'date.month_names'
- I18n.translate key, locale
+ I18n.translate key, :locale => locale
end
month_names.unshift(nil) if month_names.size < 13
@@ -633,7 +632,7 @@ def date_or_time_select(options, html_options = {})
position = { :year => 1, :month => 2, :day => 3, :hour => 4, :minute => 5, :second => 6 }
- order = options[:order] ||= I18n.translate(:'date.order', locale)
+ order = options[:order] ||= I18n.translate(:'date.order', :locale => locale)
# Discard explicit and implicit by not being included in the :order
discard = {}
@@ -70,7 +70,7 @@ def number_to_phone(number, options = {})
# # => 1234567890,50 &pound;
def number_to_currency(number, options = {})
options = options.symbolize_keys
- defaults = I18n.translate(:'currency.format', options[:locale]) || {}
+ defaults = I18n.translate(:'currency.format', :locale => options[:locale]) || {}
precision = options[:precision] || defaults[:precision]
unit = options[:unit] || defaults[:unit]
@@ -4,11 +4,11 @@ module ActionView
module Helpers
module TranslationHelper
def translate(*args)
- key, locale, options = I18n.send :process_translate_arguments, *args
- I18n.translate key, locale, options.merge(:raise => true)
+ args << args.extract_options!.merge(:raise => true)
+ I18n.translate *args
rescue I18n::MissingTranslationData => e
- keys = I18n.send :normalize_translation_keys, locale, key, options[:scope]
+ keys = I18n.send :normalize_translation_keys, e.locale, e.key, e.options[:scope]
content_tag('span', keys.join(', '), :class => 'translation_missing')
end
end
@@ -56,7 +56,7 @@ class DateHelperSelectTagsI18nTests < Test::Unit::TestCase
uses_mocha 'date_helper_select_tags_i18n_tests' do
def setup
- I18n.stubs(:translate).with(:'date.month_names', 'en-US').returns Date::MONTHNAMES
+ I18n.stubs(:translate).with(:'date.month_names', :locale => 'en-US').returns Date::MONTHNAMES
end
# select_month
@@ -67,12 +67,12 @@ def test_select_month_given_use_month_names_option_does_not_translate_monthnames
end
def test_select_month_translates_monthnames
- I18n.expects(:translate).with(:'date.month_names', 'en-US').returns Date::MONTHNAMES
+ I18n.expects(:translate).with(:'date.month_names', :locale => 'en-US').returns Date::MONTHNAMES
select_month(8, :locale => 'en-US')
end
def test_select_month_given_use_short_month_option_translates_abbr_monthnames
- I18n.expects(:translate).with(:'date.abbr_month_names', 'en-US').returns Date::ABBR_MONTHNAMES
+ I18n.expects(:translate).with(:'date.abbr_month_names', :locale => 'en-US').returns Date::ABBR_MONTHNAMES
select_month(8, :locale => 'en-US', :use_short_month => true)
end
@@ -84,7 +84,7 @@ 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', 'en-US').returns [:year, :month, :day]
+ I18n.expects(:translate).with(:'date.order', :locale => 'en-US').returns [:year, :month, :day]
datetime_select('post', 'updated_at', :locale => 'en-US')
end
end
@@ -11,7 +11,7 @@ def setup
end
def test_number_to_currency_translates_currency_formats
- I18n.expects(:translate).with(:'currency.format', 'en-US').returns @defaults
+ I18n.expects(:translate).with(:'currency.format', :locale => 'en-US').returns @defaults
number_to_currency(1, :locale => 'en-US')
end
end
@@ -70,7 +70,7 @@ def generate_message(attr, key, options = {})
msgs << options[:default] if options[:default]
msgs << key
- I18n.t options.merge(:default => msgs, :scope => [:active_record, :error_messages])
+ I18n.t nil, options.merge(:default => msgs, :scope => [:active_record, :error_messages])
end
# Returns true if the specified +attribute+ has errors associated with it.
@@ -158,7 +158,6 @@ def each_full
# ["Name is too short (minimum is 5 characters)", "Name can't be blank", "Address can't be blank"]
def full_messages(options = {})
full_messages = []
- locale = options[:locale]
@errors.each_key do |attr|
@errors[attr].each do |message|
@@ -168,7 +167,7 @@ def full_messages(options = {})
full_messages << message
else
key = :"active_record.human_attribute_names.#{@base.class.name.underscore.to_sym}.#{attr}"
- attr_name = I18n.translate(key, locale, :default => @base.class.human_attribute_name(attr))
+ attr_name = I18n.translate(key, :locale => options[:locale], :default => @base.class.human_attribute_name(attr))
full_messages << attr_name + " " + message
end
end
@@ -46,14 +46,14 @@ def test_errors_generate_message_translates_custom_model_attribute_key
global_scope = [:active_record, :error_messages]
custom_scope = global_scope + [:custom, 'topic', :title]
- I18n.expects(:t).with :scope => [:active_record, :error_messages], :default => [:"custom.topic.title.invalid", 'default from class def', :invalid]
+ I18n.expects(:t).with nil, :scope => [:active_record, :error_messages], :default => [:"custom.topic.title.invalid", 'default from class def', :invalid]
@topic.errors.generate_message :title, :invalid, :default => 'default from class def'
end
def test_errors_generate_message_translates_custom_model_attribute_keys_with_sti
custom_scope = [:active_record, :error_messages, :custom, 'topic', :title]
- I18n.expects(:t).with :scope => [:active_record, :error_messages], :default => [:"custom.reply.title.invalid", :"custom.topic.title.invalid", 'default from class def', :invalid]
+ I18n.expects(:t).with nil, :scope => [:active_record, :error_messages], :default => [:"custom.reply.title.invalid", :"custom.topic.title.invalid", 'default from class def', :invalid]
Reply.new.errors.generate_message :title, :invalid, :default => 'default from class def'
end
@@ -79,7 +79,7 @@ def test_errors_add_on_blank_generates_message_with_custom_default_message
def test_errors_full_messages_translates_human_attribute_name_for_model_attributes
@topic.errors.instance_variable_set :@errors, { 'title' => 'empty' }
- I18n.expects(:translate).with(:"active_record.human_attribute_names.topic.title", 'en-US', :default => 'Title').returns('Title')
+ I18n.expects(:translate).with(:"active_record.human_attribute_names.topic.title", :locale => 'en-US', :default => 'Title').returns('Title')
@topic.errors.full_messages :locale => 'en-US'
end
end
@@ -10,10 +10,7 @@ module Conversions
def to_sentence(options = {})
options.assert_valid_keys(:connector, :skip_last_comma, :locale)
- locale = options[:locale]
- locale ||= self.locale if respond_to?(:locale)
-
- default = I18n.translate(:'support.array.sentence_connector', locale)
+ default = I18n.translate(:'support.array.sentence_connector', :locale => options[:locale])
options.reverse_merge! :connector => default, :skip_last_comma => false
options[:connector] = "#{options[:connector]} " unless options[:connector].nil? || options[:connector].strip == ''
Submodule i18n-0.0.1 updated from 970bc7 to 46aad2
@@ -18,31 +18,31 @@ def test_date_localization_should_use_default_format
end
def test_date_localization_with_default_format
- assert_equal "2008-07-02", I18n.localize(@date, nil, :default)
+ assert_equal "2008-07-02", I18n.localize(@date, :format => :default)
end
def test_date_localization_with_short_format
- assert_equal "Jul 02", I18n.localize(@date, nil, :short)
+ assert_equal "Jul 02", I18n.localize(@date, :format => :short)
end
def test_date_localization_with_long_format
- assert_equal "July 02, 2008", I18n.localize(@date, nil, :long)
+ assert_equal "July 02, 2008", I18n.localize(@date, :format => :long)
end
def test_time_localization_should_use_default_format
assert_equal "Wed, 02 Jul 2008 16:47:01 +0100", I18n.localize(@time)
end
def test_time_localization_with_default_format
- assert_equal "Wed, 02 Jul 2008 16:47:01 +0100", I18n.localize(@time, nil, :default)
+ assert_equal "Wed, 02 Jul 2008 16:47:01 +0100", I18n.localize(@time, :format => :default)
end
def test_time_localization_with_short_format
- assert_equal "02 Jul 16:47", I18n.localize(@time, nil, :short)
+ assert_equal "02 Jul 16:47", I18n.localize(@time, :format => :short)
end
def test_time_localization_with_long_format
- assert_equal "July 02, 2008 16:47", I18n.localize(@time, nil, :long)
+ assert_equal "July 02, 2008 16:47", I18n.localize(@time, :format => :long)
end
def test_day_names

0 comments on commit 84816ae

Please sign in to comment.