i18n 0.2.0 → 0.2.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/test/api/lambda.rb CHANGED
@@ -1,50 +1,50 @@
1
- module Tests
2
- module Backend
3
- module Api
4
- module Lambda
5
- def test_translate_simple_proc
6
- setup_proc_translations
7
- assert_equal 'bar=bar, baz=baz, foo=foo', I18n.backend.translate('en', :a_lambda, :foo => 'foo', :bar => 'bar', :baz => 'baz')
8
- end
9
-
10
- def test_translate_proc_in_defaults
11
- setup_proc_translations
12
- assert_equal 'bar=bar, baz=baz, foo=foo', I18n.backend.translate('en', :does_not_exist, :default => :a_lambda, :foo => 'foo', :bar => 'bar', :baz => 'baz')
13
- assert_equal 'bar=bar, baz=baz, foo=foo', I18n.backend.translate('en', :does_not_exist, :default => [:does_not_exist_2, :does_not_exist_3, :a_lambda], :foo => 'foo', :bar => 'bar', :baz => 'baz')
14
- end
15
-
16
- def test_translate_proc_with_pluralize
17
- setup_proc_translations
18
- params = { :zero => 'zero', :one => 'one', :other => 'other' }
19
- assert_equal 'zero', I18n.backend.translate('en', :lambda_for_pluralize, params.merge(:count => 0))
20
- assert_equal 'one', I18n.backend.translate('en', :lambda_for_pluralize, params.merge(:count => 1))
21
- assert_equal 'other', I18n.backend.translate('en', :lambda_for_pluralize, params.merge(:count => 2))
22
- end
23
-
24
- def test_translate_proc_with_interpolate
25
- setup_proc_translations
26
- assert_equal 'bar baz foo', I18n.backend.translate('en', :lambda_for_interpolate, :foo => 'foo', :bar => 'bar', :baz => 'baz')
27
- end
28
-
29
- def test_translate_with_proc_as_default
30
- expected = 'result from lambda'
31
- assert_equal expected, I18n.backend.translate(:en, :'does not exist', :default => lambda { |key, values| expected })
32
- end
33
-
34
- private
35
-
36
- def setup_proc_translations
37
- I18n.backend.store_translations 'en', {
38
- :a_lambda => lambda { |key, values|
39
- values.keys.sort_by(&:to_s).collect { |key| "#{key}=#{values[key]}"}.join(', ')
40
- },
41
- :lambda_for_pluralize => lambda { |key, values| values },
42
- :lambda_for_interpolate => lambda { |key, values|
43
- "{{#{values.keys.sort_by(&:to_s).join('}} {{')}}}"
44
- }
45
- }
46
- end
47
- end
48
- end
49
- end
1
+ module Tests
2
+ module Backend
3
+ module Api
4
+ module Lambda
5
+ def test_translate_simple_proc
6
+ setup_proc_translations
7
+ assert_equal 'bar=bar, baz=baz, foo=foo', I18n.backend.translate('en', :a_lambda, :foo => 'foo', :bar => 'bar', :baz => 'baz')
8
+ end
9
+
10
+ def test_translate_proc_in_defaults
11
+ setup_proc_translations
12
+ assert_equal 'bar=bar, baz=baz, foo=foo', I18n.backend.translate('en', :does_not_exist, :default => :a_lambda, :foo => 'foo', :bar => 'bar', :baz => 'baz')
13
+ assert_equal 'bar=bar, baz=baz, foo=foo', I18n.backend.translate('en', :does_not_exist, :default => [:does_not_exist_2, :does_not_exist_3, :a_lambda], :foo => 'foo', :bar => 'bar', :baz => 'baz')
14
+ end
15
+
16
+ def test_translate_proc_with_pluralize
17
+ setup_proc_translations
18
+ params = { :zero => 'zero', :one => 'one', :other => 'other' }
19
+ assert_equal 'zero', I18n.backend.translate('en', :lambda_for_pluralize, params.merge(:count => 0))
20
+ assert_equal 'one', I18n.backend.translate('en', :lambda_for_pluralize, params.merge(:count => 1))
21
+ assert_equal 'other', I18n.backend.translate('en', :lambda_for_pluralize, params.merge(:count => 2))
22
+ end
23
+
24
+ def test_translate_proc_with_interpolate
25
+ setup_proc_translations
26
+ assert_equal 'bar baz foo', I18n.backend.translate('en', :lambda_for_interpolate, :foo => 'foo', :bar => 'bar', :baz => 'baz')
27
+ end
28
+
29
+ def test_translate_with_proc_as_default
30
+ expected = 'result from lambda'
31
+ assert_equal expected, I18n.backend.translate(:en, :'does not exist', :default => lambda { |key, values| expected })
32
+ end
33
+
34
+ private
35
+
36
+ def setup_proc_translations
37
+ I18n.backend.store_translations 'en', {
38
+ :a_lambda => lambda { |key, values|
39
+ values.keys.sort_by(&:to_s).collect { |key| "#{key}=#{values[key]}"}.join(', ')
40
+ },
41
+ :lambda_for_pluralize => lambda { |key, values| values },
42
+ :lambda_for_interpolate => lambda { |key, values|
43
+ "{{#{values.keys.sort_by(&:to_s).join('}} {{')}}}"
44
+ }
45
+ }
46
+ end
47
+ end
48
+ end
49
+ end
50
50
  end
data/test/api/link.rb CHANGED
@@ -1,45 +1,45 @@
1
- module Tests
2
- module Backend
3
- module Api
4
- module Link
5
- def test_translate_calls_translate_if_resolves_to_a_symbol
6
- setup_linked_translations
7
- assert_equal 'foo', I18n.backend.translate('en', :link_to_foo)
8
- end
9
-
10
- def test_translate_calls_translate_if_resolves_to_a_symbol2
11
- setup_linked_translations
12
- assert_equal('baz', I18n.backend.translate('en', :link_to_baz))
13
- end
14
-
15
- def test_translate_calls_translate_if_resolves_to_a_symbol3
16
- setup_linked_translations
17
- assert I18n.backend.translate('en', :link_to_bar).key?(:baz)
18
- end
19
-
20
- def test_translate_calls_translate_if_resolves_to_a_symbol_with_scope_1
21
- setup_linked_translations
22
- assert_equal('baz', I18n.backend.translate('en', :link_to_baz, :scope => :bar))
23
- end
24
-
25
- def test_translate_calls_translate_if_resolves_to_a_symbol_with_scope_1
26
- setup_linked_translations
27
- assert_equal('buz', I18n.backend.translate('en', :'bar.link_to_buz'))
28
- end
29
-
30
- private
31
-
32
- def setup_linked_translations
33
- I18n.backend.store_translations 'en', {
34
- :foo => 'foo',
35
- :bar => { :baz => 'baz', :link_to_baz => :baz, :link_to_buz => :'boz.buz' },
36
- :boz => { :buz => 'buz' },
37
- :link_to_foo => :foo,
38
- :link_to_bar => :bar,
39
- :link_to_baz => :'bar.baz'
40
- }
41
- end
42
- end
43
- end
44
- end
1
+ module Tests
2
+ module Backend
3
+ module Api
4
+ module Link
5
+ def test_translate_calls_translate_if_resolves_to_a_symbol
6
+ setup_linked_translations
7
+ assert_equal 'foo', I18n.backend.translate('en', :link_to_foo)
8
+ end
9
+
10
+ def test_translate_calls_translate_if_resolves_to_a_symbol2
11
+ setup_linked_translations
12
+ assert_equal('baz', I18n.backend.translate('en', :link_to_baz))
13
+ end
14
+
15
+ def test_translate_calls_translate_if_resolves_to_a_symbol3
16
+ setup_linked_translations
17
+ assert I18n.backend.translate('en', :link_to_bar).key?(:baz)
18
+ end
19
+
20
+ def test_translate_calls_translate_if_resolves_to_a_symbol_with_scope_1
21
+ setup_linked_translations
22
+ assert_equal('baz', I18n.backend.translate('en', :link_to_baz, :scope => :bar))
23
+ end
24
+
25
+ def test_translate_calls_translate_if_resolves_to_a_symbol_with_scope_1
26
+ setup_linked_translations
27
+ assert_equal('buz', I18n.backend.translate('en', :'bar.link_to_buz'))
28
+ end
29
+
30
+ private
31
+
32
+ def setup_linked_translations
33
+ I18n.backend.store_translations 'en', {
34
+ :foo => 'foo',
35
+ :bar => { :baz => 'baz', :link_to_baz => :baz, :link_to_buz => :'boz.buz' },
36
+ :boz => { :buz => 'buz' },
37
+ :link_to_foo => :foo,
38
+ :link_to_bar => :bar,
39
+ :link_to_baz => :'bar.baz'
40
+ }
41
+ end
42
+ end
43
+ end
44
+ end
45
45
  end
@@ -1,63 +1,70 @@
1
- module Tests
2
- module Backend
3
- module Api
4
- module Localization
5
- module Date
6
- # TODO should be Mrz, shouldn't it?
7
- def test_localize_given_the_short_format_it_uses_it
8
- assert_equal '01. Mar', I18n.backend.localize('de', date, :short)
9
- end
10
-
11
- def test_localize_given_the_long_format_it_uses_it
12
- assert_equal '01. März 2008', I18n.backend.localize('de', date, :long)
13
- end
14
-
15
- def test_localize_given_the_default_format_it_uses_it
16
- assert_equal '01.03.2008', I18n.backend.localize('de', date, :default)
17
- end
18
-
19
- def test_localize_given_a_day_name_format_it_returns_a_day_name
20
- assert_equal 'Samstag', I18n.backend.localize('de', date, '%A')
21
- end
22
-
23
- def test_localize_given_an_abbr_day_name_format_it_returns_an_abbrevated_day_name
24
- assert_equal 'Sa', I18n.backend.localize('de', date, '%a')
25
- end
26
-
27
- def test_localize_given_a_month_name_format_it_returns_a_month_name
28
- assert_equal 'März', I18n.backend.localize('de', date, '%B')
29
- end
30
-
31
- # TODO should be Mrz, shouldn't it?
32
- def test_localize_given_an_abbr_month_name_format_it_returns_an_abbrevated_month_name
33
- assert_equal 'Mar', I18n.backend.localize('de', date, '%b')
34
- end
35
-
36
- def test_localize_given_a_format_specified_as_a_proc
37
- assert_equal '1ter März 2008', I18n.backend.localize('de', date, :long_ordinalized)
38
- end
39
-
40
- def test_localize_given_a_format_specified_as_a_proc_with_additional_options
41
- assert_equal '1ter März 2008 (MEZ)', I18n.backend.localize('de', date, :long_ordinalized, :timezone => 'MEZ')
42
- end
43
-
44
- def test_localize_given_no_format_it_does_not_fail
45
- assert_nothing_raised{ I18n.backend.localize 'de', date }
46
- end
47
-
48
- def test_localize_given_an_unknown_format_it_does_not_fail
49
- assert_nothing_raised{ I18n.backend.localize 'de', date, '%x' }
50
- end
51
-
52
- def test_localize_nil_raises_argument_error
53
- assert_raises(I18n::ArgumentError) { I18n.backend.localize 'de', nil }
54
- end
55
-
56
- def test_localize_object_raises_argument_error
57
- assert_raises(I18n::ArgumentError) { I18n.backend.localize 'de', Object.new }
58
- end
59
- end
60
- end
61
- end
62
- end
63
- end
1
+ module Tests
2
+ module Backend
3
+ module Api
4
+ module Localization
5
+ module Date
6
+ # TODO should be Mrz, shouldn't it?
7
+ def test_localize_given_the_short_format_it_uses_it
8
+ assert_equal '01. Mar', I18n.backend.localize('de', date, :short)
9
+ end
10
+
11
+ def test_localize_given_the_long_format_it_uses_it
12
+ assert_equal '01. März 2008', I18n.backend.localize('de', date, :long)
13
+ end
14
+
15
+ def test_localize_given_the_default_format_it_uses_it
16
+ assert_equal '01.03.2008', I18n.backend.localize('de', date, :default)
17
+ end
18
+
19
+ def test_localize_given_a_day_name_format_it_returns_a_day_name
20
+ assert_equal 'Samstag', I18n.backend.localize('de', date, '%A')
21
+ end
22
+
23
+ def test_localize_given_an_abbr_day_name_format_it_returns_an_abbrevated_day_name
24
+ assert_equal 'Sa', I18n.backend.localize('de', date, '%a')
25
+ end
26
+
27
+ def test_localize_given_a_month_name_format_it_returns_a_month_name
28
+ assert_equal 'März', I18n.backend.localize('de', date, '%B')
29
+ end
30
+
31
+ # TODO should be Mrz, shouldn't it?
32
+ def test_localize_given_an_abbr_month_name_format_it_returns_an_abbrevated_month_name
33
+ assert_equal 'Mar', I18n.backend.localize('de', date, '%b')
34
+ end
35
+
36
+ def test_localize_given_a_format_specified_as_a_proc
37
+ assert_equal '1ter März 2008', I18n.backend.localize('de', date, :long_ordinalized)
38
+ end
39
+
40
+ def test_localize_given_a_format_specified_as_a_proc_with_additional_options
41
+ assert_equal '1ter März 2008 (MEZ)', I18n.backend.localize('de', date, :long_ordinalized, :timezone => 'MEZ')
42
+ end
43
+
44
+ def test_localize_does_not_alter_the_stored_format_string
45
+ first_of_jan = I18n.backend.localize(:de, ::Date.parse('2009-01-01'), :long)
46
+ first_of_oct = I18n.backend.localize(:de, ::Date.parse('2009-10-01'), :long)
47
+ assert_equal '01. Januar 2009', first_of_jan
48
+ assert_equal '01. Oktober 2009', first_of_oct
49
+ end
50
+
51
+ def test_localize_given_no_format_it_does_not_fail
52
+ assert_nothing_raised{ I18n.backend.localize 'de', date }
53
+ end
54
+
55
+ def test_localize_given_an_unknown_format_it_does_not_fail
56
+ assert_nothing_raised{ I18n.backend.localize 'de', date, '%x' }
57
+ end
58
+
59
+ def test_localize_nil_raises_argument_error
60
+ assert_raises(I18n::ArgumentError) { I18n.backend.localize 'de', nil }
61
+ end
62
+
63
+ def test_localize_object_raises_argument_error
64
+ assert_raises(I18n::ArgumentError) { I18n.backend.localize 'de', Object.new }
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -1,61 +1,61 @@
1
- module Tests
2
- module Backend
3
- module Api
4
- module Localization
5
- module DateTime
6
- # TODO should be Mrz, shouldn't it?
7
- def test_localize_given_the_short_format_it_uses_it
8
- assert_equal '01. Mar 06:00', I18n.backend.localize('de', morning_datetime, :short)
9
- end
10
-
11
- def test_localize_given_the_long_format_it_uses_it
12
- assert_equal '01. März 2008 06:00', I18n.backend.localize('de', morning_datetime, :long)
13
- end
14
-
15
- # TODO should be Mrz, shouldn't it?
16
- def test_localize_given_the_default_format_it_uses_it
17
- assert_equal 'Sa, 01. Mar 2008 06:00:00 +0000', I18n.backend.localize('de', morning_datetime, :default)
18
- end
19
-
20
- def test_localize_given_a_day_name_format_it_returns_the_correct_day_name
21
- assert_equal 'Samstag', I18n.backend.localize('de', morning_datetime, '%A')
22
- end
23
-
24
- def test_localize_given_an_abbr_day_name_format_it_returns_the_correct_abbrevated_day_name
25
- assert_equal 'Sa', I18n.backend.localize('de', morning_datetime, '%a')
26
- end
27
-
28
- def test_localize_given_a_month_name_format_it_returns_the_correct_month_name
29
- assert_equal 'März', I18n.backend.localize('de', morning_datetime, '%B')
30
- end
31
-
32
- # TODO should be Mrz, shouldn't it?
33
- def test_localize_given_an_abbr_month_name_format_it_returns_the_correct_abbrevated_month_name
34
- assert_equal 'Mar', I18n.backend.localize('de', morning_datetime, '%b')
35
- end
36
-
37
- def test_localize_given_a_meridian_indicator_format_it_returns_the_correct_meridian_indicator
38
- assert_equal 'am', I18n.backend.localize('de', morning_datetime, '%p')
39
- assert_equal 'pm', I18n.backend.localize('de', evening_datetime, '%p')
40
- end
41
-
42
- def test_localize_given_a_format_specified_as_a_proc
43
- assert_equal '1ter März 2008, 06:00 Uhr', I18n.backend.localize('de', morning_datetime, :long_ordinalized)
44
- end
45
-
46
- def test_localize_given_a_format_specified_as_a_proc_with_additional_options
47
- assert_equal '1ter März 2008, 06:00 Uhr (MEZ)', I18n.backend.localize('de', morning_datetime, :long_ordinalized, :timezone => 'MEZ')
48
- end
49
-
50
- def test_localize_given_no_format_it_does_not_fail
51
- assert_nothing_raised{ I18n.backend.localize 'de', morning_datetime }
52
- end
53
-
54
- def test_localize_given_an_unknown_format_it_does_not_fail
55
- assert_nothing_raised{ I18n.backend.localize 'de', morning_datetime, '%x' }
56
- end
57
- end
58
- end
59
- end
60
- end
1
+ module Tests
2
+ module Backend
3
+ module Api
4
+ module Localization
5
+ module DateTime
6
+ # TODO should be Mrz, shouldn't it?
7
+ def test_localize_given_the_short_format_it_uses_it
8
+ assert_equal '01. Mar 06:00', I18n.backend.localize('de', morning_datetime, :short)
9
+ end
10
+
11
+ def test_localize_given_the_long_format_it_uses_it
12
+ assert_equal '01. März 2008 06:00', I18n.backend.localize('de', morning_datetime, :long)
13
+ end
14
+
15
+ # TODO should be Mrz, shouldn't it?
16
+ def test_localize_given_the_default_format_it_uses_it
17
+ assert_equal 'Sa, 01. Mar 2008 06:00:00 +0000', I18n.backend.localize('de', morning_datetime, :default)
18
+ end
19
+
20
+ def test_localize_given_a_day_name_format_it_returns_the_correct_day_name
21
+ assert_equal 'Samstag', I18n.backend.localize('de', morning_datetime, '%A')
22
+ end
23
+
24
+ def test_localize_given_an_abbr_day_name_format_it_returns_the_correct_abbrevated_day_name
25
+ assert_equal 'Sa', I18n.backend.localize('de', morning_datetime, '%a')
26
+ end
27
+
28
+ def test_localize_given_a_month_name_format_it_returns_the_correct_month_name
29
+ assert_equal 'März', I18n.backend.localize('de', morning_datetime, '%B')
30
+ end
31
+
32
+ # TODO should be Mrz, shouldn't it?
33
+ def test_localize_given_an_abbr_month_name_format_it_returns_the_correct_abbrevated_month_name
34
+ assert_equal 'Mar', I18n.backend.localize('de', morning_datetime, '%b')
35
+ end
36
+
37
+ def test_localize_given_a_meridian_indicator_format_it_returns_the_correct_meridian_indicator
38
+ assert_equal 'am', I18n.backend.localize('de', morning_datetime, '%p')
39
+ assert_equal 'pm', I18n.backend.localize('de', evening_datetime, '%p')
40
+ end
41
+
42
+ def test_localize_given_a_format_specified_as_a_proc
43
+ assert_equal '1ter März 2008, 06:00 Uhr', I18n.backend.localize('de', morning_datetime, :long_ordinalized)
44
+ end
45
+
46
+ def test_localize_given_a_format_specified_as_a_proc_with_additional_options
47
+ assert_equal '1ter März 2008, 06:00 Uhr (MEZ)', I18n.backend.localize('de', morning_datetime, :long_ordinalized, :timezone => 'MEZ')
48
+ end
49
+
50
+ def test_localize_given_no_format_it_does_not_fail
51
+ assert_nothing_raised{ I18n.backend.localize 'de', morning_datetime }
52
+ end
53
+
54
+ def test_localize_given_an_unknown_format_it_does_not_fail
55
+ assert_nothing_raised{ I18n.backend.localize 'de', morning_datetime, '%x' }
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
61
  end
@@ -1,24 +1,24 @@
1
- module Tests
2
- module Backend
3
- module Api
4
- module Localization
5
- module Lambda
6
- def test_localize_uses_lambda_day_names
7
- assert_match /Суббота/, I18n.backend.localize('ru', time, "%A, %d %B")
8
- assert_match /суббота/, I18n.backend.localize('ru', time, "%d %B (%A)")
9
- end
10
-
11
- def test_localize_uses_lambda_month_names
12
- assert_match /марта/, I18n.backend.localize('ru', time, "%d %B %Y")
13
- assert_match /Март/, I18n.backend.localize('ru', time, "%B %Y")
14
- end
15
-
16
- def test_localize_uses_lambda_abbr_day_names
17
- assert_match /марта/, I18n.backend.localize('ru', time, "%d %b %Y")
18
- assert_match /март/, I18n.backend.localize('ru', time, "%b %Y")
19
- end
20
- end
21
- end
22
- end
23
- end
1
+ module Tests
2
+ module Backend
3
+ module Api
4
+ module Localization
5
+ module Lambda
6
+ def test_localize_uses_lambda_day_names
7
+ assert_match /Суббота/, I18n.backend.localize('ru', time, "%A, %d %B")
8
+ assert_match /суббота/, I18n.backend.localize('ru', time, "%d %B (%A)")
9
+ end
10
+
11
+ def test_localize_uses_lambda_month_names
12
+ assert_match /марта/, I18n.backend.localize('ru', time, "%d %B %Y")
13
+ assert_match /Март/, I18n.backend.localize('ru', time, "%B %Y")
14
+ end
15
+
16
+ def test_localize_uses_lambda_abbr_day_names
17
+ assert_match /марта/, I18n.backend.localize('ru', time, "%d %b %Y")
18
+ assert_match /март/, I18n.backend.localize('ru', time, "%b %Y")
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
24
  end