aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support.rb4
-rw-r--r--activesupport/lib/active_support/core_ext/array/conversions.rb11
-rw-r--r--activesupport/lib/active_support/locale/en-US.rb28
-rw-r--r--activesupport/lib/active_support/vendor.rb10
m---------activesupport/lib/active_support/vendor/i18n-0.0.10
-rw-r--r--activesupport/test/i18n_test.rb75
6 files changed, 123 insertions, 5 deletions
diff --git a/activesupport/lib/active_support.rb b/activesupport/lib/active_support.rb
index 0526057b15..1df911a3f2 100644
--- a/activesupport/lib/active_support.rb
+++ b/activesupport/lib/active_support.rb
@@ -57,6 +57,10 @@ require 'active_support/base64'
require 'active_support/time_with_zone'
+I18n.backend.populate do
+ require 'active_support/locale/en-US.rb'
+end
+
Inflector = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('Inflector', 'ActiveSupport::Inflector')
Dependencies = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('Dependencies', 'ActiveSupport::Dependencies')
TimeZone = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('TimeZone', 'ActiveSupport::TimeZone')
diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb
index 49ada8f174..e67b719ddb 100644
--- a/activesupport/lib/active_support/core_ext/array/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/array/conversions.rb
@@ -6,10 +6,12 @@ module ActiveSupport #:nodoc:
module Conversions
# Converts the array to a comma-separated sentence where the last element is joined by the connector word. Options:
# * <tt>:connector</tt> - The word used to join the last element in arrays with two or more elements (default: "and")
- # * <tt>:skip_last_comma</tt> - Set to true to return "a, b and c" instead of "a, b, and c".
- def to_sentence(options = {})
- options.assert_valid_keys(:connector, :skip_last_comma)
- options.reverse_merge! :connector => 'and', :skip_last_comma => false
+ # * <tt>:skip_last_comma</tt> - Set to true to return "a, b and c" instead of "a, b, and c".
+ def to_sentence(options = {})
+ options.assert_valid_keys(:connector, :skip_last_comma, :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 == ''
case length
@@ -23,6 +25,7 @@ module ActiveSupport #:nodoc:
"#{self[0...-1].join(', ')}#{options[:skip_last_comma] ? '' : ','} #{options[:connector]}#{self[-1]}"
end
end
+
# Calls <tt>to_param</tt> on all its elements and joins the result with
# slashes. This is used by <tt>url_for</tt> in Action Pack.
diff --git a/activesupport/lib/active_support/locale/en-US.rb b/activesupport/lib/active_support/locale/en-US.rb
new file mode 100644
index 0000000000..51324a90bf
--- /dev/null
+++ b/activesupport/lib/active_support/locale/en-US.rb
@@ -0,0 +1,28 @@
+I18n.backend.store_translations :'en-US', {
+ :support => {
+ :array => {
+ :sentence_connector => 'and'
+ }
+ },
+ :date => {
+ :formats => {
+ :default => "%Y-%m-%d",
+ :short => "%b %d",
+ :long => "%B %d, %Y",
+ },
+ :day_names => Date::DAYNAMES,
+ :abbr_day_names => Date::ABBR_DAYNAMES,
+ :month_names => Date::MONTHNAMES,
+ :abbr_month_names => Date::ABBR_MONTHNAMES,
+ :order => [:year, :month, :day]
+ },
+ :time => {
+ :formats => {
+ :default => "%a, %d %b %Y %H:%M:%S %z",
+ :short => "%d %b %H:%M",
+ :long => "%B %d, %Y %H:%M",
+ },
+ :am => 'am',
+ :pm => 'pm'
+ }
+} \ No newline at end of file
diff --git a/activesupport/lib/active_support/vendor.rb b/activesupport/lib/active_support/vendor.rb
index a02e42f791..381471b833 100644
--- a/activesupport/lib/active_support/vendor.rb
+++ b/activesupport/lib/active_support/vendor.rb
@@ -23,4 +23,12 @@ begin
gem 'tzinfo', '~> 0.3.9'
rescue Gem::LoadError
$:.unshift "#{File.dirname(__FILE__)}/vendor/tzinfo-0.3.9"
-end \ No newline at end of file
+end
+
+# TODO I18n gem has not been released yet
+# begin
+# gem 'i18n', '~> 0.0.1'
+# rescue Gem::LoadError
+ $:.unshift "#{File.dirname(__FILE__)}/vendor/i18n-0.0.1/lib"
+ require 'i18n'
+# end \ No newline at end of file
diff --git a/activesupport/lib/active_support/vendor/i18n-0.0.1 b/activesupport/lib/active_support/vendor/i18n-0.0.1
new file mode 160000
+Subproject 46aad289935eaf059c429acb5f3bfa0946f2d99
diff --git a/activesupport/test/i18n_test.rb b/activesupport/test/i18n_test.rb
new file mode 100644
index 0000000000..17074b6cc6
--- /dev/null
+++ b/activesupport/test/i18n_test.rb
@@ -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, :format => :default)
+ end
+
+ def test_date_localization_with_short_format
+ 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, :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, :format => :default)
+ end
+
+ def test_time_localization_with_short_format
+ 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, :format => :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