i18n 0.3.0 → 0.3.1
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.
- data/CHANGELOG.textile +19 -0
- data/README.textile +41 -15
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/i18n.rb +1 -1
- data/lib/i18n/backend/active_record.rb +6 -5
- data/lib/i18n/backend/active_record/missing.rb +64 -0
- data/lib/i18n/backend/active_record/translation.rb +2 -2
- data/lib/i18n/backend/base.rb +2 -2
- data/lib/i18n/backend/chain.rb +3 -3
- data/lib/i18n/helpers/gettext.rb +1 -1
- data/test/all.rb +4 -4
- data/test/api/basics.rb +8 -8
- data/test/api/defaults.rb +40 -0
- data/test/api/interpolation.rb +65 -67
- data/test/api/link.rb +31 -38
- data/test/api/localization/date.rb +69 -50
- data/test/api/localization/date_time.rb +66 -42
- data/test/api/localization/procs.rb +54 -0
- data/test/api/localization/time.rb +71 -52
- data/test/api/lookup.rb +38 -0
- data/test/api/pluralization.rb +22 -24
- data/test/api/procs.rb +40 -0
- data/test/cases/api/active_record_test.rb +28 -0
- data/test/cases/api/all_features_test.rb +37 -0
- data/test/cases/api/chain_test.rb +26 -0
- data/test/cases/api/fallbacks_test.rb +33 -0
- data/test/cases/api/pluralization_test.rb +33 -0
- data/test/cases/api/simple_test.rb +21 -0
- data/test/{backend/active_record_missing/active_record_missing_test.rb → cases/backend/active_record/missing_test.rb} +5 -8
- data/test/{backend/active_record → cases/backend}/active_record_test.rb +13 -3
- data/test/{backend/cache → cases/backend}/cache_test.rb +7 -7
- data/test/{backend/chain → cases/backend}/chain_test.rb +1 -1
- data/test/{backend/fallbacks → cases/backend}/fallbacks_test.rb +5 -5
- data/test/{backend/simple → cases/backend}/helpers_test.rb +1 -1
- data/test/{backend/metadata → cases/backend}/metadata_test.rb +12 -10
- data/test/{backend/pluralization → cases/backend}/pluralization_test.rb +10 -10
- data/test/cases/backend/simple_test.rb +77 -0
- data/test/{core_ext → cases/core_ext}/string/interpolate_test.rb +15 -15
- data/test/{gettext → cases/gettext}/api_test.rb +1 -4
- data/test/{gettext → cases/gettext}/backend_test.rb +9 -2
- data/test/{i18n_exceptions_test.rb → cases/i18n_exceptions_test.rb} +1 -1
- data/test/{i18n_load_path_test.rb → cases/i18n_load_path_test.rb} +2 -2
- data/test/{i18n_test.rb → cases/i18n_test.rb} +1 -1
- data/test/{locale → cases/locale}/fallbacks_test.rb +1 -3
- data/test/{locale → cases/locale}/tag/rfc4646_test.rb +1 -3
- data/test/{locale → cases/locale}/tag/simple_test.rb +1 -3
- data/test/fixtures/locales/de.po +5 -0
- data/test/test_helper.rb +45 -30
- data/vendor/po_parser.rb +329 -0
- metadata +60 -69
- data/lib/i18n/backend/active_record_missing.rb +0 -55
- data/test/api/lambda.rb +0 -52
- data/test/api/localization/lambda.rb +0 -26
- data/test/api/translation.rb +0 -51
- data/test/backend/active_record/all.rb +0 -3
- data/test/backend/active_record/api_test.rb +0 -54
- data/test/backend/active_record/setup.rb +0 -166
- data/test/backend/all/api_test.rb +0 -88
- data/test/backend/chain/api_test.rb +0 -80
- data/test/backend/fallbacks/api_test.rb +0 -84
- data/test/backend/pluralization/api_test.rb +0 -86
- data/test/backend/simple/all.rb +0 -5
- data/test/backend/simple/api_test.rb +0 -92
- data/test/backend/simple/lookup_test.rb +0 -24
- data/test/backend/simple/setup.rb +0 -147
- data/test/backend/simple/translations_test.rb +0 -83
- data/test/with_options.rb +0 -34
data/test/api/link.rb
CHANGED
@@ -1,47 +1,40 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module Tests
|
4
|
-
module
|
5
|
-
module
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_translate_calls_translate_if_resolves_to_a_symbol2
|
13
|
-
setup_linked_translations
|
14
|
-
assert_equal('baz', I18n.backend.translate('en', :link_to_baz))
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_translate_calls_translate_if_resolves_to_a_symbol3
|
18
|
-
setup_linked_translations
|
19
|
-
assert I18n.backend.translate('en', :link_to_bar).key?(:baz)
|
20
|
-
end
|
4
|
+
module Api
|
5
|
+
module Link
|
6
|
+
define_method "test linked lookup: given the key resolves to a symbol it looks up the symbol" do
|
7
|
+
setup_linked_translations
|
8
|
+
assert_equal 'foo', I18n.backend.translate('en', :link_to_foo)
|
9
|
+
end
|
21
10
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
11
|
+
define_method "test linked lookup: given the key resolves to a dot-separated symbol it looks up the dot-separated symbol (1)" do
|
12
|
+
setup_linked_translations
|
13
|
+
assert_equal('baz', I18n.backend.translate('en', :link_to_baz))
|
14
|
+
end
|
15
|
+
|
16
|
+
define_method "test linked lookup: given the key resolves to a dot-separated symbol it looks up the dot-separated symbol (2)" do
|
17
|
+
setup_linked_translations
|
18
|
+
assert_equal('buz', I18n.backend.translate('en', :'bar.link_to_buz'))
|
19
|
+
end
|
20
|
+
|
21
|
+
define_method "test linked lookup: given a scope and the key resolves to a symbol it looks up the symbol within the scope" do
|
22
|
+
setup_linked_translations
|
23
|
+
assert_equal('baz', I18n.backend.translate('en', :link_to_baz, :scope => :bar))
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
26
27
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
28
|
+
def setup_linked_translations
|
29
|
+
I18n.backend.store_translations 'en', {
|
30
|
+
:foo => 'foo',
|
31
|
+
:bar => { :baz => 'baz', :link_to_baz => :baz, :link_to_buz => :'boz.buz' },
|
32
|
+
:boz => { :buz => 'buz' },
|
33
|
+
:link_to_foo => :foo,
|
34
|
+
:link_to_bar => :bar,
|
35
|
+
:link_to_baz => :'bar.baz'
|
36
|
+
}
|
30
37
|
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def setup_linked_translations
|
35
|
-
I18n.backend.store_translations 'en', {
|
36
|
-
:foo => 'foo',
|
37
|
-
:bar => { :baz => 'baz', :link_to_baz => :baz, :link_to_buz => :'boz.buz' },
|
38
|
-
:boz => { :buz => 'buz' },
|
39
|
-
:link_to_foo => :foo,
|
40
|
-
:link_to_bar => :bar,
|
41
|
-
:link_to_baz => :'bar.baz'
|
42
|
-
}
|
43
|
-
end
|
44
|
-
end
|
45
38
|
end
|
46
39
|
end
|
47
40
|
end
|
@@ -1,71 +1,90 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module Tests
|
4
|
-
module
|
5
|
-
module
|
6
|
-
module
|
7
|
-
|
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
|
8
14
|
# TODO should be Mrz, shouldn't it?
|
9
|
-
|
10
|
-
|
11
|
-
end
|
15
|
+
assert_equal '01. Mar', I18n.l(@date, :format => :short, :locale => :de)
|
16
|
+
end
|
12
17
|
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
16
21
|
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
20
25
|
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
24
29
|
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
28
33
|
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
32
37
|
|
38
|
+
define_method "test localize Date: given an abbreviated month name format it returns the correct abbreviated month name" do
|
33
39
|
# TODO should be Mrz, shouldn't it?
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_localize_given_a_format_specified_as_a_proc
|
39
|
-
assert_equal '1ter März 2008', I18n.backend.localize('de', date, :long_ordinalized)
|
40
|
-
end
|
40
|
+
assert_equal 'Mar', I18n.l(@date, :format => '%b', :locale => :de)
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
assert_equal '01. Oktober 2009', first_of_oct
|
51
|
-
end
|
48
|
+
# TODO fails, but 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
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
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
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
define_method "test localize Date: given nil it raises I18n::ArgumentError" do
|
58
|
+
assert_raises(I18n::ArgumentError) { I18n.l(nil) }
|
59
|
+
end
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
64
69
|
|
65
|
-
|
66
|
-
|
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
|
+
}
|
67
87
|
end
|
68
|
-
end
|
69
88
|
end
|
70
89
|
end
|
71
90
|
end
|
@@ -1,62 +1,86 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module Tests
|
4
|
-
module
|
5
|
-
module
|
6
|
-
module
|
7
|
-
|
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
|
8
15
|
# TODO should be Mrz, shouldn't it?
|
9
|
-
|
10
|
-
|
11
|
-
end
|
16
|
+
assert_equal '01. Mar 06:00', I18n.l(@datetime, :format => :short, :locale => :de)
|
17
|
+
end
|
12
18
|
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
16
22
|
|
23
|
+
define_method "test localize DateTime: given the default format it uses it" do
|
17
24
|
# TODO should be Mrz, shouldn't it?
|
18
|
-
|
19
|
-
|
20
|
-
end
|
25
|
+
assert_equal 'Sa, 01. Mar 2008 06:00:00 +0000', I18n.l(@datetime, :format => :default, :locale => :de)
|
26
|
+
end
|
21
27
|
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
25
31
|
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
29
35
|
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
33
39
|
|
40
|
+
define_method "test localize DateTime: given an abbreviated month name format it returns the correct abbreviated month name" do
|
34
41
|
# TODO should be Mrz, shouldn't it?
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_localize_given_a_meridian_indicator_format_it_returns_the_correct_meridian_indicator
|
40
|
-
assert_equal 'am', I18n.backend.localize('de', morning_datetime, '%p')
|
41
|
-
assert_equal 'pm', I18n.backend.localize('de', evening_datetime, '%p')
|
42
|
-
end
|
42
|
+
assert_equal 'Mar', I18n.l(@datetime, :format => '%b', :locale => :de)
|
43
|
+
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
47
49
|
|
48
|
-
|
49
|
-
|
50
|
-
|
50
|
+
define_method "test localize Date: given a format that resolves to a Proc it calls the Proc with the object" do
|
51
|
+
assert_equal '[Sat Mar 01 06:00:00 UTC 2008, {}]', I18n.l(@time, :format => :proc, :locale => :de)
|
52
|
+
end
|
51
53
|
|
52
|
-
|
53
|
-
|
54
|
-
|
54
|
+
# define_method "test localize DateTime: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
|
55
|
+
# assert_equal '1ter März 2008, 06:00 Uhr', I18n.l(@datetime, :long_ordinalized)
|
56
|
+
# end
|
55
57
|
|
56
|
-
|
57
|
-
|
58
|
-
end
|
58
|
+
define_method "test localize DateTime: given an unknown format it does not fail" do
|
59
|
+
assert_nothing_raised { I18n.l(@datetime, :format => '%x') }
|
59
60
|
end
|
61
|
+
|
62
|
+
protected
|
63
|
+
|
64
|
+
def setup_datetime_translations
|
65
|
+
# time translations might have been set up in Tests::Api::Localization::Time
|
66
|
+
I18n.t(:'time.formats.default', :locale => :de, :raise => true)
|
67
|
+
rescue
|
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
|
+
:long_ordinalized => lambda { |date, options|
|
75
|
+
tz = " (#{options[:timezone]})" if options[:timezone]
|
76
|
+
"#{date.day}ter %B %Y, %H:%M Uhr#{tz}"
|
77
|
+
}
|
78
|
+
},
|
79
|
+
:am => 'am',
|
80
|
+
:pm => 'pm'
|
81
|
+
}
|
82
|
+
}
|
83
|
+
end
|
60
84
|
end
|
61
85
|
end
|
62
86
|
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
|
@@ -1,62 +1,81 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module Tests
|
4
|
-
module
|
5
|
-
module
|
6
|
-
module
|
7
|
-
|
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
|
8
15
|
# TODO should be Mrz, shouldn't it?
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
34
41
|
# TODO should be Mrz, shouldn't it?
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_localize_given_a_format_specified_as_a_proc
|
45
|
-
assert_equal '1ter März 2008, 06:00 Uhr', I18n.backend.localize('de', morning_time, :long_ordinalized)
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_localize_given_a_format_specified_as_a_proc_with_additional_options
|
49
|
-
assert_equal '1ter März 2008, 06:00 Uhr (MEZ)', I18n.backend.localize('de', morning_time, :long_ordinalized, :timezone => 'MEZ')
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_localize_given_no_format_it_does_not_fail
|
53
|
-
assert_nothing_raised{ I18n.backend.localize 'de', morning_time }
|
54
|
-
end
|
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
|
55
49
|
|
56
|
-
|
57
|
-
|
58
|
-
|
50
|
+
define_method "test localize Time: given a format that resolves to a Proc it calls the Proc with the object" do
|
51
|
+
assert_equal '[Sat Mar 01 06:00:00 UTC 2008, {}]', I18n.l(@time, :format => :proc, :locale => :de)
|
52
|
+
end
|
53
|
+
|
54
|
+
# TODO fails, but probably should pass
|
55
|
+
# define_method "test localize Time: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
|
56
|
+
# assert_equal '[Sat Mar 01 06:00:00 UTC 2008, {:foo=>"foo"}]', I18n.l(@time, :format => :proc, :foo => 'foo', :locale => :de)
|
57
|
+
# end
|
58
|
+
|
59
|
+
define_method "test localize Time: given an unknown format it does not fail" do
|
60
|
+
assert_nothing_raised { I18n.l(@time, :format => '%x') }
|
59
61
|
end
|
62
|
+
|
63
|
+
protected
|
64
|
+
|
65
|
+
def setup_time_translations
|
66
|
+
store_translations :de, {
|
67
|
+
:time => {
|
68
|
+
:formats => {
|
69
|
+
:default => "%a, %d. %b %Y %H:%M:%S %z",
|
70
|
+
:short => "%d. %b %H:%M",
|
71
|
+
:long => "%d. %B %Y %H:%M",
|
72
|
+
:proc => lambda { |*args| args.inspect }
|
73
|
+
},
|
74
|
+
:am => 'am',
|
75
|
+
:pm => 'pm'
|
76
|
+
}
|
77
|
+
}
|
78
|
+
end
|
60
79
|
end
|
61
80
|
end
|
62
81
|
end
|