aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorTarmo Tänav <tarmo@itech.ee>2008-10-07 14:23:05 +0300
committerPratik Naik <pratiknaik@gmail.com>2008-10-09 01:19:02 +0100
commitd69b4b7bea28fcab04f61afe381e06fa8e37b429 (patch)
treeeb58b3068cbe3a76e79a0c373f1458e4d05ab083 /activesupport/lib
parent0dea211f44d85e9c28963784286838bfa6c343f9 (diff)
downloadrails-d69b4b7bea28fcab04f61afe381e06fa8e37b429.tar.gz
rails-d69b4b7bea28fcab04f61afe381e06fa8e37b429.tar.bz2
rails-d69b4b7bea28fcab04f61afe381e06fa8e37b429.zip
Made i18n simple backend able to store false values (and not confuse them with nil or lack of value)
Implemented support.array.skip_last_comma i18n key for Array#to_sentence, this also tests the ability to store false. Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/core_ext/array/conversions.rb3
-rw-r--r--activesupport/lib/active_support/locale/en-US.yml1
-rw-r--r--activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb16
3 files changed, 17 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb
index e67b719ddb..11c128da22 100644
--- a/activesupport/lib/active_support/core_ext/array/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/array/conversions.rb
@@ -11,7 +11,8 @@ module ActiveSupport #:nodoc:
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
+ default_skip_last_comma = I18n.translate(:'support.array.skip_last_comma', :locale => options[:locale])
+ options.reverse_merge! :connector => default, :skip_last_comma => default_skip_last_comma
options[:connector] = "#{options[:connector]} " unless options[:connector].nil? || options[:connector].strip == ''
case length
diff --git a/activesupport/lib/active_support/locale/en-US.yml b/activesupport/lib/active_support/locale/en-US.yml
index 60ecb1d42a..c31694b9d6 100644
--- a/activesupport/lib/active_support/locale/en-US.yml
+++ b/activesupport/lib/active_support/locale/en-US.yml
@@ -29,3 +29,4 @@ en-US:
support:
array:
sentence_connector: "and"
+ skip_last_comma: false
diff --git a/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb b/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb
index 2dbaf8a405..30e3655b7b 100644
--- a/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb
+++ b/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb
@@ -30,7 +30,13 @@ module I18n
options.delete(:default)
values = options.reject{|name, value| reserved.include? name }
- entry = lookup(locale, key, scope) || default(locale, default, options) || raise(I18n::MissingTranslationData.new(locale, key, options))
+ entry = lookup(locale, key, scope)
+ if entry.nil?
+ entry = default(locale, default, options)
+ if entry.nil?
+ raise(I18n::MissingTranslationData.new(locale, key, options))
+ end
+ end
entry = pluralize locale, entry, count
entry = interpolate locale, entry, values
entry
@@ -83,7 +89,13 @@ module I18n
return unless key
init_translations unless initialized?
keys = I18n.send :normalize_translation_keys, locale, key, scope
- keys.inject(translations){|result, k| result[k.to_sym] or return nil }
+ keys.inject(translations) do |result, k|
+ if (x = result[k.to_sym]).nil?
+ return nil
+ else
+ x
+ end
+ end
end
# Evaluates a default translation.