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.

@@ -1,3 +1,3 @@
1
- en:
2
- foo:
1
+ en:
2
+ foo:
3
3
  bar: baz
@@ -1,95 +1,95 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
-
3
- class I18nExceptionsTest < Test::Unit::TestCase
4
- def test_invalid_locale_stores_locale
5
- force_invalid_locale
6
- rescue I18n::ArgumentError => e
7
- assert_nil e.locale
8
- end
9
-
10
- def test_invalid_locale_message
11
- force_invalid_locale
12
- rescue I18n::ArgumentError => e
13
- assert_equal 'nil is not a valid locale', e.message
14
- end
15
-
16
- def test_missing_translation_data_stores_locale_key_and_options
17
- force_missing_translation_data
18
- rescue I18n::ArgumentError => e
19
- options = {:scope => :bar}
20
- assert_equal 'de', e.locale
21
- assert_equal :foo, e.key
22
- assert_equal options, e.options
23
- end
24
-
25
- def test_missing_translation_data_message
26
- force_missing_translation_data
27
- rescue I18n::ArgumentError => e
28
- assert_equal 'translation missing: de, bar, foo', e.message
29
- end
30
-
31
- def test_invalid_pluralization_data_stores_entry_and_count
32
- force_invalid_pluralization_data
33
- rescue I18n::ArgumentError => e
34
- assert_equal [:bar], e.entry
35
- assert_equal 1, e.count
36
- end
37
-
38
- def test_invalid_pluralization_data_message
39
- force_invalid_pluralization_data
40
- rescue I18n::ArgumentError => e
41
- assert_equal 'translation data [:bar] can not be used with :count => 1', e.message
42
- end
43
-
44
- def test_missing_interpolation_argument_stores_key_and_string
45
- assert_raises(I18n::MissingInterpolationArgument) { force_missing_interpolation_argument }
46
- force_missing_interpolation_argument
47
- rescue I18n::ArgumentError => e
48
- # assert_equal :bar, e.key
49
- assert_equal "{{bar}}", e.string
50
- end
51
-
52
- def test_missing_interpolation_argument_message
53
- force_missing_interpolation_argument
54
- rescue I18n::ArgumentError => e
55
- assert_equal 'missing interpolation argument in "{{bar}}" ({:baz=>"baz"} given)', e.message
56
- end
57
-
58
- def test_reserved_interpolation_key_stores_key_and_string
59
- force_reserved_interpolation_key
60
- rescue I18n::ArgumentError => e
61
- assert_equal :scope, e.key
62
- assert_equal "{{scope}}", e.string
63
- end
64
-
65
- def test_reserved_interpolation_key_message
66
- force_reserved_interpolation_key
67
- rescue I18n::ArgumentError => e
68
- assert_equal 'reserved key :scope used in "{{scope}}"', e.message
69
- end
70
-
71
- private
72
- def force_invalid_locale
73
- I18n.backend.translate nil, :foo
74
- end
75
-
76
- def force_missing_translation_data
77
- I18n.backend.store_translations 'de', :bar => nil
78
- I18n.backend.translate 'de', :foo, :scope => :bar
79
- end
80
-
81
- def force_invalid_pluralization_data
82
- I18n.backend.store_translations 'de', :foo => [:bar]
83
- I18n.backend.translate 'de', :foo, :count => 1
84
- end
85
-
86
- def force_missing_interpolation_argument
87
- I18n.backend.store_translations 'de', :foo => "{{bar}}"
88
- I18n.backend.translate 'de', :foo, :baz => 'baz'
89
- end
90
-
91
- def force_reserved_interpolation_key
92
- I18n.backend.store_translations 'de', :foo => "{{scope}}"
93
- I18n.backend.translate 'de', :foo, :baz => 'baz'
94
- end
1
+ require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
+
3
+ class I18nExceptionsTest < Test::Unit::TestCase
4
+ def test_invalid_locale_stores_locale
5
+ force_invalid_locale
6
+ rescue I18n::ArgumentError => e
7
+ assert_nil e.locale
8
+ end
9
+
10
+ def test_invalid_locale_message
11
+ force_invalid_locale
12
+ rescue I18n::ArgumentError => e
13
+ assert_equal 'nil is not a valid locale', e.message
14
+ end
15
+
16
+ def test_missing_translation_data_stores_locale_key_and_options
17
+ force_missing_translation_data
18
+ rescue I18n::ArgumentError => e
19
+ options = {:scope => :bar}
20
+ assert_equal 'de', e.locale
21
+ assert_equal :foo, e.key
22
+ assert_equal options, e.options
23
+ end
24
+
25
+ def test_missing_translation_data_message
26
+ force_missing_translation_data
27
+ rescue I18n::ArgumentError => e
28
+ assert_equal 'translation missing: de, bar, foo', e.message
29
+ end
30
+
31
+ def test_invalid_pluralization_data_stores_entry_and_count
32
+ force_invalid_pluralization_data
33
+ rescue I18n::ArgumentError => e
34
+ assert_equal [:bar], e.entry
35
+ assert_equal 1, e.count
36
+ end
37
+
38
+ def test_invalid_pluralization_data_message
39
+ force_invalid_pluralization_data
40
+ rescue I18n::ArgumentError => e
41
+ assert_equal 'translation data [:bar] can not be used with :count => 1', e.message
42
+ end
43
+
44
+ def test_missing_interpolation_argument_stores_key_and_string
45
+ assert_raises(I18n::MissingInterpolationArgument) { force_missing_interpolation_argument }
46
+ force_missing_interpolation_argument
47
+ rescue I18n::ArgumentError => e
48
+ # assert_equal :bar, e.key
49
+ assert_equal "{{bar}}", e.string
50
+ end
51
+
52
+ def test_missing_interpolation_argument_message
53
+ force_missing_interpolation_argument
54
+ rescue I18n::ArgumentError => e
55
+ assert_equal 'missing interpolation argument in "{{bar}}" ({:baz=>"baz"} given)', e.message
56
+ end
57
+
58
+ def test_reserved_interpolation_key_stores_key_and_string
59
+ force_reserved_interpolation_key
60
+ rescue I18n::ArgumentError => e
61
+ assert_equal :scope, e.key
62
+ assert_equal "{{scope}}", e.string
63
+ end
64
+
65
+ def test_reserved_interpolation_key_message
66
+ force_reserved_interpolation_key
67
+ rescue I18n::ArgumentError => e
68
+ assert_equal 'reserved key :scope used in "{{scope}}"', e.message
69
+ end
70
+
71
+ private
72
+ def force_invalid_locale
73
+ I18n.backend.translate nil, :foo
74
+ end
75
+
76
+ def force_missing_translation_data
77
+ I18n.backend.store_translations 'de', :bar => nil
78
+ I18n.backend.translate 'de', :foo, :scope => :bar
79
+ end
80
+
81
+ def force_invalid_pluralization_data
82
+ I18n.backend.store_translations 'de', :foo => [:bar]
83
+ I18n.backend.translate 'de', :foo, :count => 1
84
+ end
85
+
86
+ def force_missing_interpolation_argument
87
+ I18n.backend.store_translations 'de', :foo => "{{bar}}"
88
+ I18n.backend.translate 'de', :foo, :baz => 'baz'
89
+ end
90
+
91
+ def force_reserved_interpolation_key
92
+ I18n.backend.store_translations 'de', :foo => "{{scope}}"
93
+ I18n.backend.translate 'de', :foo, :baz => 'baz'
94
+ end
95
95
  end
@@ -1,16 +1,16 @@
1
- # encoding: utf-8
2
- require File.expand_path(File.dirname(__FILE__) + '/test_helper')
3
-
4
- class I18nLoadPathTest < Test::Unit::TestCase
5
- include Tests::Backend::Simple::Setup::Base
6
-
7
- def test_nested_load_paths_do_not_break_locale_loading
8
- I18n.load_path = [[locales_dir + '/en.yml']]
9
- assert_equal "baz", I18n.t(:'foo.bar')
10
- end
11
-
12
- def test_adding_arrays_of_filenames_to_load_path_do_not_break_locale_loading
13
- I18n.load_path << Dir[locales_dir + '/*.{rb,yml}']
14
- assert_equal "baz", I18n.t(:'foo.bar')
15
- end
16
- end
1
+ # encoding: utf-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/test_helper')
3
+
4
+ class I18nLoadPathTest < Test::Unit::TestCase
5
+ include Tests::Backend::Simple::Setup::Base
6
+
7
+ def test_nested_load_paths_do_not_break_locale_loading
8
+ I18n.load_path = [[locales_dir + '/en.yml']]
9
+ assert_equal "baz", I18n.t(:'foo.bar')
10
+ end
11
+
12
+ def test_adding_arrays_of_filenames_to_load_path_do_not_break_locale_loading
13
+ I18n.load_path << Dir[locales_dir + '/*.{rb,yml}']
14
+ assert_equal "baz", I18n.t(:'foo.bar')
15
+ end
16
+ end
data/test/i18n_test.rb CHANGED
@@ -1,140 +1,140 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
-
3
- class I18nTest < Test::Unit::TestCase
4
- def setup
5
- I18n.backend.store_translations :'en', {
6
- :currency => {
7
- :format => {
8
- :separator => '.',
9
- :delimiter => ',',
10
- }
11
- }
12
- }
13
- end
14
-
15
- def test_uses_simple_backend_set_by_default
16
- assert I18n.backend.is_a?(I18n::Backend::Simple)
17
- end
18
-
19
- def test_can_set_backend
20
- assert_nothing_raised { I18n.backend = self }
21
- assert_equal self, I18n.backend
22
- I18n.backend = I18n::Backend::Simple.new
23
- end
24
-
25
- def test_uses_en_us_as_default_locale_by_default
26
- assert_equal 'en', I18n.default_locale
27
- end
28
-
29
- def test_can_set_default_locale
30
- assert_nothing_raised { I18n.default_locale = 'de' }
31
- assert_equal 'de', I18n.default_locale
32
- I18n.default_locale = 'en'
33
- end
34
-
35
- def test_uses_default_locale_as_locale_by_default
36
- assert_equal I18n.default_locale, I18n.locale
37
- end
38
-
39
- def test_can_set_locale_to_thread_current
40
- assert_nothing_raised { I18n.locale = 'de' }
41
- assert_equal 'de', I18n.locale
42
- assert_equal 'de', Thread.current[:locale]
43
- I18n.locale = 'en'
44
- end
45
-
46
- def test_defaults_to_dot_as_separator
47
- assert_equal '.', I18n.default_separator
48
- end
49
-
50
- def test_can_set_default_separator
51
- assert_nothing_raised { I18n.default_separator = "\001" }
52
- I18n.default_separator = '.' # revert it
53
- end
54
-
55
- def test_normalize_keys
56
- assert_equal [:en, :foo, :bar], I18n.send(:normalize_translation_keys, :en, :bar, :foo)
57
- assert_equal [:en, :foo, :bar, :baz, :buz], I18n.send(:normalize_translation_keys, :en, :'baz.buz', :'foo.bar')
58
- assert_equal [:en, :foo, :bar, :baz, :buz], I18n.send(:normalize_translation_keys, :en, 'baz.buz', 'foo.bar')
59
- assert_equal [:en, :foo, :bar, :baz, :buz], I18n.send(:normalize_translation_keys, :en, %w(baz buz), %w(foo bar))
60
- assert_equal [:en, :foo, :bar, :baz, :buz], I18n.send(:normalize_translation_keys, :en, [:baz, :buz], [:foo, :bar])
61
- end
62
-
63
- def test_uses_passed_separator_to_normalize_keys
64
- assert_equal [:en, :foo, :bar, :baz, :buz], I18n.send(:normalize_translation_keys, :en, :'baz|buz', :'foo|bar', '|')
65
- end
66
-
67
- def test_can_set_exception_handler
68
- assert_nothing_raised { I18n.exception_handler = :custom_exception_handler }
69
- I18n.exception_handler = :default_exception_handler # revert it
70
- end
71
-
72
- def test_uses_custom_exception_handler
73
- I18n.exception_handler = :custom_exception_handler
74
- I18n.expects(:custom_exception_handler)
75
- I18n.translate :bogus
76
- I18n.exception_handler = :default_exception_handler # revert it
77
- end
78
-
79
- def test_delegates_translate_to_backend
80
- I18n.backend.expects(:translate).with 'de', :foo, {}
81
- I18n.translate :foo, :locale => 'de'
82
- end
83
-
84
- def test_delegates_localize_to_backend
85
- I18n.backend.expects(:localize).with 'de', :whatever, :default
86
- I18n.localize :whatever, :locale => 'de'
87
- end
88
-
89
- def test_translate_given_no_locale_uses_i18n_locale
90
- I18n.backend.expects(:translate).with 'en', :foo, {}
91
- I18n.translate :foo
92
- end
93
-
94
- def test_translate_on_nested_symbol_keys_works
95
- assert_equal ".", I18n.t(:'currency.format.separator')
96
- end
97
-
98
- def test_translate_with_nested_string_keys_works
99
- assert_equal ".", I18n.t('currency.format.separator')
100
- end
101
-
102
- def test_translate_with_array_as_scope_works
103
- assert_equal ".", I18n.t(:separator, :scope => %w(currency format))
104
- end
105
-
106
- def test_translate_with_array_containing_dot_separated_strings_as_scope_works
107
- assert_equal ".", I18n.t(:separator, :scope => ['currency.format'])
108
- end
109
-
110
- def test_translate_with_key_array_and_dot_separated_scope_works
111
- assert_equal [".", ","], I18n.t(%w(separator delimiter), :scope => 'currency.format')
112
- end
113
-
114
- def test_translate_with_dot_separated_key_array_and_scope_works
115
- assert_equal [".", ","], I18n.t(%w(format.separator format.delimiter), :scope => 'currency')
116
- end
117
-
118
- def test_translate_with_options_using_scope_works
119
- I18n.backend.expects(:translate).with('de', :precision, :scope => :"currency.format")
120
- I18n.with_options :locale => 'de', :scope => :'currency.format' do |locale|
121
- locale.t :precision
122
- end
123
- end
124
-
125
- # def test_translate_given_no_args_raises_missing_translation_data
126
- # assert_equal "translation missing: en, no key", I18n.t
127
- # end
128
-
129
- def test_translate_given_a_bogus_key_raises_missing_translation_data
130
- assert_equal "translation missing: en, bogus", I18n.t(:bogus)
131
- end
132
-
133
- def test_localize_nil_raises_argument_error
134
- assert_raises(I18n::ArgumentError) { I18n.l nil }
135
- end
136
-
137
- def test_localize_object_raises_argument_error
138
- assert_raises(I18n::ArgumentError) { I18n.l Object.new }
139
- end
140
- end
1
+ require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
+
3
+ class I18nTest < Test::Unit::TestCase
4
+ def setup
5
+ I18n.backend.store_translations :'en', {
6
+ :currency => {
7
+ :format => {
8
+ :separator => '.',
9
+ :delimiter => ',',
10
+ }
11
+ }
12
+ }
13
+ end
14
+
15
+ def test_uses_simple_backend_set_by_default
16
+ assert I18n.backend.is_a?(I18n::Backend::Simple)
17
+ end
18
+
19
+ def test_can_set_backend
20
+ assert_nothing_raised { I18n.backend = self }
21
+ assert_equal self, I18n.backend
22
+ I18n.backend = I18n::Backend::Simple.new
23
+ end
24
+
25
+ def test_uses_en_us_as_default_locale_by_default
26
+ assert_equal 'en', I18n.default_locale
27
+ end
28
+
29
+ def test_can_set_default_locale
30
+ assert_nothing_raised { I18n.default_locale = 'de' }
31
+ assert_equal 'de', I18n.default_locale
32
+ I18n.default_locale = 'en'
33
+ end
34
+
35
+ def test_uses_default_locale_as_locale_by_default
36
+ assert_equal I18n.default_locale, I18n.locale
37
+ end
38
+
39
+ def test_can_set_locale_to_thread_current
40
+ assert_nothing_raised { I18n.locale = 'de' }
41
+ assert_equal 'de', I18n.locale
42
+ assert_equal 'de', Thread.current[:locale]
43
+ I18n.locale = 'en'
44
+ end
45
+
46
+ def test_defaults_to_dot_as_separator
47
+ assert_equal '.', I18n.default_separator
48
+ end
49
+
50
+ def test_can_set_default_separator
51
+ assert_nothing_raised { I18n.default_separator = "\001" }
52
+ I18n.default_separator = '.' # revert it
53
+ end
54
+
55
+ def test_normalize_keys
56
+ assert_equal [:en, :foo, :bar], I18n.send(:normalize_translation_keys, :en, :bar, :foo)
57
+ assert_equal [:en, :foo, :bar, :baz, :buz], I18n.send(:normalize_translation_keys, :en, :'baz.buz', :'foo.bar')
58
+ assert_equal [:en, :foo, :bar, :baz, :buz], I18n.send(:normalize_translation_keys, :en, 'baz.buz', 'foo.bar')
59
+ assert_equal [:en, :foo, :bar, :baz, :buz], I18n.send(:normalize_translation_keys, :en, %w(baz buz), %w(foo bar))
60
+ assert_equal [:en, :foo, :bar, :baz, :buz], I18n.send(:normalize_translation_keys, :en, [:baz, :buz], [:foo, :bar])
61
+ end
62
+
63
+ def test_uses_passed_separator_to_normalize_keys
64
+ assert_equal [:en, :foo, :bar, :baz, :buz], I18n.send(:normalize_translation_keys, :en, :'baz|buz', :'foo|bar', '|')
65
+ end
66
+
67
+ def test_can_set_exception_handler
68
+ assert_nothing_raised { I18n.exception_handler = :custom_exception_handler }
69
+ I18n.exception_handler = :default_exception_handler # revert it
70
+ end
71
+
72
+ def test_uses_custom_exception_handler
73
+ I18n.exception_handler = :custom_exception_handler
74
+ I18n.expects(:custom_exception_handler)
75
+ I18n.translate :bogus
76
+ I18n.exception_handler = :default_exception_handler # revert it
77
+ end
78
+
79
+ def test_delegates_translate_to_backend
80
+ I18n.backend.expects(:translate).with 'de', :foo, {}
81
+ I18n.translate :foo, :locale => 'de'
82
+ end
83
+
84
+ def test_delegates_localize_to_backend
85
+ I18n.backend.expects(:localize).with 'de', :whatever, :default
86
+ I18n.localize :whatever, :locale => 'de'
87
+ end
88
+
89
+ def test_translate_given_no_locale_uses_i18n_locale
90
+ I18n.backend.expects(:translate).with 'en', :foo, {}
91
+ I18n.translate :foo
92
+ end
93
+
94
+ def test_translate_on_nested_symbol_keys_works
95
+ assert_equal ".", I18n.t(:'currency.format.separator')
96
+ end
97
+
98
+ def test_translate_with_nested_string_keys_works
99
+ assert_equal ".", I18n.t('currency.format.separator')
100
+ end
101
+
102
+ def test_translate_with_array_as_scope_works
103
+ assert_equal ".", I18n.t(:separator, :scope => %w(currency format))
104
+ end
105
+
106
+ def test_translate_with_array_containing_dot_separated_strings_as_scope_works
107
+ assert_equal ".", I18n.t(:separator, :scope => ['currency.format'])
108
+ end
109
+
110
+ def test_translate_with_key_array_and_dot_separated_scope_works
111
+ assert_equal [".", ","], I18n.t(%w(separator delimiter), :scope => 'currency.format')
112
+ end
113
+
114
+ def test_translate_with_dot_separated_key_array_and_scope_works
115
+ assert_equal [".", ","], I18n.t(%w(format.separator format.delimiter), :scope => 'currency')
116
+ end
117
+
118
+ def test_translate_with_options_using_scope_works
119
+ I18n.backend.expects(:translate).with('de', :precision, :scope => :"currency.format")
120
+ I18n.with_options :locale => 'de', :scope => :'currency.format' do |locale|
121
+ locale.t :precision
122
+ end
123
+ end
124
+
125
+ # def test_translate_given_no_args_raises_missing_translation_data
126
+ # assert_equal "translation missing: en, no key", I18n.t
127
+ # end
128
+
129
+ def test_translate_given_a_bogus_key_raises_missing_translation_data
130
+ assert_equal "translation missing: en, bogus", I18n.t(:bogus)
131
+ end
132
+
133
+ def test_localize_nil_raises_argument_error
134
+ assert_raises(I18n::ArgumentError) { I18n.l nil }
135
+ end
136
+
137
+ def test_localize_object_raises_argument_error
138
+ assert_raises(I18n::ArgumentError) { I18n.l Object.new }
139
+ end
140
+ end