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'.
This commit is contained in:
parent
78372b6cbb
commit
6724c8c887
@ -114,6 +114,7 @@ def number_to_currency(number, options = {})
|
|||||||
|
|
||||||
defaults = I18n.translate(:'number.format', :locale => options[:locale], :default => {})
|
defaults = I18n.translate(:'number.format', :locale => options[:locale], :default => {})
|
||||||
currency = I18n.translate(:'number.currency.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 = DEFAULT_CURRENCY_VALUES.merge(defaults).merge!(currency)
|
||||||
defaults[:negative_format] = "-" + options[:format] if options[:format]
|
defaults[:negative_format] = "-" + options[:format] if options[:format]
|
||||||
|
@ -53,6 +53,13 @@ def test_number_to_currency_with_clean_i18n_settings
|
|||||||
assert_equal("-$10.00", number_to_currency(-10))
|
assert_equal("-$10.00", number_to_currency(-10))
|
||||||
end
|
end
|
||||||
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
|
def test_number_with_i18n_precision
|
||||||
#Delimiter was set to ""
|
#Delimiter was set to ""
|
||||||
|
Loading…
Reference in New Issue
Block a user