diff options
author | Tsutomu Kuroda <t-kuroda@oiax.jp> | 2012-01-05 00:23:10 +0900 |
---|---|---|
committer | Tsutomu Kuroda <t-kuroda@oiax.jp> | 2012-01-05 00:23:10 +0900 |
commit | 6724c8c8879dc41a4cdffc507353d8a114ca8028 (patch) | |
tree | cb6a20de1489d596d9cc6f871a7f37a791078ce9 /actionpack | |
parent | 78372b6cbb655227f4e6ddcb32187704659de84f (diff) | |
download | rails-6724c8c8879dc41a4cdffc507353d8a114ca8028.tar.gz rails-6724c8c8879dc41a4cdffc507353d8a114ca8028.tar.bz2 rails-6724c8c8879dc41a4cdffc507353d8a114ca8028.zip |
Infer currency negative format from positive one.
When a locale file sets the format of the positive
currency value as '%n %u', the default negative
currency format should be '-%n %u'.
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view/helpers/number_helper.rb | 1 | ||||
-rw-r--r-- | actionpack/test/template/number_helper_i18n_test.rb | 7 |
2 files changed, 8 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb index 1c0fdb8ff9..857c4fd992 100644 --- a/actionpack/lib/action_view/helpers/number_helper.rb +++ b/actionpack/lib/action_view/helpers/number_helper.rb @@ -114,6 +114,7 @@ module ActionView defaults = I18n.translate(:'number.format', :locale => options[:locale], :default => {}) currency = I18n.translate(:'number.currency.format', :locale => options[:locale], :default => {}) + currency[:negative_format] ||= "-" + currency[:format] if currency[:format] defaults = DEFAULT_CURRENCY_VALUES.merge(defaults).merge!(currency) defaults[:negative_format] = "-" + options[:format] if options[:format] diff --git a/actionpack/test/template/number_helper_i18n_test.rb b/actionpack/test/template/number_helper_i18n_test.rb index 5df09b4d3b..d6e9de9555 100644 --- a/actionpack/test/template/number_helper_i18n_test.rb +++ b/actionpack/test/template/number_helper_i18n_test.rb @@ -53,6 +53,13 @@ class NumberHelperTest < ActionView::TestCase assert_equal("-$10.00", number_to_currency(-10)) end end + + def test_number_to_currency_without_currency_negative_format + clean_i18n do + I18n.backend.store_translations 'ts', :number => { :currency => { :format => { :unit => '@', :format => '%n %u' } } } + assert_equal("-10.00 @", number_to_currency(-10, :locale => 'ts')) + end + end def test_number_with_i18n_precision #Delimiter was set to "" |