i18n 0.4.2 → 0.5.0beta1

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

Potentially problematic release.


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

Files changed (43) hide show
  1. data/CHANGELOG.textile +12 -3
  2. data/lib/i18n.rb +18 -21
  3. data/lib/i18n/backend.rb +0 -1
  4. data/lib/i18n/backend/base.rb +0 -13
  5. data/lib/i18n/backend/cache.rb +0 -2
  6. data/lib/i18n/backend/cascade.rb +6 -10
  7. data/lib/i18n/backend/chain.rb +0 -2
  8. data/lib/i18n/backend/cldr.rb +1 -2
  9. data/lib/i18n/backend/fallbacks.rb +0 -2
  10. data/lib/i18n/backend/gettext.rb +0 -2
  11. data/lib/i18n/backend/interpolation_compiler.rb +1 -3
  12. data/lib/i18n/backend/key_value.rb +1 -3
  13. data/lib/i18n/backend/memoize.rb +1 -3
  14. data/lib/i18n/backend/pluralization.rb +0 -2
  15. data/lib/i18n/backend/simple.rb +0 -2
  16. data/lib/i18n/config.rb +2 -2
  17. data/lib/i18n/core_ext/string/interpolate.rb +1 -3
  18. data/lib/i18n/exceptions.rb +29 -6
  19. data/lib/i18n/gettext.rb +0 -2
  20. data/lib/i18n/gettext/helpers.rb +0 -1
  21. data/lib/i18n/locale/fallbacks.rb +0 -2
  22. data/lib/i18n/locale/tag/parents.rb +0 -2
  23. data/lib/i18n/locale/tag/rfc4646.rb +0 -2
  24. data/lib/i18n/locale/tag/simple.rb +0 -2
  25. data/lib/i18n/tests.rb +12 -0
  26. data/lib/i18n/tests/basics.rb +54 -0
  27. data/lib/i18n/tests/defaults.rb +40 -0
  28. data/lib/i18n/tests/interpolation.rb +133 -0
  29. data/lib/i18n/tests/link.rb +56 -0
  30. data/lib/i18n/tests/localization.rb +19 -0
  31. data/lib/i18n/tests/localization/date.rb +84 -0
  32. data/lib/i18n/tests/localization/date_time.rb +77 -0
  33. data/lib/i18n/tests/localization/procs.rb +103 -0
  34. data/lib/i18n/tests/localization/time.rb +76 -0
  35. data/lib/i18n/tests/lookup.rb +74 -0
  36. data/lib/i18n/tests/pluralization.rb +35 -0
  37. data/lib/i18n/tests/procs.rb +55 -0
  38. data/lib/i18n/version.rb +1 -1
  39. metadata +19 -10
  40. data/lib/i18n/backend/active_record.rb +0 -61
  41. data/lib/i18n/backend/active_record/missing.rb +0 -65
  42. data/lib/i18n/backend/active_record/store_procs.rb +0 -38
  43. data/lib/i18n/backend/active_record/translation.rb +0 -110
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+ module I18n
4
+ module Tests
5
+ module Defaults
6
+ def setup
7
+ super
8
+ I18n.backend.store_translations(:en, :foo => { :bar => 'bar', :baz => 'baz' })
9
+ end
10
+
11
+ test "defaults: given nil as a key it returns the given default" do
12
+ assert_equal 'default', I18n.t(nil, :default => 'default')
13
+ end
14
+
15
+ test "defaults: given a symbol as a default it translates the symbol" do
16
+ assert_equal 'bar', I18n.t(nil, :default => :'foo.bar')
17
+ end
18
+
19
+ test "defaults: given a symbol as a default and a scope it stays inside the scope when looking up the symbol" do
20
+ assert_equal 'bar', I18n.t(:missing, :default => :bar, :scope => :foo)
21
+ end
22
+
23
+ test "defaults: given an array as a default it returns the first match" do
24
+ assert_equal 'bar', I18n.t(:does_not_exist, :default => [:does_not_exist_2, :'foo.bar'])
25
+ end
26
+
27
+ test "defaults: given an array of missing keys it raises a MissingTranslationData exception" do
28
+ assert_raise I18n::MissingTranslationData do
29
+ I18n.t(:does_not_exist, :default => [:does_not_exist_2, :does_not_exist_3], :raise => true)
30
+ end
31
+ end
32
+
33
+ test "defaults: using a custom scope separator" do
34
+ # data must have been stored using the custom separator when using the ActiveRecord backend
35
+ I18n.backend.store_translations(:en, { :foo => { :bar => 'bar' } }, { :separator => '|' })
36
+ assert_equal 'bar', I18n.t(nil, :default => :'foo|bar', :separator => '|')
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,133 @@
1
+ # encoding: utf-8
2
+
3
+ module I18n
4
+ module Tests
5
+ module Interpolation
6
+ # If no interpolation parameter is not given, I18n should not alter the string.
7
+ # This behavior is due to three reasons:
8
+ #
9
+ # * Checking interpolation keys in all strings hits performance, badly;
10
+ #
11
+ # * This allows us to retrieve untouched values through I18n. For example
12
+ # I could have a middleware that returns I18n lookup results in JSON
13
+ # to be processed through Javascript. Leaving the keys untouched allows
14
+ # the interpolation to happen at the javascript level;
15
+ #
16
+ # * Security concerns: if I allow users to translate a web site, they can
17
+ # insert %{} in messages causing the I18n lookup to fail in every request.
18
+ #
19
+ test "interpolation: given no values it does not alter the string" do
20
+ assert_equal 'Hi %{name}!', interpolate(:default => 'Hi %{name}!')
21
+ end
22
+
23
+ test "interpolation: given values it interpolates them into the string" do
24
+ assert_equal 'Hi David!', interpolate(:default => 'Hi %{name}!', :name => 'David')
25
+ end
26
+
27
+ test "interpolation: given a nil value it still interpolates it into the string" do
28
+ assert_equal 'Hi !', interpolate(:default => 'Hi %{name}!', :name => nil)
29
+ end
30
+
31
+ test "interpolation: given a lambda as a value it calls it if the string contains the key" do
32
+ assert_equal 'Hi David!', interpolate(:default => 'Hi %{name}!', :name => lambda { |*args| 'David' })
33
+ end
34
+
35
+ test "interpolation: given a lambda as a value it does not call it if the string does not contain the key" do
36
+ assert_nothing_raised { interpolate(:default => 'Hi!', :name => lambda { |*args| raise 'fail' }) }
37
+ end
38
+
39
+ test "interpolation: given values but missing a key it raises I18n::MissingInterpolationArgument" do
40
+ assert_raise(I18n::MissingInterpolationArgument) do
41
+ interpolate(:default => '%{foo}', :bar => 'bar')
42
+ end
43
+ end
44
+
45
+ test "interpolation: it does not raise I18n::MissingInterpolationArgument for escaped variables" do
46
+ assert_nothing_raised(I18n::MissingInterpolationArgument) do
47
+ assert_equal 'Barr %{foo}', interpolate(:default => '%{bar} %%{foo}', :bar => 'Barr')
48
+ end
49
+ end
50
+
51
+ test "interpolation: it does not change the original, stored translation string" do
52
+ I18n.backend.store_translations(:en, :interpolate => 'Hi %{name}!')
53
+ assert_equal 'Hi David!', interpolate(:interpolate, :name => 'David')
54
+ assert_equal 'Hi Yehuda!', interpolate(:interpolate, :name => 'Yehuda')
55
+ end
56
+
57
+ test "interpolation: given the translation is in utf-8 it still works" do
58
+ assert_equal 'Häi David!', interpolate(:default => 'Häi %{name}!', :name => 'David')
59
+ end
60
+
61
+ test "interpolation: given the value is in utf-8 it still works" do
62
+ assert_equal 'Hi ゆきひろ!', interpolate(:default => 'Hi %{name}!', :name => 'ゆきひろ')
63
+ end
64
+
65
+ test "interpolation: given the translation and the value are in utf-8 it still works" do
66
+ assert_equal 'こんにちは、ゆきひろさん!', interpolate(:default => 'こんにちは、%{name}さん!', :name => 'ゆきひろ')
67
+ end
68
+
69
+ if Kernel.const_defined?(:Encoding)
70
+ test "interpolation: given a euc-jp translation and a utf-8 value it raises Encoding::CompatibilityError" do
71
+ assert_raise(Encoding::CompatibilityError) do
72
+ interpolate(:default => euc_jp('こんにちは、%{name}さん!'), :name => 'ゆきひろ')
73
+ end
74
+ end
75
+
76
+ test "interpolation: given a utf-8 translation and a euc-jp value it raises Encoding::CompatibilityError" do
77
+ assert_raise(Encoding::CompatibilityError) do
78
+ interpolate(:default => 'こんにちは、%{name}さん!', :name => euc_jp('ゆきひろ'))
79
+ end
80
+ end
81
+
82
+ test "interpolation: ASCII strings in the backend should be encoded to UTF8 if interpolation options are in UTF8" do
83
+ I18n.backend.store_translations 'en', 'encoding' => ('%{who} let me go'.force_encoding("ASCII"))
84
+ result = I18n.t 'encoding', :who => "måmmå miå"
85
+ assert_equal Encoding::UTF_8, result.encoding
86
+ end
87
+
88
+ test "interpolation: UTF8 strings in the backend are still returned as UTF8 with ASCII interpolation" do
89
+ I18n.backend.store_translations 'en', 'encoding' => 'måmmå miå %{what}'
90
+ result = I18n.t 'encoding', :what => 'let me go'.force_encoding("ASCII")
91
+ assert_equal Encoding::UTF_8, result.encoding
92
+ end
93
+
94
+ test "interpolation: UTF8 strings in the backend are still returned as UTF8 even with numbers interpolation" do
95
+ I18n.backend.store_translations 'en', 'encoding' => '%{count} times: måmmå miå'
96
+ result = I18n.t 'encoding', :count => 3
97
+ assert_equal Encoding::UTF_8, result.encoding
98
+ end
99
+ end
100
+
101
+ test "interpolation: given a translations containing a reserved key it raises I18n::ReservedInterpolationKey" do
102
+ assert_raise(I18n::ReservedInterpolationKey) { interpolate(:default => '%{default}', :foo => :bar) }
103
+ assert_raise(I18n::ReservedInterpolationKey) { interpolate(:default => '%{scope}', :foo => :bar) }
104
+ assert_raise(I18n::ReservedInterpolationKey) { interpolate(:default => '%{separator}', :foo => :bar) }
105
+ end
106
+
107
+ protected
108
+
109
+ def capture(stream)
110
+ begin
111
+ stream = stream.to_s
112
+ eval "$#{stream} = StringIO.new"
113
+ yield
114
+ result = eval("$#{stream}").string
115
+ ensure
116
+ eval("$#{stream} = #{stream.upcase}")
117
+ end
118
+
119
+ result
120
+ end
121
+
122
+ def euc_jp(string)
123
+ string.encode!(Encoding::EUC_JP)
124
+ end
125
+
126
+ def interpolate(*args)
127
+ options = args.last.is_a?(Hash) ? args.pop : {}
128
+ key = args.pop
129
+ I18n.backend.translate('en', key, options)
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,56 @@
1
+ # encoding: utf-8
2
+
3
+ module I18n
4
+ module Tests
5
+ module Link
6
+ 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
+ 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
+ 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
+ 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
+ test "linked lookup: links always refer to the absolute key" 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
+ 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
+ assert_equal "can't be blank", I18n.t(:"activerecord.errors.messages.blank")
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,19 @@
1
+ module I18n
2
+ module Tests
3
+ module Localization
4
+ autoload :Date, 'i18n/tests/localization/date'
5
+ autoload :DateTime, 'i18n/tests/localization/date_time'
6
+ autoload :Time, 'i18n/tests/localization/time'
7
+ autoload :Procs, 'i18n/tests/localization/procs'
8
+
9
+ def self.included(base)
10
+ base.class_eval do
11
+ include I18n::Tests::Localization::Date
12
+ include I18n::Tests::Localization::DateTime
13
+ include I18n::Tests::Localization::Procs
14
+ include I18n::Tests::Localization::Time
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,84 @@
1
+ # encoding: utf-8
2
+
3
+ module I18n
4
+ module Tests
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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ test "localize Date: given an unknown format it does not fail" do
44
+ assert_nothing_raised { I18n.l(@date, :format => '%x') }
45
+ end
46
+
47
+ test "localize Date: given nil it raises I18n::ArgumentError" do
48
+ assert_raise(I18n::ArgumentError) { I18n.l(nil) }
49
+ end
50
+
51
+ test "localize Date: given a plain Object it raises I18n::ArgumentError" do
52
+ assert_raise(I18n::ArgumentError) { I18n.l(Object.new) }
53
+ end
54
+
55
+ test "localize Date: given a format is missing it raises I18n::MissingTranslationData" do
56
+ assert_raise(I18n::MissingTranslationData) { I18n.l(@date, :format => :missing) }
57
+ end
58
+
59
+ test "localize Date: it does not alter the format string" do
60
+ assert_equal '01. Februar 2009', I18n.l(::Date.parse('2009-02-01'), :format => :long, :locale => :de)
61
+ assert_equal '01. Oktober 2009', I18n.l(::Date.parse('2009-10-01'), :format => :long, :locale => :de)
62
+ end
63
+
64
+ protected
65
+
66
+ def setup_date_translations
67
+ I18n.backend.store_translations :de, {
68
+ :date => {
69
+ :formats => {
70
+ :default => "%d.%m.%Y",
71
+ :short => "%d. %b",
72
+ :long => "%d. %B %Y",
73
+ },
74
+ :day_names => %w(Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag),
75
+ :abbr_day_names => %w(So Mo Di Mi Do Fr Sa),
76
+ :month_names => %w(Januar Februar März April Mai Juni Juli August September Oktober November Dezember).unshift(nil),
77
+ :abbr_month_names => %w(Jan Feb Mar Apr Mai Jun Jul Aug Sep Okt Nov Dez).unshift(nil)
78
+ }
79
+ }
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,77 @@
1
+ # encoding: utf-8
2
+
3
+ module I18n
4
+ module Tests
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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ test "localize DateTime: given an unknown format it does not fail" do
51
+ assert_nothing_raised { I18n.l(@datetime, :format => '%x') }
52
+ end
53
+
54
+ test "localize DateTime: given a format is missing it raises I18n::MissingTranslationData" do
55
+ assert_raise(I18n::MissingTranslationData) { I18n.l(@datetime, :format => :missing) }
56
+ end
57
+
58
+ protected
59
+
60
+ def setup_datetime_translations
61
+ # time translations might have been set up in Tests::Api::Localization::Time
62
+ I18n.backend.store_translations :de, {
63
+ :time => {
64
+ :formats => {
65
+ :default => "%a, %d. %b %Y %H:%M:%S %z",
66
+ :short => "%d. %b %H:%M",
67
+ :long => "%d. %B %Y %H:%M"
68
+ },
69
+ :am => 'am',
70
+ :pm => 'pm'
71
+ }
72
+ }
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,103 @@
1
+ # encoding: utf-8
2
+
3
+ module I18n
4
+ module Tests
5
+ module Localization
6
+ module Procs
7
+ 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
+ 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
+ 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
+ test "localize Date: given a format that resolves to a Proc it calls the Proc with the object" do
29
+ setup_time_proc_translations
30
+ date = ::Date.new(2008, 3, 1, 6)
31
+ assert_equal '[Sat, 01 Mar 2008, {}]', I18n.l(date, :format => :proc, :locale => :ru)
32
+ end
33
+
34
+ test "localize Date: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
35
+ setup_time_proc_translations
36
+ date = ::Date.new(2008, 3, 1, 6)
37
+ assert_equal '[Sat, 01 Mar 2008, {:foo=>"foo"}]', I18n.l(date, :format => :proc, :foo => 'foo', :locale => :ru)
38
+ end
39
+
40
+ test "localize DateTime: given a format that resolves to a Proc it calls the Proc with the object" do
41
+ setup_time_proc_translations
42
+ datetime = ::DateTime.new(2008, 3, 1, 6)
43
+ assert_equal '[Sat, 01 Mar 2008 06:00:00 +0000, {}]', I18n.l(datetime, :format => :proc, :locale => :ru)
44
+ end
45
+
46
+ test "localize DateTime: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
47
+ setup_time_proc_translations
48
+ datetime = ::DateTime.new(2008, 3, 1, 6)
49
+ assert_equal '[Sat, 01 Mar 2008 06:00:00 +0000, {:foo=>"foo"}]', I18n.l(datetime, :format => :proc, :foo => 'foo', :locale => :ru)
50
+ end
51
+
52
+ test "localize Time: given a format that resolves to a Proc it calls the Proc with the object" do
53
+ setup_time_proc_translations
54
+ time = ::Time.parse('2008-03-01 6:00 UTC')
55
+ assert_equal [time, {}].inspect, I18n.l(time, :format => :proc, :locale => :ru)
56
+ end
57
+
58
+ test "localize Time: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
59
+ setup_time_proc_translations
60
+ time = ::Time.parse('2008-03-01 6:00 UTC')
61
+ options = { :foo => 'foo' }
62
+ assert_equal [time, options].inspect, I18n.l(time, options.merge(:format => :proc, :locale => :ru))
63
+ end
64
+
65
+ protected
66
+
67
+ def filter_args(*args)
68
+ args.map {|arg| arg.delete(:fallback) if arg.is_a?(Hash) ; arg }.inspect
69
+ end
70
+
71
+ def setup_time_proc_translations
72
+ I18n.backend.store_translations :ru, {
73
+ :time => {
74
+ :formats => {
75
+ :proc => lambda { |*args| filter_args(*args) }
76
+ }
77
+ },
78
+ :date => {
79
+ :formats => {
80
+ :proc => lambda { |*args| filter_args(*args) }
81
+ },
82
+ :'day_names' => lambda { |key, options|
83
+ (options[:format] =~ /^%A/) ?
84
+ %w(Воскресенье Понедельник Вторник Среда Четверг Пятница Суббота) :
85
+ %w(воскресенье понедельник вторник среда четверг пятница суббота)
86
+ },
87
+ :'month_names' => lambda { |key, options|
88
+ (options[:format] =~ /(%d|%e)(\s*)?(%B)/) ?
89
+ %w(января февраля марта апреля мая июня июля августа сентября октября ноября декабря).unshift(nil) :
90
+ %w(Январь Февраль Март Апрель Май Июнь Июль Август Сентябрь Октябрь Ноябрь Декабрь).unshift(nil)
91
+ },
92
+ :'abbr_month_names' => lambda { |key, options|
93
+ (options[:format] =~ /(%d|%e)(\s*)(%b)/) ?
94
+ %w(янв. февр. марта апр. мая июня июля авг. сент. окт. нояб. дек.).unshift(nil) :
95
+ %w(янв. февр. март апр. май июнь июль авг. сент. окт. нояб. дек.).unshift(nil)
96
+ },
97
+ }
98
+ }
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end