activesupport 2.3.5 → 2.3.6.pre

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activesupport might be problematic. Click here for more details.

Files changed (121) hide show
  1. data/CHANGELOG +23 -0
  2. data/lib/active_support.rb +1 -0
  3. data/lib/active_support/core_ext/date_time/conversions.rb +14 -3
  4. data/lib/active_support/core_ext/enumerable.rb +6 -0
  5. data/lib/active_support/core_ext/file/atomic.rb +2 -1
  6. data/lib/active_support/core_ext/numeric/conversions.rb +2 -2
  7. data/lib/active_support/core_ext/object.rb +1 -0
  8. data/lib/active_support/core_ext/object/metaclass.rb +6 -5
  9. data/lib/active_support/core_ext/object/singleton_class.rb +13 -0
  10. data/lib/active_support/core_ext/string.rb +0 -1
  11. data/lib/active_support/core_ext/string/output_safety.rb +148 -44
  12. data/lib/active_support/core_ext/time/calculations.rb +1 -1
  13. data/lib/active_support/inflector.rb +1 -1
  14. data/lib/active_support/json/backends/yajl.rb +40 -0
  15. data/lib/active_support/json/decoding.rb +16 -1
  16. data/lib/active_support/json/encoding.rb +11 -2
  17. data/lib/active_support/ordered_hash.rb +24 -1
  18. data/lib/active_support/vendor.rb +10 -2
  19. data/lib/active_support/vendor/i18n-0.3.3/CHANGELOG.textile +76 -0
  20. data/lib/active_support/vendor/{i18n-0.1.3 → i18n-0.3.3}/MIT-LICENSE +0 -0
  21. data/lib/active_support/vendor/i18n-0.3.3/README.textile +81 -0
  22. data/lib/active_support/vendor/i18n-0.3.3/Rakefile +24 -0
  23. data/lib/active_support/vendor/i18n-0.3.3/benchmark/example.yml +144 -0
  24. data/lib/active_support/vendor/i18n-0.3.3/benchmark/run.rb +71 -0
  25. data/lib/active_support/vendor/i18n-0.3.3/contributors.txt +17 -0
  26. data/lib/active_support/vendor/i18n-0.3.3/i18n.gemspec +165 -0
  27. data/lib/active_support/vendor/i18n-0.3.3/init.rb +1 -0
  28. data/lib/active_support/vendor/{i18n-0.1.3 → i18n-0.3.3}/lib/i18n.rb +99 -21
  29. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend.rb +17 -0
  30. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/active_record.rb +70 -0
  31. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/active_record/missing.rb +67 -0
  32. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/active_record/store_procs.rb +38 -0
  33. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/active_record/translation.rb +83 -0
  34. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/base.rb +259 -0
  35. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/cache.rb +75 -0
  36. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/cascade.rb +44 -0
  37. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/chain.rb +74 -0
  38. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/fallbacks.rb +52 -0
  39. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/fast.rb +68 -0
  40. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/gettext.rb +75 -0
  41. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/helpers.rb +80 -0
  42. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/interpolation_compiler.rb +119 -0
  43. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/metadata.rb +73 -0
  44. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/pluralization.rb +57 -0
  45. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/backend/simple.rb +22 -0
  46. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/core_ext/object/meta_class.rb +5 -0
  47. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/core_ext/string/interpolate.rb +99 -0
  48. data/lib/active_support/vendor/{i18n-0.1.3 → i18n-0.3.3}/lib/i18n/exceptions.rb +14 -6
  49. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/gettext.rb +25 -0
  50. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/helpers.rb +5 -0
  51. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/helpers/gettext.rb +64 -0
  52. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale.rb +6 -0
  53. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/fallbacks.rb +98 -0
  54. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/tag.rb +28 -0
  55. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/tag/parents.rb +24 -0
  56. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/tag/rfc4646.rb +76 -0
  57. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/locale/tag/simple.rb +41 -0
  58. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/version.rb +3 -0
  59. data/lib/active_support/vendor/i18n-0.3.3/test/all.rb +8 -0
  60. data/lib/active_support/vendor/i18n-0.3.3/test/api/basics.rb +15 -0
  61. data/lib/active_support/vendor/i18n-0.3.3/test/api/defaults.rb +40 -0
  62. data/lib/active_support/vendor/i18n-0.3.3/test/api/interpolation.rb +92 -0
  63. data/lib/active_support/vendor/i18n-0.3.3/test/api/link.rb +55 -0
  64. data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/date.rb +91 -0
  65. data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/date_time.rb +90 -0
  66. data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/procs.rb +54 -0
  67. data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/time.rb +84 -0
  68. data/lib/active_support/vendor/i18n-0.3.3/test/api/lookup.rb +45 -0
  69. data/lib/active_support/vendor/i18n-0.3.3/test/api/pluralization.rb +35 -0
  70. data/lib/active_support/vendor/i18n-0.3.3/test/api/procs.rb +40 -0
  71. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/active_record_test.rb +29 -0
  72. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/all_features_test.rb +40 -0
  73. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/cascade_test.rb +31 -0
  74. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/chain_test.rb +26 -0
  75. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/fallbacks_test.rb +33 -0
  76. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/fast_test.rb +31 -0
  77. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/pluralization_test.rb +33 -0
  78. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/simple_test.rb +21 -0
  79. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/active_record/missing_test.rb +60 -0
  80. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/active_record_test.rb +52 -0
  81. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/cache_test.rb +72 -0
  82. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/cascade_test.rb +66 -0
  83. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/chain_test.rb +64 -0
  84. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/fallbacks_test.rb +57 -0
  85. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/fast_test.rb +50 -0
  86. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/helpers_test.rb +26 -0
  87. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/interpolation_compiler_test.rb +107 -0
  88. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/metadata_test.rb +67 -0
  89. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/pluralization_test.rb +43 -0
  90. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/simple_test.rb +77 -0
  91. data/lib/active_support/vendor/i18n-0.3.3/test/cases/core_ext/string/interpolate_test.rb +94 -0
  92. data/lib/active_support/vendor/i18n-0.3.3/test/cases/gettext/api_test.rb +201 -0
  93. data/lib/active_support/vendor/i18n-0.3.3/test/cases/gettext/backend_test.rb +91 -0
  94. data/lib/active_support/vendor/{i18n-0.1.3/test → i18n-0.3.3/test/cases}/i18n_exceptions_test.rb +8 -10
  95. data/lib/active_support/vendor/i18n-0.3.3/test/cases/i18n_load_path_test.rb +23 -0
  96. data/lib/active_support/vendor/i18n-0.3.3/test/cases/i18n_test.rb +172 -0
  97. data/lib/active_support/vendor/i18n-0.3.3/test/cases/locale/fallbacks_test.rb +126 -0
  98. data/lib/active_support/vendor/i18n-0.3.3/test/cases/locale/tag/rfc4646_test.rb +143 -0
  99. data/lib/active_support/vendor/i18n-0.3.3/test/cases/locale/tag/simple_test.rb +33 -0
  100. data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/de.po +72 -0
  101. data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/en.rb +3 -0
  102. data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/en.yml +3 -0
  103. data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/plurals.rb +113 -0
  104. data/lib/active_support/vendor/i18n-0.3.3/test/test_helper.rb +100 -0
  105. data/lib/active_support/vendor/i18n-0.3.3/vendor/po_parser.rb +329 -0
  106. data/lib/active_support/version.rb +1 -1
  107. data/lib/active_support/whiny_nil.rb +1 -1
  108. data/lib/active_support/xml_mini/libxml.rb +23 -83
  109. data/lib/active_support/xml_mini/libxmlsax.rb +74 -0
  110. data/lib/active_support/xml_mini/nokogiri.rb +25 -22
  111. data/lib/active_support/xml_mini/nokogirisax.rb +73 -0
  112. metadata +108 -20
  113. data/lib/active_support/vendor/i18n-0.1.3/README.textile +0 -20
  114. data/lib/active_support/vendor/i18n-0.1.3/Rakefile +0 -5
  115. data/lib/active_support/vendor/i18n-0.1.3/i18n.gemspec +0 -27
  116. data/lib/active_support/vendor/i18n-0.1.3/lib/i18n/backend/simple.rb +0 -214
  117. data/lib/active_support/vendor/i18n-0.1.3/test/all.rb +0 -5
  118. data/lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb +0 -124
  119. data/lib/active_support/vendor/i18n-0.1.3/test/locale/en.rb +0 -1
  120. data/lib/active_support/vendor/i18n-0.1.3/test/locale/en.yml +0 -3
  121. data/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb +0 -567
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+
3
+ module Tests
4
+ module Api
5
+ module Link
6
+ define_method "test linked lookup: if a key resolves to a symbol it looks up the symbol" do
7
+ I18n.backend.store_translations 'en', {
8
+ :link => :linked,
9
+ :linked => 'linked'
10
+ }
11
+ assert_equal 'linked', I18n.backend.translate('en', :link)
12
+ end
13
+
14
+ define_method "test linked lookup: if a key resolves to a dot-separated symbol it looks up the symbol" do
15
+ I18n.backend.store_translations 'en', {
16
+ :link => :"foo.linked",
17
+ :foo => { :linked => 'linked' }
18
+ }
19
+ assert_equal('linked', I18n.backend.translate('en', :link))
20
+ end
21
+
22
+ define_method "test linked lookup: if a dot-separated key resolves to a symbol it looks up the symbol" do
23
+ I18n.backend.store_translations 'en', {
24
+ :foo => { :link => :linked },
25
+ :linked => 'linked'
26
+ }
27
+ assert_equal('linked', I18n.backend.translate('en', :'foo.link'))
28
+ end
29
+
30
+ define_method "test linked lookup: if a dot-separated key resolves to a dot-separated symbol it looks up the symbol" do
31
+ I18n.backend.store_translations 'en', {
32
+ :foo => { :link => :"bar.linked" },
33
+ :bar => { :linked => 'linked' }
34
+ }
35
+ assert_equal('linked', I18n.backend.translate('en', :'foo.link'))
36
+ end
37
+
38
+ define_method "test linked lookup: links refer to absolute keys even if a scope was given" do
39
+ I18n.backend.store_translations 'en', {
40
+ :foo => { :link => :linked, :linked => 'linked in foo' },
41
+ :linked => 'linked absolutely'
42
+ }
43
+ assert_equal 'linked absolutely', I18n.backend.translate('en', :link, :scope => :foo)
44
+ end
45
+
46
+ define_method "test linked lookup: a link can resolve to a namespace in the middle of a dot-separated key" do
47
+ I18n.backend.store_translations 'en', {
48
+ :activemodel => { :errors => { :messages => { :blank => "can't be blank" } } },
49
+ :activerecord => { :errors => { :messages => :"activemodel.errors.messages" } }
50
+ }
51
+ assert_equal "can't be blank", I18n.t(:"activerecord.errors.messages.blank")
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,91 @@
1
+ # encoding: utf-8
2
+
3
+ module Tests
4
+ module Api
5
+ module Localization
6
+ module Date
7
+ def setup
8
+ super
9
+ setup_date_translations
10
+ @date = ::Date.new(2008, 3, 1)
11
+ end
12
+
13
+ define_method "test localize Date: given the short format it uses it" do
14
+ # TODO should be Mrz, shouldn't it?
15
+ assert_equal '01. Mar', I18n.l(@date, :format => :short, :locale => :de)
16
+ end
17
+
18
+ define_method "test localize Date: given the long format it uses it" do
19
+ assert_equal '01. März 2008', I18n.l(@date, :format => :long, :locale => :de)
20
+ end
21
+
22
+ define_method "test localize Date: given the default format it uses it" do
23
+ assert_equal '01.03.2008', I18n.l(@date, :format => :default, :locale => :de)
24
+ end
25
+
26
+ define_method "test localize Date: given a day name format it returns the correct day name" do
27
+ assert_equal 'Samstag', I18n.l(@date, :format => '%A', :locale => :de)
28
+ end
29
+
30
+ define_method "test localize Date: given an abbreviated day name format it returns the correct abbreviated day name" do
31
+ assert_equal 'Sa', I18n.l(@date, :format => '%a', :locale => :de)
32
+ end
33
+
34
+ define_method "test localize Date: given a month name format it returns the correct month name" do
35
+ assert_equal 'März', I18n.l(@date, :format => '%B', :locale => :de)
36
+ end
37
+
38
+ define_method "test localize Date: given an abbreviated month name format it returns the correct abbreviated month name" do
39
+ # TODO should be Mrz, shouldn't it?
40
+ assert_equal 'Mar', I18n.l(@date, :format => '%b', :locale => :de)
41
+ end
42
+
43
+ define_method "test localize Date: given a format that resolves to a Proc it calls the Proc with the object" do
44
+ # TODO should be Mrz, shouldn't it?
45
+ assert_equal '[Sat, 01 Mar 2008, {}]', I18n.l(@date, :format => :proc, :locale => :de)
46
+ end
47
+
48
+ # TODO fails, but something along these lines probably should pass
49
+ # define_method "test localize Date: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
50
+ # assert_equal '[Sat Mar 01 06:00:00 UTC 2008, {:foo=>"foo"}]', I18n.l(@time, :format => :proc, :foo => 'foo', :locale => :de)
51
+ # end
52
+
53
+ define_method "test localize Date: given an unknown format it does not fail" do
54
+ assert_nothing_raised { I18n.l(@date, :format => '%x') }
55
+ end
56
+
57
+ define_method "test localize Date: given nil it raises I18n::ArgumentError" do
58
+ assert_raises(I18n::ArgumentError) { I18n.l(nil) }
59
+ end
60
+
61
+ define_method "test localize Date: given a plain Object it raises I18n::ArgumentError" do
62
+ assert_raises(I18n::ArgumentError) { I18n.l(Object.new) }
63
+ end
64
+
65
+ define_method "test localize Date: it does not alter the format string" do
66
+ assert_equal '01. Februar 2009', I18n.l(::Date.parse('2009-02-01'), :format => :long, :locale => :de)
67
+ assert_equal '01. Oktober 2009', I18n.l(::Date.parse('2009-10-01'), :format => :long, :locale => :de)
68
+ end
69
+
70
+ protected
71
+
72
+ def setup_date_translations
73
+ store_translations :de, {
74
+ :date => {
75
+ :formats => {
76
+ :default => "%d.%m.%Y",
77
+ :short => "%d. %b",
78
+ :long => "%d. %B %Y",
79
+ :proc => lambda { |*args| args.inspect }
80
+ },
81
+ :day_names => %w(Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag),
82
+ :abbr_day_names => %w(So Mo Di Mi Do Fr Sa),
83
+ :month_names => %w(Januar Februar März April Mai Juni Juli August September Oktober November Dezember).unshift(nil),
84
+ :abbr_month_names => %w(Jan Feb Mar Apr Mai Jun Jul Aug Sep Okt Nov Dez).unshift(nil)
85
+ }
86
+ }
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,90 @@
1
+ # encoding: utf-8
2
+
3
+ module Tests
4
+ module Api
5
+ module Localization
6
+ module DateTime
7
+ def setup
8
+ super
9
+ setup_datetime_translations
10
+ @datetime = ::DateTime.new(2008, 3, 1, 6)
11
+ @other_datetime = ::DateTime.new(2008, 3, 1, 18)
12
+ end
13
+
14
+ define_method "test localize DateTime: given the short format it uses it" do
15
+ # TODO should be Mrz, shouldn't it?
16
+ assert_equal '01. Mar 06:00', I18n.l(@datetime, :format => :short, :locale => :de)
17
+ end
18
+
19
+ define_method "test localize DateTime: given the long format it uses it" do
20
+ assert_equal '01. März 2008 06:00', I18n.l(@datetime, :format => :long, :locale => :de)
21
+ end
22
+
23
+ define_method "test localize DateTime: given the default format it uses it" do
24
+ # TODO should be Mrz, shouldn't it?
25
+ assert_equal 'Sa, 01. Mar 2008 06:00:00 +0000', I18n.l(@datetime, :format => :default, :locale => :de)
26
+ end
27
+
28
+ define_method "test localize DateTime: given a day name format it returns the correct day name" do
29
+ assert_equal 'Samstag', I18n.l(@datetime, :format => '%A', :locale => :de)
30
+ end
31
+
32
+ define_method "test localize DateTime: given an abbreviated day name format it returns the correct abbreviated day name" do
33
+ assert_equal 'Sa', I18n.l(@datetime, :format => '%a', :locale => :de)
34
+ end
35
+
36
+ define_method "test localize DateTime: given a month name format it returns the correct month name" do
37
+ assert_equal 'März', I18n.l(@datetime, :format => '%B', :locale => :de)
38
+ end
39
+
40
+ define_method "test localize DateTime: given an abbreviated month name format it returns the correct abbreviated month name" do
41
+ # TODO should be Mrz, shouldn't it?
42
+ assert_equal 'Mar', I18n.l(@datetime, :format => '%b', :locale => :de)
43
+ end
44
+
45
+ define_method "test localize DateTime: given a meridian indicator format it returns the correct meridian indicator" do
46
+ assert_equal 'am', I18n.l(@datetime, :format => '%p', :locale => :de)
47
+ assert_equal 'pm', I18n.l(@other_datetime, :format => '%p', :locale => :de)
48
+ end
49
+
50
+ define_method "test localize Date: given a format that resolves to a Proc it calls the Proc with the object" do
51
+ if can_store_procs?
52
+ assert_equal '[Sat, 01 Mar 2008 06:00:00 +0000, {}]', I18n.l(@datetime, :format => :proc, :locale => :de)
53
+ end
54
+ end
55
+
56
+ # TODO fails, but something along these lines probably should pass
57
+ # define_method "test localize DateTime: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
58
+ # assert_equal '1ter März 2008, 06:00 Uhr', I18n.l(@datetime, :long_ordinalized)
59
+ # end
60
+
61
+ define_method "test localize DateTime: given an unknown format it does not fail" do
62
+ assert_nothing_raised { I18n.l(@datetime, :format => '%x') }
63
+ end
64
+
65
+ protected
66
+
67
+ def setup_datetime_translations
68
+ # time translations might have been set up in Tests::Api::Localization::Time
69
+ I18n.t(:'time.formats.default', :locale => :de, :raise => true)
70
+ rescue
71
+ store_translations :de, {
72
+ :time => {
73
+ :formats => {
74
+ :default => "%a, %d. %b %Y %H:%M:%S %z",
75
+ :short => "%d. %b %H:%M",
76
+ :long => "%d. %B %Y %H:%M",
77
+ :long_ordinalized => lambda { |date, options|
78
+ tz = " (#{options[:timezone]})" if options[:timezone]
79
+ "#{date.day}ter %B %Y, %H:%M Uhr#{tz}"
80
+ }
81
+ },
82
+ :am => 'am',
83
+ :pm => 'pm'
84
+ }
85
+ }
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+
3
+ module Tests
4
+ module Api
5
+ module Localization
6
+ module Procs
7
+ define_method "test localize: using day names from lambdas" do
8
+ setup_time_proc_translations
9
+ time = ::Time.parse('2008-03-01 6:00 UTC')
10
+ assert_match /Суббота/, I18n.l(time, :format => "%A, %d %B", :locale => :ru)
11
+ assert_match /суббота/, I18n.l(time, :format => "%d %B (%A)", :locale => :ru)
12
+ end
13
+
14
+ define_method "test localize: using month names from lambdas" do
15
+ setup_time_proc_translations
16
+ time = ::Time.parse('2008-03-01 6:00 UTC')
17
+ assert_match /марта/, I18n.l(time, :format => "%d %B %Y", :locale => :ru)
18
+ assert_match /Март /, I18n.l(time, :format => "%B %Y", :locale => :ru)
19
+ end
20
+
21
+ define_method "test localize: using abbreviated day names from lambdas" do
22
+ setup_time_proc_translations
23
+ time = ::Time.parse('2008-03-01 6:00 UTC')
24
+ assert_match /марта/, I18n.l(time, :format => "%d %b %Y", :locale => :ru)
25
+ assert_match /март /, I18n.l(time, :format => "%b %Y", :locale => :ru)
26
+ end
27
+
28
+ protected
29
+
30
+ def setup_time_proc_translations
31
+ store_translations :ru, {
32
+ :date => {
33
+ :'day_names' => lambda { |key, options|
34
+ (options[:format] =~ /^%A/) ?
35
+ %w(Воскресенье Понедельник Вторник Среда Четверг Пятница Суббота) :
36
+ %w(воскресенье понедельник вторник среда четверг пятница суббота)
37
+ },
38
+ :'month_names' => lambda { |key, options|
39
+ (options[:format] =~ /(%d|%e)(\s*)?(%B)/) ?
40
+ %w(января февраля марта апреля мая июня июля августа сентября октября ноября декабря).unshift(nil) :
41
+ %w(Январь Февраль Март Апрель Май Июнь Июль Август Сентябрь Октябрь Ноябрь Декабрь).unshift(nil)
42
+ },
43
+ :'abbr_month_names' => lambda { |key, options|
44
+ (options[:format] =~ /(%d|%e)(\s*)(%b)/) ?
45
+ %w(янв. февр. марта апр. мая июня июля авг. сент. окт. нояб. дек.).unshift(nil) :
46
+ %w(янв. февр. март апр. май июнь июль авг. сент. окт. нояб. дек.).unshift(nil)
47
+ },
48
+ }
49
+ }
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,84 @@
1
+ # encoding: utf-8
2
+
3
+ module Tests
4
+ module Api
5
+ module Localization
6
+ module Time
7
+ def setup
8
+ super
9
+ setup_time_translations
10
+ @time = ::Time.parse('2008-03-01 6:00 UTC')
11
+ @other_time = ::Time.parse('2008-03-01 18:00 UTC')
12
+ end
13
+
14
+ define_method "test localize Time: given the short format it uses it" do
15
+ # TODO should be Mrz, shouldn't it?
16
+ assert_equal '01. Mar 06:00', I18n.l(@time, :format => :short, :locale => :de)
17
+ end
18
+
19
+ define_method "test localize Time: given the long format it uses it" do
20
+ assert_equal '01. März 2008 06:00', I18n.l(@time, :format => :long, :locale => :de)
21
+ end
22
+
23
+ # TODO Seems to break on Windows because ENV['TZ'] is ignored. What's a better way to do this?
24
+ # def test_localize_given_the_default_format_it_uses_it
25
+ # assert_equal 'Sa, 01. Mar 2008 06:00:00 +0000', I18n.l(@time, :format => :default, :locale => :de)
26
+ # end
27
+
28
+ define_method "test localize Time: given a day name format it returns the correct day name" do
29
+ assert_equal 'Samstag', I18n.l(@time, :format => '%A', :locale => :de)
30
+ end
31
+
32
+ define_method "test localize Time: given an abbreviated day name format it returns the correct abbreviated day name" do
33
+ assert_equal 'Sa', I18n.l(@time, :format => '%a', :locale => :de)
34
+ end
35
+
36
+ define_method "test localize Time: given a month name format it returns the correct month name" do
37
+ assert_equal 'März', I18n.l(@time, :format => '%B', :locale => :de)
38
+ end
39
+
40
+ define_method "test localize Time: given an abbreviated month name format it returns the correct abbreviated month name" do
41
+ # TODO should be Mrz, shouldn't it?
42
+ assert_equal 'Mar', I18n.l(@time, :format => '%b', :locale => :de)
43
+ end
44
+
45
+ define_method "test localize Time: given a meridian indicator format it returns the correct meridian indicator" do
46
+ assert_equal 'am', I18n.l(@time, :format => '%p', :locale => :de)
47
+ assert_equal 'pm', I18n.l(@other_time, :format => '%p', :locale => :de)
48
+ end
49
+
50
+ define_method "test localize Time: given a format that resolves to a Proc it calls the Proc with the object" do
51
+ if can_store_procs?
52
+ assert_equal '[Sat, 01 Mar 2008 06:00:00 +0000, {}]', I18n.l(@datetime, :format => :proc, :locale => :de)
53
+ end
54
+ end
55
+
56
+ # TODO fails, but something along these lines probably should pass
57
+ # define_method "test localize Time: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
58
+ # assert_equal '[Sat Mar 01 06:00:00 UTC 2008, {:foo=>"foo"}]', I18n.l(@time, :format => :proc, :foo => 'foo', :locale => :de)
59
+ # end
60
+
61
+ define_method "test localize Time: given an unknown format it does not fail" do
62
+ assert_nothing_raised { I18n.l(@time, :format => '%x') }
63
+ end
64
+
65
+ protected
66
+
67
+ def setup_time_translations
68
+ store_translations :de, {
69
+ :time => {
70
+ :formats => {
71
+ :default => "%a, %d. %b %Y %H:%M:%S %z",
72
+ :short => "%d. %b %H:%M",
73
+ :long => "%d. %B %Y %H:%M",
74
+ :proc => lambda { |*args| args.inspect }
75
+ },
76
+ :am => 'am',
77
+ :pm => 'pm'
78
+ }
79
+ }
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ module Tests
4
+ module Api
5
+ module Lookup
6
+ def setup
7
+ super
8
+ store_translations(:foo => { :bar => 'bar', :baz => 'baz' }, :bla => false)
9
+ end
10
+
11
+ define_method "test lookup: given a nested key it looks up the nested hash value" do
12
+ assert_equal 'bar', I18n.t(:'foo.bar')
13
+ end
14
+
15
+ define_method "test make sure we can store a native false value as well" do
16
+ assert_equal false, I18n.t(:bla)
17
+ end
18
+
19
+ define_method "test lookup: given a missing key, no default and no raise option it returns an error message" do
20
+ assert_equal "translation missing: en, missing", I18n.t(:missing)
21
+ end
22
+
23
+ define_method "test lookup: given a missing key, no default and the raise option it raises MissingTranslationData" do
24
+ assert_raises(I18n::MissingTranslationData) { I18n.t(:missing, :raise => true) }
25
+ end
26
+
27
+ define_method "test lookup: given an array of keys it translates all of them" do
28
+ assert_equal %w(bar baz), I18n.t([:bar, :baz], :scope => [:foo])
29
+ end
30
+
31
+ define_method "test lookup: using a custom scope separator" do
32
+ # data must have been stored using the custom separator when using the ActiveRecord backend
33
+ I18n.backend.store_translations(:en, { :foo => { :bar => 'bar' } }, { :separator => '|' })
34
+ assert_equal 'bar', I18n.t('foo|bar', :separator => '|')
35
+ end
36
+
37
+ # In fact it probably *should* fail but Rails currently relies on using the default locale instead.
38
+ # So we'll stick to this for now until we get it fixed in Rails.
39
+ define_method "test lookup: given nil as a locale it does not raise but use the default locale" do
40
+ # assert_raises(I18n::InvalidLocale) { I18n.t(:bar, :locale => nil) }
41
+ assert_nothing_raised { I18n.t(:bar, :locale => nil) }
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+
3
+ module Tests
4
+ module Api
5
+ module Pluralization
6
+ define_method "test pluralization: given 0 it returns the :zero translation if it is defined" do
7
+ assert_equal 'zero', I18n.t(:default => { :zero => 'zero' }, :count => 0)
8
+ end
9
+
10
+ define_method "test pluralization: given 0 it returns the :other translation if :zero is not defined" do
11
+ assert_equal 'bars', I18n.t(:default => { :other => 'bars' }, :count => 0)
12
+ end
13
+
14
+ define_method "test pluralization: given 1 it returns the singular translation" do
15
+ assert_equal 'bar', I18n.t(:default => { :one => 'bar' }, :count => 1)
16
+ end
17
+
18
+ define_method "test pluralization: given 2 it returns the :other translation" do
19
+ assert_equal 'bars', I18n.t(:default => { :other => 'bars' }, :count => 2)
20
+ end
21
+
22
+ define_method "test pluralization: given 3 it returns the :other translation" do
23
+ assert_equal 'bars', I18n.t(:default => { :other => 'bars' }, :count => 3)
24
+ end
25
+
26
+ define_method "test pluralization: given nil it returns the whole entry" do
27
+ assert_equal({ :one => 'bar' }, I18n.t(:default => { :one => 'bar' }, :count => nil))
28
+ end
29
+
30
+ define_method "test pluralization: given incomplete pluralization data it raises I18n::InvalidPluralizationData" do
31
+ assert_raises(I18n::InvalidPluralizationData) { I18n.t(:default => { :one => 'bar' }, :count => 2) }
32
+ end
33
+ end
34
+ end
35
+ end