7 test "localize: using day names from lambdas" do
8 setup_time_proc_translations
9 time = ::Time.utc(2008, 3, 1, 6, 0)
10 assert_match(/Суббота/, I18n.l(time, :format => "%A, %d %B", :locale => :ru))
11 assert_match(/суббота/, I18n.l(time, :format => "%d %B (%A)", :locale => :ru))
14 test "localize: using month names from lambdas" do
15 setup_time_proc_translations
16 time = ::Time.utc(2008, 3, 1, 6, 0)
17 assert_match(/марта/, I18n.l(time, :format => "%d %B %Y", :locale => :ru))
18 assert_match(/Март /, I18n.l(time, :format => "%B %Y", :locale => :ru))
21 test "localize: using abbreviated day names from lambdas" do
22 setup_time_proc_translations
23 time = ::Time.utc(2008, 3, 1, 6, 0)
24 assert_match(/марта/, I18n.l(time, :format => "%d %b %Y", :locale => :ru))
25 assert_match(/март /, I18n.l(time, :format => "%b %Y", :locale => :ru))
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)
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)
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 +00:00, {}]', I18n.l(datetime, :format => :proc, :locale => :ru)
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 +00:00, {:foo=>"foo"}]', I18n.l(datetime, :format => :proc, :foo => 'foo', :locale => :ru)
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.utc(2008, 3, 1, 6, 0)
55 assert_equal inspect_args([time, {}]), I18n.l(time, :format => :proc, :locale => :ru)
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.utc(2008, 3, 1, 6, 0)
61 options = { :foo => 'foo' }
62 assert_equal inspect_args([time, options]), I18n.l(time, options.merge(:format => :proc, :locale => :ru))
67 def inspect_args(args)
68 args = args.map do |arg|
70 when ::Time, ::DateTime
71 arg.strftime('%a, %d %b %Y %H:%M:%S %Z').sub('+0000', '+00:00')
73 arg.strftime('%a, %d %b %Y')
81 "[#{args.join(', ')}]"
84 def setup_time_proc_translations
85 I18n.backend.store_translations :ru, {
88 :proc => lambda { |*args| inspect_args(args) }
93 :proc => lambda { |*args| inspect_args(args) }
95 :'day_names' => lambda { |key, options|
96 (options[:format] =~ /^%A/) ?
97 %w(Воскресенье Понедельник Вторник Среда Четверг Пятница Суббота) :
98 %w(воскресенье понедельник вторник среда четверг пятница суббота)
100 :'month_names' => lambda { |key, options|
101 (options[:format] =~ /(%d|%e)(\s*)?(%B)/) ?
102 %w(января февраля марта апреля мая июня июля августа сентября октября ноября декабря).unshift(nil) :
103 %w(Январь Февраль Март Апрель Май Июнь Июль Август Сентябрь Октябрь Ноябрь Декабрь).unshift(nil)
105 :'abbr_month_names' => lambda { |key, options|
106 (options[:format] =~ /(%d|%e)(\s*)(%b)/) ?
107 %w(янв. февр. марта апр. мая июня июля авг. сент. окт. нояб. дек.).unshift(nil) :
108 %w(янв. февр. март апр. май июнь июль авг. сент. окт. нояб. дек.).unshift(nil)