mirror of
https://github.com/github/rails.git
synced 2026-02-05 11:45:13 -05:00
remove core extensions in favor of I18n#translate and I18n#localize
This commit is contained in:
@@ -349,7 +349,7 @@ module ActionMailer #:nodoc:
|
||||
# the current locale, and, finally, on the +default_charset+ specified
|
||||
# for ActionMailer::Base.
|
||||
def charset(charset = nil)
|
||||
@charset ||= charset || :'charset'.t || @@default_charset
|
||||
@charset ||= charset || I18n.translate(:charset) || @@default_charset
|
||||
end
|
||||
attr_writer :charset
|
||||
|
||||
|
||||
@@ -512,7 +512,8 @@ module ActionView
|
||||
else
|
||||
month_options = []
|
||||
month_names = options[:use_month_names] || begin
|
||||
(options[:use_short_month] ? :'date.abbr_month_names' : :'date.month_names').t locale
|
||||
key = options[:use_short_month] ? :'date.abbr_month_names' : :'date.month_names'
|
||||
I18n.translate key, locale
|
||||
end
|
||||
month_names.unshift(nil) if month_names.size < 13
|
||||
|
||||
@@ -632,7 +633,7 @@ module ActionView
|
||||
|
||||
position = { :year => 1, :month => 2, :day => 3, :hour => 4, :minute => 5, :second => 6 }
|
||||
|
||||
order = options[:order] ||= :'date.order'.t(locale)
|
||||
order = options[:order] ||= I18n.translate(:'date.order', locale)
|
||||
|
||||
# Discard explicit and implicit by not being included in the :order
|
||||
discard = {}
|
||||
|
||||
@@ -70,7 +70,7 @@ module ActionView
|
||||
# # => 1234567890,50 £
|
||||
def number_to_currency(number, options = {})
|
||||
options = options.symbolize_keys
|
||||
defaults = :'currency.format'.t(options[:locale]) || {}
|
||||
defaults = I18n.translate(:'currency.format', options[:locale]) || {}
|
||||
|
||||
precision = options[:precision] || defaults[:precision]
|
||||
unit = options[:unit] || defaults[:unit]
|
||||
|
||||
@@ -22,7 +22,7 @@ module ActiveRecord
|
||||
class << self
|
||||
def default_error_messages
|
||||
ActiveSupport::Deprecation.warn("ActiveRecord::Errors.default_error_messages has been deprecated. Please use 'active_record.error_messages'.t.")
|
||||
'active_record.error_messages'.t
|
||||
I18n.translate 'active_record.error_messages'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -43,7 +43,7 @@ module ActiveRecord
|
||||
# error can be added to the same +attribute+ in which case an array will be returned on a call to <tt>on(attribute)</tt>.
|
||||
# If no +msg+ is supplied, "invalid" is assumed.
|
||||
def add(attribute, message = nil)
|
||||
message ||= :"active_record.error_messages.invalid".t
|
||||
message ||= I18n.translate :"active_record.error_messages.invalid"
|
||||
@errors[attribute.to_s] ||= []
|
||||
@errors[attribute.to_s] << message
|
||||
end
|
||||
@@ -168,7 +168,7 @@ module ActiveRecord
|
||||
full_messages << message
|
||||
else
|
||||
key = :"active_record.human_attribute_names.#{@base.class.name.underscore.to_sym}.#{attr}"
|
||||
attr_name = key.t(locale) || @base.class.human_attribute_name(attr)
|
||||
attr_name = I18n.translate(key, locale, :raise => true) rescue @base.class.human_attribute_name(attr)
|
||||
full_messages << attr_name + " " + message
|
||||
end
|
||||
end
|
||||
|
||||
@@ -79,7 +79,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
|
||||
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').returns('Title')
|
||||
I18n.expects(:translate).with(:"active_record.human_attribute_names.topic.title", 'en-US', :raise => true).returns('Title')
|
||||
@topic.errors.full_messages :locale => 'en-US'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,7 +13,7 @@ module ActiveSupport #:nodoc:
|
||||
locale = options[:locale]
|
||||
locale ||= self.locale if respond_to?(:locale)
|
||||
|
||||
default = :'support.array.sentence_connector'.t(locale)
|
||||
default = I18n.translate(:'support.array.sentence_connector', locale)
|
||||
options.reverse_merge! :connector => default, :skip_last_comma => false
|
||||
options[:connector] = "#{options[:connector]} " unless options[:connector].nil? || options[:connector].strip == ''
|
||||
|
||||
|
||||
Submodule activesupport/lib/active_support/vendor/i18n-0.0.1 updated: 20c331666b...970bc7ab5f
@@ -1,75 +0,0 @@
|
||||
require 'abstract_unit'
|
||||
|
||||
class I18nTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@date = Date.parse("2008-7-2")
|
||||
@time = Time.utc(2008, 7, 2, 16, 47, 1)
|
||||
end
|
||||
|
||||
uses_mocha 'I18nTimeZoneTest' do
|
||||
def test_time_zone_localization_with_default_format
|
||||
Time.zone.stubs(:now).returns Time.local(2000)
|
||||
assert_equal "Sat, 01 Jan 2000 00:00:00 +0100", Time.zone.now.l
|
||||
end
|
||||
end
|
||||
|
||||
def test_date_localization_should_use_default_format
|
||||
assert_equal "2008-07-02", @date.l
|
||||
end
|
||||
|
||||
def test_date_localization_with_default_format
|
||||
assert_equal "2008-07-02", @date.l(nil, :default)
|
||||
end
|
||||
|
||||
def test_date_localization_with_short_format
|
||||
assert_equal "Jul 02", @date.l(nil, :short)
|
||||
end
|
||||
|
||||
def test_date_localization_with_long_format
|
||||
assert_equal "July 02, 2008", @date.l(nil, :long)
|
||||
end
|
||||
|
||||
def test_time_localization_should_use_default_format
|
||||
assert_equal "Wed, 02 Jul 2008 16:47:01 +0100", @time.l
|
||||
end
|
||||
|
||||
def test_time_localization_with_default_format
|
||||
assert_equal "Wed, 02 Jul 2008 16:47:01 +0100", @time.l(nil, :default)
|
||||
end
|
||||
|
||||
def test_time_localization_with_short_format
|
||||
assert_equal "02 Jul 16:47", @time.l(nil, :short)
|
||||
end
|
||||
|
||||
def test_time_localization_with_long_format
|
||||
assert_equal "July 02, 2008 16:47", @time.l(nil, :long)
|
||||
end
|
||||
|
||||
def test_day_names
|
||||
assert_equal Date::DAYNAMES, :'date.day_names'.t
|
||||
end
|
||||
|
||||
def test_abbr_day_names
|
||||
assert_equal Date::ABBR_DAYNAMES, :'date.abbr_day_names'.t
|
||||
end
|
||||
|
||||
def test_month_names
|
||||
assert_equal Date::MONTHNAMES, :'date.month_names'.t
|
||||
end
|
||||
|
||||
def test_abbr_month_names
|
||||
assert_equal Date::ABBR_MONTHNAMES, :'date.abbr_month_names'.t
|
||||
end
|
||||
|
||||
def test_date_order
|
||||
assert_equal [:year, :month, :day], :'date.order'.t
|
||||
end
|
||||
|
||||
def test_time_am
|
||||
assert_equal 'am', :'time.am'.t
|
||||
end
|
||||
|
||||
def test_time_pm
|
||||
assert_equal 'pm', :'time.pm'.t
|
||||
end
|
||||
end
|
||||
75
activesupport/test/i18n_test.rb
Normal file
75
activesupport/test/i18n_test.rb
Normal file
@@ -0,0 +1,75 @@
|
||||
require 'abstract_unit'
|
||||
|
||||
class I18nTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@date = Date.parse("2008-7-2")
|
||||
@time = Time.utc(2008, 7, 2, 16, 47, 1)
|
||||
end
|
||||
|
||||
uses_mocha 'I18nTimeZoneTest' do
|
||||
def test_time_zone_localization_with_default_format
|
||||
Time.zone.stubs(:now).returns Time.local(2000)
|
||||
assert_equal "Sat, 01 Jan 2000 00:00:00 +0100", I18n.localize(Time.zone.now)
|
||||
end
|
||||
end
|
||||
|
||||
def test_date_localization_should_use_default_format
|
||||
assert_equal "2008-07-02", I18n.localize(@date)
|
||||
end
|
||||
|
||||
def test_date_localization_with_default_format
|
||||
assert_equal "2008-07-02", I18n.localize(@date, nil, :default)
|
||||
end
|
||||
|
||||
def test_date_localization_with_short_format
|
||||
assert_equal "Jul 02", I18n.localize(@date, nil, :short)
|
||||
end
|
||||
|
||||
def test_date_localization_with_long_format
|
||||
assert_equal "July 02, 2008", I18n.localize(@date, nil, :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)
|
||||
end
|
||||
|
||||
def test_time_localization_with_short_format
|
||||
assert_equal "02 Jul 16:47", I18n.localize(@time, nil, :short)
|
||||
end
|
||||
|
||||
def test_time_localization_with_long_format
|
||||
assert_equal "July 02, 2008 16:47", I18n.localize(@time, nil, :long)
|
||||
end
|
||||
|
||||
def test_day_names
|
||||
assert_equal Date::DAYNAMES, I18n.translate(:'date.day_names')
|
||||
end
|
||||
|
||||
def test_abbr_day_names
|
||||
assert_equal Date::ABBR_DAYNAMES, I18n.translate(:'date.abbr_day_names')
|
||||
end
|
||||
|
||||
def test_month_names
|
||||
assert_equal Date::MONTHNAMES, I18n.translate(:'date.month_names')
|
||||
end
|
||||
|
||||
def test_abbr_month_names
|
||||
assert_equal Date::ABBR_MONTHNAMES, I18n.translate(:'date.abbr_month_names')
|
||||
end
|
||||
|
||||
def test_date_order
|
||||
assert_equal [:year, :month, :day], I18n.translate(:'date.order')
|
||||
end
|
||||
|
||||
def test_time_am
|
||||
assert_equal 'am', I18n.translate(:'time.am')
|
||||
end
|
||||
|
||||
def test_time_pm
|
||||
assert_equal 'pm', I18n.translate(:'time.pm')
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user