i18n 0.1.0 → 0.2.0

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.

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