aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers
diff options
context:
space:
mode:
authorYaroslav Markin <yaroslav@markin.net>2008-11-23 17:30:59 +0300
committerJeremy Kemper <jeremy@bitsweat.net>2008-11-23 13:11:59 -0800
commitd36158794b19ee8ea49d74061218b37d4301f0f9 (patch)
tree1e044f880a2aa931804e7d1674200fa68cafec19 /actionpack/lib/action_view/helpers
parent9d4ae40bb40b2354c4061a23ae4db9a28e3174e6 (diff)
downloadrails-d36158794b19ee8ea49d74061218b37d4301f0f9.tar.gz
rails-d36158794b19ee8ea49d74061218b37d4301f0f9.tar.bz2
rails-d36158794b19ee8ea49d74061218b37d4301f0f9.zip
Add i18n for number_to_human_size() helper storage units. Translation key is number.human.storage_units.
[#1448 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'actionpack/lib/action_view/helpers')
-rw-r--r--actionpack/lib/action_view/helpers/number_helper.rb7
1 files changed, 3 insertions, 4 deletions
diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb
index 77f19b36a6..3e734ccaab 100644
--- a/actionpack/lib/action_view/helpers/number_helper.rb
+++ b/actionpack/lib/action_view/helpers/number_helper.rb
@@ -220,8 +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
# reporting file sizes to users. This method returns nil if
@@ -257,6 +255,7 @@ module ActionView
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)
+ storage_units = I18n.translate(:'number.human.storage_units', :locale => options[:locale], :raise => true)
unless args.empty?
ActiveSupport::Deprecation.warn('number_to_human_size takes an option hash ' +
@@ -268,12 +267,12 @@ module ActionView
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)