From 17db28f1ca0597fa1e9abdcacd934ca27d589fb9 Mon Sep 17 00:00:00 2001 From: Yaroslav Markin Date: Thu, 1 Jan 2009 21:29:11 +0300 Subject: Improve i18n support for number_to_human_size helper: * now using pluralization properly * storage unit translations moved to number.human.storage_units.units * introduced number.human.storage_units.format for languages that do not follow "{{number}} {{unit}}" format (Japanese) NOTE: I18n table changed, you will need to update your translations. [#1634 state:committed] Signed-off-by: Jeremy Kemper --- .../test/template/number_helper_i18n_test.rb | 24 +++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/number_helper_i18n_test.rb b/actionpack/test/template/number_helper_i18n_test.rb index 2528bead36..3fdf991a44 100644 --- a/actionpack/test/template/number_helper_i18n_test.rb +++ b/actionpack/test/template/number_helper_i18n_test.rb @@ -10,7 +10,9 @@ class NumberHelperI18nTests < Test::Unit::TestCase @number_defaults = { :precision => 3, :delimiter => ',', :separator => '.' } @currency_defaults = { :unit => '$', :format => '%u%n', :precision => 2 } @human_defaults = { :precision => 1 } - @human_storage_units_defaults = %w(Bytes KB MB GB TB) + @human_storage_units_format_default = "%n %u" + @human_storage_units_units_byte_other = "Bytes" + @human_storage_units_units_kb_other = "KB" @percentage_defaults = { :delimiter => '' } @precision_defaults = { :delimiter => '' } @@ -48,10 +50,22 @@ class NumberHelperI18nTests < Test::Unit::TestCase I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults) I18n.expects(:translate).with(:'number.human.format', :locale => 'en', :raise => true).returns(@human_defaults) - I18n.expects(:translate).with(:'number.human.storage_units', :locale => 'en', - :raise => true).returns(@human_storage_units_defaults) - # can't be called with 1 because this directly returns without calling I18n.translate - number_to_human_size(1025, :locale => 'en') + I18n.expects(:translate).with(:'number.human.storage_units.format', :locale => 'en', + :raise => true).returns(@human_storage_units_format_default) + I18n.expects(:translate).with(:'number.human.storage_units.units.kb', :locale => 'en', :count => 2, + :raise => true).returns(@human_storage_units_units_kb_other) + # 2KB + number_to_human_size(2048, :locale => 'en') + + I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults) + I18n.expects(:translate).with(:'number.human.format', :locale => 'en', + :raise => true).returns(@human_defaults) + I18n.expects(:translate).with(:'number.human.storage_units.format', :locale => 'en', + :raise => true).returns(@human_storage_units_format_default) + I18n.expects(:translate).with(:'number.human.storage_units.units.byte', :locale => 'en', :count => 42, + :raise => true).returns(@human_storage_units_units_byte_other) + # 42 Bytes + number_to_human_size(42, :locale => 'en') end end end -- cgit v1.2.3