diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb index 77f19b3..6dff90c 100644 --- a/actionpack/lib/action_view/helpers/number_helper.rb +++ b/actionpack/lib/action_view/helpers/number_helper.rb @@ -220,7 +220,6 @@ module ActionView end end - STORAGE_UNITS = %w( Bytes KB MB GB TB ).freeze # Formats the bytes in +size+ into a more understandable representation # (e.g., giving it 1500 yields 1.5 KB). This method is useful for @@ -253,7 +252,8 @@ module ActionView options = args.extract_options! options.symbolize_keys! - + + storage_units = I18n.translate(:'number.human.format.storage_units', :locale => options[:locale], :raise => true) rescue %w( Bytes KB MB GB TB PB ) defaults = I18n.translate(:'number.format', :locale => options[:locale], :raise => true) rescue {} human = I18n.translate(:'number.human.format', :locale => options[:locale], :raise => true) rescue {} defaults = defaults.merge(human) @@ -264,16 +264,16 @@ module ActionView precision = args[0] || defaults[:precision] end - precision ||= (options[:precision] || defaults[:precision]) - separator ||= (options[:separator] || defaults[:separator]) - delimiter ||= (options[:delimiter] || defaults[:delimiter]) + precision ||= (options[:precision] || defaults[:precision] || 1) + separator ||= (options[:separator] || defaults[:separator] || "") + delimiter ||= (options[:delimiter] || defaults[:delimiter] || "") - max_exp = STORAGE_UNITS.size - 1 + max_exp = storage_units.size - 1 number = Float(number) exponent = (Math.log(number) / Math.log(1024)).to_i # Convert to base 1024 exponent = max_exp if exponent > max_exp # we need this to avoid overflow for the highest unit number /= 1024 ** exponent - unit = STORAGE_UNITS[exponent] + unit = storage_units[exponent] begin escaped_separator = Regexp.escape(separator)