russian 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.textile +3 -3
- data/Rakefile +1 -1
- data/TODO +1 -0
- data/lib/russian.rb +1 -1
- data/lib/russian/locale/actionview.yml +0 -1
- data/lib/russian/locale/activerecord.yml +1 -1
- data/lib/russian/locale/activesupport.yml +1 -0
- data/lib/vendor/i18n/README.textile +2 -0
- data/lib/vendor/i18n/i18n.gemspec +21 -18
- data/lib/vendor/i18n/lib/i18n.rb +53 -44
- data/lib/vendor/i18n/lib/i18n/backend/simple.rb +70 -52
- data/lib/vendor/i18n/lib/i18n/exceptions.rb +3 -3
- data/lib/vendor/i18n/test/all.rb +1 -1
- data/lib/vendor/i18n/test/i18n_exceptions_test.rb +14 -14
- data/lib/vendor/i18n/test/i18n_test.rb +23 -23
- data/lib/vendor/i18n/test/simple_backend_test.rb +121 -92
- data/spec/locale_spec.rb +0 -1
- metadata +3 -3
@@ -1,6 +1,6 @@
|
|
1
1
|
module I18n
|
2
2
|
class ArgumentError < ::ArgumentError; end
|
3
|
-
|
3
|
+
|
4
4
|
class InvalidLocale < ArgumentError
|
5
5
|
attr_reader :locale
|
6
6
|
def initialize(locale)
|
@@ -42,7 +42,7 @@ module I18n
|
|
42
42
|
super "reserved key #{key.inspect} used in #{string.inspect}"
|
43
43
|
end
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
class UnknownFileType < ArgumentError
|
47
47
|
attr_reader :type, :filename
|
48
48
|
def initialize(type, filename)
|
@@ -50,4 +50,4 @@ module I18n
|
|
50
50
|
super "can not load translations from #{filename}, the file type #{type} is not known"
|
51
51
|
end
|
52
52
|
end
|
53
|
-
end
|
53
|
+
end
|
data/lib/vendor/i18n/test/all.rb
CHANGED
@@ -12,13 +12,13 @@ class I18nExceptionsTest < Test::Unit::TestCase
|
|
12
12
|
rescue I18n::ArgumentError => e
|
13
13
|
assert_nil e.locale
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def test_invalid_locale_message
|
17
17
|
force_invalid_locale
|
18
18
|
rescue I18n::ArgumentError => e
|
19
19
|
assert_equal 'nil is not a valid locale', e.message
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def test_missing_translation_data_stores_locale_key_and_options
|
23
23
|
force_missing_translation_data
|
24
24
|
rescue I18n::ArgumentError => e
|
@@ -27,72 +27,72 @@ class I18nExceptionsTest < Test::Unit::TestCase
|
|
27
27
|
assert_equal :foo, e.key
|
28
28
|
assert_equal options, e.options
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def test_missing_translation_data_message
|
32
32
|
force_missing_translation_data
|
33
33
|
rescue I18n::ArgumentError => e
|
34
34
|
assert_equal 'translation missing: de-DE, bar, foo', e.message
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def test_invalid_pluralization_data_stores_entry_and_count
|
38
38
|
force_invalid_pluralization_data
|
39
39
|
rescue I18n::ArgumentError => e
|
40
40
|
assert_equal [:bar], e.entry
|
41
41
|
assert_equal 1, e.count
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def test_invalid_pluralization_data_message
|
45
45
|
force_invalid_pluralization_data
|
46
46
|
rescue I18n::ArgumentError => e
|
47
47
|
assert_equal 'translation data [:bar] can not be used with :count => 1', e.message
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
def test_missing_interpolation_argument_stores_key_and_string
|
51
51
|
force_missing_interpolation_argument
|
52
52
|
rescue I18n::ArgumentError => e
|
53
53
|
assert_equal 'bar', e.key
|
54
54
|
assert_equal "{{bar}}", e.string
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
def test_missing_interpolation_argument_message
|
58
58
|
force_missing_interpolation_argument
|
59
59
|
rescue I18n::ArgumentError => e
|
60
60
|
assert_equal 'interpolation argument bar missing in "{{bar}}"', e.message
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
def test_reserved_interpolation_key_stores_key_and_string
|
64
64
|
force_reserved_interpolation_key
|
65
65
|
rescue I18n::ArgumentError => e
|
66
66
|
assert_equal 'scope', e.key
|
67
67
|
assert_equal "{{scope}}", e.string
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
def test_reserved_interpolation_key_message
|
71
71
|
force_reserved_interpolation_key
|
72
72
|
rescue I18n::ArgumentError => e
|
73
73
|
assert_equal 'reserved key "scope" used in "{{scope}}"', e.message
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
private
|
77
77
|
def force_invalid_locale
|
78
78
|
I18n.backend.translate nil, :foo
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
def force_missing_translation_data
|
82
82
|
I18n.backend.store_translations 'de-DE', :bar => nil
|
83
83
|
I18n.backend.translate 'de-DE', :foo, :scope => :bar
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
def force_invalid_pluralization_data
|
87
87
|
I18n.backend.store_translations 'de-DE', :foo => [:bar]
|
88
88
|
I18n.backend.translate 'de-DE', :foo, :count => 1
|
89
89
|
end
|
90
|
-
|
90
|
+
|
91
91
|
def force_missing_interpolation_argument
|
92
92
|
I18n.backend.store_translations 'de-DE', :foo => "{{bar}}"
|
93
93
|
I18n.backend.translate 'de-DE', :foo, :baz => 'baz'
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
def force_reserved_interpolation_key
|
97
97
|
I18n.backend.store_translations 'de-DE', :foo => "{{scope}}"
|
98
98
|
I18n.backend.translate 'de-DE', :foo, :baz => 'baz'
|
@@ -17,108 +17,108 @@ class I18nTest < Test::Unit::TestCase
|
|
17
17
|
}
|
18
18
|
}
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def test_uses_simple_backend_set_by_default
|
22
22
|
assert I18n.backend.is_a?(I18n::Backend::Simple)
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def test_can_set_backend
|
26
26
|
assert_nothing_raised{ I18n.backend = self }
|
27
27
|
assert_equal self, I18n.backend
|
28
28
|
I18n.backend = I18n::Backend::Simple.new
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def test_uses_en_us_as_default_locale_by_default
|
32
32
|
assert_equal 'en-US', I18n.default_locale
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def test_can_set_default_locale
|
36
36
|
assert_nothing_raised{ I18n.default_locale = 'de-DE' }
|
37
37
|
assert_equal 'de-DE', I18n.default_locale
|
38
38
|
I18n.default_locale = 'en-US'
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def test_uses_default_locale_as_locale_by_default
|
42
42
|
assert_equal I18n.default_locale, I18n.locale
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
def test_can_set_locale_to_thread_current
|
46
46
|
assert_nothing_raised{ I18n.locale = 'de-DE' }
|
47
47
|
assert_equal 'de-DE', I18n.locale
|
48
48
|
assert_equal 'de-DE', Thread.current[:locale]
|
49
49
|
I18n.locale = 'en-US'
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
def test_can_set_exception_handler
|
53
53
|
assert_nothing_raised{ I18n.exception_handler = :custom_exception_handler }
|
54
54
|
I18n.exception_handler = :default_exception_handler # revert it
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
def test_uses_custom_exception_handler
|
58
58
|
I18n.exception_handler = :custom_exception_handler
|
59
59
|
I18n.expects(:custom_exception_handler)
|
60
60
|
I18n.translate :bogus
|
61
61
|
I18n.exception_handler = :default_exception_handler # revert it
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
def test_delegates_translate_to_backend
|
65
65
|
I18n.backend.expects(:translate).with 'de-DE', :foo, {}
|
66
66
|
I18n.translate :foo, :locale => 'de-DE'
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
def test_delegates_localize_to_backend
|
70
70
|
I18n.backend.expects(:localize).with 'de-DE', :whatever, :default
|
71
71
|
I18n.localize :whatever, :locale => 'de-DE'
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
def test_translate_given_no_locale_uses_i18n_locale
|
75
75
|
I18n.backend.expects(:translate).with 'en-US', :foo, {}
|
76
76
|
I18n.translate :foo
|
77
|
-
end
|
78
|
-
|
77
|
+
end
|
78
|
+
|
79
79
|
def test_translate_on_nested_symbol_keys_works
|
80
80
|
assert_equal ".", I18n.t(:'currency.format.separator')
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
def test_translate_with_nested_string_keys_works
|
84
84
|
assert_equal ".", I18n.t('currency.format.separator')
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
def test_translate_with_array_as_scope_works
|
88
88
|
assert_equal ".", I18n.t(:separator, :scope => ['currency.format'])
|
89
89
|
end
|
90
|
-
|
90
|
+
|
91
91
|
def test_translate_with_array_containing_dot_separated_strings_as_scope_works
|
92
92
|
assert_equal ".", I18n.t(:separator, :scope => ['currency.format'])
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
def test_translate_with_key_array_and_dot_separated_scope_works
|
96
96
|
assert_equal [".", ","], I18n.t(%w(separator delimiter), :scope => 'currency.format')
|
97
97
|
end
|
98
|
-
|
98
|
+
|
99
99
|
def test_translate_with_dot_separated_key_array_and_scope_works
|
100
100
|
assert_equal [".", ","], I18n.t(%w(format.separator format.delimiter), :scope => 'currency')
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
def test_translate_with_options_using_scope_works
|
104
104
|
I18n.backend.expects(:translate).with('de-DE', :precision, :scope => :"currency.format")
|
105
105
|
I18n.with_options :locale => 'de-DE', :scope => :'currency.format' do |locale|
|
106
106
|
locale.t :precision
|
107
107
|
end
|
108
108
|
end
|
109
|
-
|
109
|
+
|
110
110
|
# def test_translate_given_no_args_raises_missing_translation_data
|
111
111
|
# assert_equal "translation missing: en-US, no key", I18n.t
|
112
112
|
# end
|
113
|
-
|
113
|
+
|
114
114
|
def test_translate_given_a_bogus_key_raises_missing_translation_data
|
115
115
|
assert_equal "translation missing: en-US, bogus", I18n.t(:bogus)
|
116
116
|
end
|
117
|
-
|
117
|
+
|
118
118
|
def test_localize_nil_raises_argument_error
|
119
119
|
assert_raises(I18n::ArgumentError) { I18n.l nil }
|
120
120
|
end
|
121
|
-
|
121
|
+
|
122
122
|
def test_localize_object_raises_argument_error
|
123
123
|
assert_raises(I18n::ArgumentError) { I18n.l Object.new }
|
124
124
|
end
|
@@ -16,7 +16,7 @@ module I18nSimpleBackendTestSetup
|
|
16
16
|
@locale_dir = File.dirname(__FILE__) + '/locale'
|
17
17
|
end
|
18
18
|
alias :setup :setup_backend
|
19
|
-
|
19
|
+
|
20
20
|
# def backend_reset_translations!
|
21
21
|
# I18n::Backend::Simple::ClassMethods.send :class_variable_set, :@@translations, {}
|
22
22
|
# end
|
@@ -24,8 +24,8 @@ module I18nSimpleBackendTestSetup
|
|
24
24
|
def backend_get_translations
|
25
25
|
# I18n::Backend::Simple::ClassMethods.send :class_variable_get, :@@translations
|
26
26
|
@backend.instance_variable_get :@translations
|
27
|
-
end
|
28
|
-
|
27
|
+
end
|
28
|
+
|
29
29
|
def add_datetime_translations
|
30
30
|
@backend.store_translations :'de-DE', {
|
31
31
|
:date => {
|
@@ -53,77 +53,77 @@ module I18nSimpleBackendTestSetup
|
|
53
53
|
:distance_in_words => {
|
54
54
|
:half_a_minute => 'half a minute',
|
55
55
|
:less_than_x_seconds => {
|
56
|
-
:one => 'less than 1 second',
|
56
|
+
:one => 'less than 1 second',
|
57
57
|
:other => 'less than {{count}} seconds'
|
58
58
|
},
|
59
59
|
:x_seconds => {
|
60
|
-
:one => '1 second',
|
60
|
+
:one => '1 second',
|
61
61
|
:other => '{{count}} seconds'
|
62
62
|
},
|
63
63
|
:less_than_x_minutes => {
|
64
|
-
:one => 'less than a minute',
|
64
|
+
:one => 'less than a minute',
|
65
65
|
:other => 'less than {{count}} minutes'
|
66
66
|
},
|
67
67
|
:x_minutes => {
|
68
|
-
:one => '1 minute',
|
68
|
+
:one => '1 minute',
|
69
69
|
:other => '{{count}} minutes'
|
70
70
|
},
|
71
71
|
:about_x_hours => {
|
72
|
-
:one => 'about 1 hour',
|
72
|
+
:one => 'about 1 hour',
|
73
73
|
:other => 'about {{count}} hours'
|
74
74
|
},
|
75
75
|
:x_days => {
|
76
76
|
:one => '1 day',
|
77
|
-
:other => '{{count}} days'
|
77
|
+
:other => '{{count}} days'
|
78
78
|
},
|
79
|
-
:about_x_months => {
|
80
|
-
:one => 'about 1 month',
|
79
|
+
:about_x_months => {
|
80
|
+
:one => 'about 1 month',
|
81
81
|
:other => 'about {{count}} months'
|
82
82
|
},
|
83
83
|
:x_months => {
|
84
|
-
:one => '1 month',
|
84
|
+
:one => '1 month',
|
85
85
|
:other => '{{count}} months'
|
86
86
|
},
|
87
87
|
:about_x_years => {
|
88
|
-
:one => 'about 1 year',
|
88
|
+
:one => 'about 1 year',
|
89
89
|
:other => 'about {{count}} year'
|
90
90
|
},
|
91
91
|
:over_x_years => {
|
92
|
-
:one => 'over 1 year',
|
92
|
+
:one => 'over 1 year',
|
93
93
|
:other => 'over {{count}} years'
|
94
94
|
}
|
95
95
|
}
|
96
|
-
}
|
96
|
+
}
|
97
97
|
}
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
101
|
class I18nSimpleBackendTranslationsTest < Test::Unit::TestCase
|
102
102
|
include I18nSimpleBackendTestSetup
|
103
|
-
|
103
|
+
|
104
104
|
def test_store_translations_adds_translations # no, really :-)
|
105
105
|
@backend.store_translations :'en-US', :foo => 'bar'
|
106
106
|
assert_equal Hash[:'en-US', {:foo => 'bar'}], backend_get_translations
|
107
107
|
end
|
108
|
-
|
108
|
+
|
109
109
|
def test_store_translations_deep_merges_translations
|
110
110
|
@backend.store_translations :'en-US', :foo => {:bar => 'bar'}
|
111
111
|
@backend.store_translations :'en-US', :foo => {:baz => 'baz'}
|
112
112
|
assert_equal Hash[:'en-US', {:foo => {:bar => 'bar', :baz => 'baz'}}], backend_get_translations
|
113
113
|
end
|
114
|
-
|
114
|
+
|
115
115
|
def test_store_translations_forces_locale_to_sym
|
116
116
|
@backend.store_translations 'en-US', :foo => 'bar'
|
117
117
|
assert_equal Hash[:'en-US', {:foo => 'bar'}], backend_get_translations
|
118
118
|
end
|
119
|
-
|
119
|
+
|
120
120
|
def test_store_translations_converts_keys_to_symbols
|
121
121
|
# backend_reset_translations!
|
122
122
|
@backend.store_translations 'en-US', 'foo' => {'bar' => 'bar', 'baz' => 'baz'}
|
123
|
-
assert_equal Hash[:'en-US', {:foo => {:bar => 'bar', :baz => 'baz'}}], backend_get_translations
|
123
|
+
assert_equal Hash[:'en-US', {:foo => {:bar => 'bar', :baz => 'baz'}}], backend_get_translations
|
124
124
|
end
|
125
125
|
end
|
126
|
-
|
126
|
+
|
127
127
|
class I18nSimpleBackendTranslateTest < Test::Unit::TestCase
|
128
128
|
include I18nSimpleBackendTestSetup
|
129
129
|
|
@@ -131,110 +131,110 @@ class I18nSimpleBackendTranslateTest < Test::Unit::TestCase
|
|
131
131
|
@backend.expects(:lookup).with('de-DE', :bar, [:foo]).returns 'bar'
|
132
132
|
@backend.translate 'de-DE', :bar, :scope => [:foo]
|
133
133
|
end
|
134
|
-
|
134
|
+
|
135
135
|
def test_given_no_keys_it_returns_the_default
|
136
|
-
assert_equal 'default', @backend.translate('en-US', nil, :default => 'default')
|
136
|
+
assert_equal 'default', @backend.translate('en-US', nil, :default => 'default')
|
137
137
|
end
|
138
|
-
|
138
|
+
|
139
139
|
def test_translate_given_a_symbol_as_a_default_translates_the_symbol
|
140
140
|
assert_equal 'bar', @backend.translate('en-US', nil, :scope => [:foo], :default => :bar)
|
141
141
|
end
|
142
|
-
|
142
|
+
|
143
143
|
def test_translate_given_an_array_as_default_uses_the_first_match
|
144
144
|
assert_equal 'bar', @backend.translate('en-US', :does_not_exist, :scope => [:foo], :default => [:does_not_exist_2, :bar])
|
145
145
|
end
|
146
|
-
|
146
|
+
|
147
147
|
def test_translate_given_an_array_of_inexistent_keys_it_raises_missing_translation_data
|
148
|
-
assert_raises I18n::MissingTranslationData do
|
148
|
+
assert_raises I18n::MissingTranslationData do
|
149
149
|
@backend.translate('en-US', :does_not_exist, :scope => [:foo], :default => [:does_not_exist_2, :does_not_exist_3])
|
150
150
|
end
|
151
151
|
end
|
152
|
-
|
152
|
+
|
153
153
|
def test_translate_an_array_of_keys_translates_all_of_them
|
154
154
|
assert_equal %w(bar baz), @backend.translate('en-US', [:bar, :baz], :scope => [:foo])
|
155
155
|
end
|
156
|
-
|
156
|
+
|
157
157
|
def test_translate_calls_pluralize
|
158
158
|
@backend.expects(:pluralize).with 'en-US', 'bar', 1
|
159
159
|
@backend.translate 'en-US', :bar, :scope => [:foo], :count => 1
|
160
160
|
end
|
161
|
-
|
161
|
+
|
162
162
|
def test_translate_calls_interpolate
|
163
163
|
@backend.expects(:interpolate).with 'en-US', 'bar', {}
|
164
164
|
@backend.translate 'en-US', :bar, :scope => [:foo]
|
165
165
|
end
|
166
|
-
|
166
|
+
|
167
167
|
def test_translate_calls_interpolate_including_count_as_a_value
|
168
168
|
@backend.expects(:interpolate).with 'en-US', 'bar', {:count => 1}
|
169
169
|
@backend.translate 'en-US', :bar, :scope => [:foo], :count => 1
|
170
170
|
end
|
171
|
-
|
171
|
+
|
172
172
|
def test_translate_given_nil_as_a_locale_raises_an_argument_error
|
173
173
|
assert_raises(I18n::InvalidLocale){ @backend.translate nil, :bar }
|
174
174
|
end
|
175
|
-
|
175
|
+
|
176
176
|
def test_translate_with_a_bogus_key_and_no_default_raises_missing_translation_data
|
177
177
|
assert_raises(I18n::MissingTranslationData){ @backend.translate 'de-DE', :bogus }
|
178
178
|
end
|
179
179
|
end
|
180
|
-
|
180
|
+
|
181
181
|
class I18nSimpleBackendLookupTest < Test::Unit::TestCase
|
182
182
|
include I18nSimpleBackendTestSetup
|
183
|
-
|
183
|
+
|
184
184
|
# useful because this way we can use the backend with no key for interpolation/pluralization
|
185
|
-
def test_lookup_given_nil_as_a_key_returns_nil
|
185
|
+
def test_lookup_given_nil_as_a_key_returns_nil
|
186
186
|
assert_nil @backend.send(:lookup, 'en-US', nil)
|
187
187
|
end
|
188
|
-
|
188
|
+
|
189
189
|
def test_lookup_given_nested_keys_looks_up_a_nested_hash_value
|
190
190
|
assert_equal 'bar', @backend.send(:lookup, 'en-US', :bar, [:foo])
|
191
191
|
end
|
192
192
|
end
|
193
|
-
|
193
|
+
|
194
194
|
class I18nSimpleBackendPluralizeTest < Test::Unit::TestCase
|
195
195
|
include I18nSimpleBackendTestSetup
|
196
|
-
|
196
|
+
|
197
197
|
def test_pluralize_given_nil_returns_the_given_entry
|
198
198
|
entry = {:one => 'bar', :other => 'bars'}
|
199
199
|
assert_equal entry, @backend.send(:pluralize, nil, entry, nil)
|
200
200
|
end
|
201
|
-
|
201
|
+
|
202
202
|
def test_pluralize_given_0_returns_zero_string_if_zero_key_given
|
203
203
|
assert_equal 'zero', @backend.send(:pluralize, nil, {:zero => 'zero', :one => 'bar', :other => 'bars'}, 0)
|
204
204
|
end
|
205
|
-
|
205
|
+
|
206
206
|
def test_pluralize_given_0_returns_plural_string_if_no_zero_key_given
|
207
207
|
assert_equal 'bars', @backend.send(:pluralize, nil, {:one => 'bar', :other => 'bars'}, 0)
|
208
208
|
end
|
209
|
-
|
209
|
+
|
210
210
|
def test_pluralize_given_1_returns_singular_string
|
211
211
|
assert_equal 'bar', @backend.send(:pluralize, nil, {:one => 'bar', :other => 'bars'}, 1)
|
212
212
|
end
|
213
|
-
|
213
|
+
|
214
214
|
def test_pluralize_given_2_returns_plural_string
|
215
215
|
assert_equal 'bars', @backend.send(:pluralize, nil, {:one => 'bar', :other => 'bars'}, 2)
|
216
216
|
end
|
217
|
-
|
217
|
+
|
218
218
|
def test_pluralize_given_3_returns_plural_string
|
219
219
|
assert_equal 'bars', @backend.send(:pluralize, nil, {:one => 'bar', :other => 'bars'}, 3)
|
220
220
|
end
|
221
|
-
|
221
|
+
|
222
222
|
def test_interpolate_given_incomplete_pluralization_data_raises_invalid_pluralization_data
|
223
223
|
assert_raises(I18n::InvalidPluralizationData){ @backend.send(:pluralize, nil, {:one => 'bar'}, 2) }
|
224
224
|
end
|
225
|
-
|
225
|
+
|
226
226
|
# def test_interpolate_given_a_string_raises_invalid_pluralization_data
|
227
227
|
# assert_raises(I18n::InvalidPluralizationData){ @backend.send(:pluralize, nil, 'bar', 2) }
|
228
228
|
# end
|
229
|
-
#
|
229
|
+
#
|
230
230
|
# def test_interpolate_given_an_array_raises_invalid_pluralization_data
|
231
231
|
# assert_raises(I18n::InvalidPluralizationData){ @backend.send(:pluralize, nil, ['bar'], 2) }
|
232
232
|
# end
|
233
233
|
end
|
234
|
-
|
234
|
+
|
235
235
|
class I18nSimpleBackendInterpolateTest < Test::Unit::TestCase
|
236
236
|
include I18nSimpleBackendTestSetup
|
237
|
-
|
237
|
+
|
238
238
|
def test_interpolate_given_a_value_hash_interpolates_the_values_to_the_string
|
239
239
|
assert_equal 'Hi David!', @backend.send(:interpolate, nil, 'Hi {{name}}!', :name => 'David')
|
240
240
|
end
|
@@ -246,19 +246,19 @@ class I18nSimpleBackendInterpolateTest < Test::Unit::TestCase
|
|
246
246
|
def test_interpolate_given_nil_as_a_string_returns_nil
|
247
247
|
assert_nil @backend.send(:interpolate, nil, nil, :name => 'David')
|
248
248
|
end
|
249
|
-
|
249
|
+
|
250
250
|
def test_interpolate_given_an_non_string_as_a_string_returns_nil
|
251
251
|
assert_equal [], @backend.send(:interpolate, nil, [], :name => 'David')
|
252
252
|
end
|
253
|
-
|
253
|
+
|
254
254
|
def test_interpolate_given_a_values_hash_with_nil_values_interpolates_the_string
|
255
255
|
assert_equal 'Hi !', @backend.send(:interpolate, nil, 'Hi {{name}}!', {:name => nil})
|
256
256
|
end
|
257
|
-
|
257
|
+
|
258
258
|
def test_interpolate_given_an_empty_values_hash_raises_missing_interpolation_argument
|
259
259
|
assert_raises(I18n::MissingInterpolationArgument) { @backend.send(:interpolate, nil, 'Hi {{name}}!', {}) }
|
260
260
|
end
|
261
|
-
|
261
|
+
|
262
262
|
def test_interpolate_given_a_string_containing_a_reserved_key_raises_reserved_interpolation_key
|
263
263
|
assert_raises(I18n::ReservedInterpolationKey) { @backend.send(:interpolate, nil, '{{default}}', {:default => nil}) }
|
264
264
|
end
|
@@ -266,53 +266,53 @@ end
|
|
266
266
|
|
267
267
|
class I18nSimpleBackendLocalizeDateTest < Test::Unit::TestCase
|
268
268
|
include I18nSimpleBackendTestSetup
|
269
|
-
|
269
|
+
|
270
270
|
def setup
|
271
271
|
@backend = I18n::Backend::Simple.new
|
272
272
|
add_datetime_translations
|
273
273
|
@date = Date.new 2008, 1, 1
|
274
274
|
end
|
275
|
-
|
275
|
+
|
276
276
|
def test_translate_given_the_short_format_it_uses_it
|
277
277
|
assert_equal '01. Jan', @backend.localize('de-DE', @date, :short)
|
278
278
|
end
|
279
|
-
|
279
|
+
|
280
280
|
def test_translate_given_the_long_format_it_uses_it
|
281
281
|
assert_equal '01. Januar 2008', @backend.localize('de-DE', @date, :long)
|
282
282
|
end
|
283
|
-
|
283
|
+
|
284
284
|
def test_translate_given_the_default_format_it_uses_it
|
285
285
|
assert_equal '01.01.2008', @backend.localize('de-DE', @date, :default)
|
286
286
|
end
|
287
|
-
|
287
|
+
|
288
288
|
def test_translate_given_a_day_name_format_it_returns_a_day_name
|
289
289
|
assert_equal 'Dienstag', @backend.localize('de-DE', @date, '%A')
|
290
290
|
end
|
291
|
-
|
291
|
+
|
292
292
|
def test_translate_given_an_abbr_day_name_format_it_returns_an_abbrevated_day_name
|
293
293
|
assert_equal 'Di', @backend.localize('de-DE', @date, '%a')
|
294
294
|
end
|
295
|
-
|
295
|
+
|
296
296
|
def test_translate_given_a_month_name_format_it_returns_a_month_name
|
297
297
|
assert_equal 'Januar', @backend.localize('de-DE', @date, '%B')
|
298
298
|
end
|
299
|
-
|
299
|
+
|
300
300
|
def test_translate_given_an_abbr_month_name_format_it_returns_an_abbrevated_month_name
|
301
301
|
assert_equal 'Jan', @backend.localize('de-DE', @date, '%b')
|
302
302
|
end
|
303
|
-
|
303
|
+
|
304
304
|
def test_translate_given_no_format_it_does_not_fail
|
305
305
|
assert_nothing_raised{ @backend.localize 'de-DE', @date }
|
306
306
|
end
|
307
|
-
|
307
|
+
|
308
308
|
def test_translate_given_an_unknown_format_it_does_not_fail
|
309
309
|
assert_nothing_raised{ @backend.localize 'de-DE', @date, '%x' }
|
310
|
-
end
|
311
|
-
|
310
|
+
end
|
311
|
+
|
312
312
|
def test_localize_nil_raises_argument_error
|
313
313
|
assert_raises(I18n::ArgumentError) { @backend.localize 'de-DE', nil }
|
314
314
|
end
|
315
|
-
|
315
|
+
|
316
316
|
def test_localize_object_raises_argument_error
|
317
317
|
assert_raises(I18n::ArgumentError) { @backend.localize 'de-DE', Object.new }
|
318
318
|
end
|
@@ -320,59 +320,59 @@ end
|
|
320
320
|
|
321
321
|
class I18nSimpleBackendLocalizeDateTimeTest < Test::Unit::TestCase
|
322
322
|
include I18nSimpleBackendTestSetup
|
323
|
-
|
323
|
+
|
324
324
|
def setup
|
325
325
|
@backend = I18n::Backend::Simple.new
|
326
326
|
add_datetime_translations
|
327
327
|
@morning = DateTime.new 2008, 1, 1, 6
|
328
328
|
@evening = DateTime.new 2008, 1, 1, 18
|
329
329
|
end
|
330
|
-
|
330
|
+
|
331
331
|
def test_translate_given_the_short_format_it_uses_it
|
332
332
|
assert_equal '01. Jan 06:00', @backend.localize('de-DE', @morning, :short)
|
333
333
|
end
|
334
|
-
|
334
|
+
|
335
335
|
def test_translate_given_the_long_format_it_uses_it
|
336
336
|
assert_equal '01. Januar 2008 06:00', @backend.localize('de-DE', @morning, :long)
|
337
337
|
end
|
338
|
-
|
338
|
+
|
339
339
|
def test_translate_given_the_default_format_it_uses_it
|
340
340
|
assert_equal 'Di, 01. Jan 2008 06:00:00 +0000', @backend.localize('de-DE', @morning, :default)
|
341
341
|
end
|
342
|
-
|
342
|
+
|
343
343
|
def test_translate_given_a_day_name_format_it_returns_the_correct_day_name
|
344
344
|
assert_equal 'Dienstag', @backend.localize('de-DE', @morning, '%A')
|
345
345
|
end
|
346
|
-
|
346
|
+
|
347
347
|
def test_translate_given_an_abbr_day_name_format_it_returns_the_correct_abbrevated_day_name
|
348
348
|
assert_equal 'Di', @backend.localize('de-DE', @morning, '%a')
|
349
349
|
end
|
350
|
-
|
350
|
+
|
351
351
|
def test_translate_given_a_month_name_format_it_returns_the_correct_month_name
|
352
352
|
assert_equal 'Januar', @backend.localize('de-DE', @morning, '%B')
|
353
353
|
end
|
354
|
-
|
354
|
+
|
355
355
|
def test_translate_given_an_abbr_month_name_format_it_returns_the_correct_abbrevated_month_name
|
356
356
|
assert_equal 'Jan', @backend.localize('de-DE', @morning, '%b')
|
357
357
|
end
|
358
|
-
|
358
|
+
|
359
359
|
def test_translate_given_a_meridian_indicator_format_it_returns_the_correct_meridian_indicator
|
360
360
|
assert_equal 'am', @backend.localize('de-DE', @morning, '%p')
|
361
361
|
assert_equal 'pm', @backend.localize('de-DE', @evening, '%p')
|
362
362
|
end
|
363
|
-
|
363
|
+
|
364
364
|
def test_translate_given_no_format_it_does_not_fail
|
365
365
|
assert_nothing_raised{ @backend.localize 'de-DE', @morning }
|
366
366
|
end
|
367
|
-
|
367
|
+
|
368
368
|
def test_translate_given_an_unknown_format_it_does_not_fail
|
369
369
|
assert_nothing_raised{ @backend.localize 'de-DE', @morning, '%x' }
|
370
|
-
end
|
370
|
+
end
|
371
371
|
end
|
372
372
|
|
373
373
|
class I18nSimpleBackendLocalizeTimeTest < Test::Unit::TestCase
|
374
374
|
include I18nSimpleBackendTestSetup
|
375
|
-
|
375
|
+
|
376
376
|
def setup
|
377
377
|
@old_timezone, ENV['TZ'] = ENV['TZ'], 'UTC'
|
378
378
|
@backend = I18n::Backend::Simple.new
|
@@ -380,49 +380,49 @@ class I18nSimpleBackendLocalizeTimeTest < Test::Unit::TestCase
|
|
380
380
|
@morning = Time.parse '2008-01-01 6:00 UTC'
|
381
381
|
@evening = Time.parse '2008-01-01 18:00 UTC'
|
382
382
|
end
|
383
|
-
|
383
|
+
|
384
384
|
def teardown
|
385
385
|
@old_timezone ? ENV['TZ'] = @old_timezone : ENV.delete('TZ')
|
386
386
|
end
|
387
|
-
|
387
|
+
|
388
388
|
def test_translate_given_the_short_format_it_uses_it
|
389
389
|
assert_equal '01. Jan 06:00', @backend.localize('de-DE', @morning, :short)
|
390
390
|
end
|
391
|
-
|
391
|
+
|
392
392
|
def test_translate_given_the_long_format_it_uses_it
|
393
393
|
assert_equal '01. Januar 2008 06:00', @backend.localize('de-DE', @morning, :long)
|
394
394
|
end
|
395
|
-
|
395
|
+
|
396
396
|
# TODO Seems to break on Windows because ENV['TZ'] is ignored. What's a better way to do this?
|
397
397
|
# def test_translate_given_the_default_format_it_uses_it
|
398
398
|
# assert_equal 'Di, 01. Jan 2008 06:00:00 +0000', @backend.localize('de-DE', @morning, :default)
|
399
399
|
# end
|
400
|
-
|
400
|
+
|
401
401
|
def test_translate_given_a_day_name_format_it_returns_the_correct_day_name
|
402
402
|
assert_equal 'Dienstag', @backend.localize('de-DE', @morning, '%A')
|
403
403
|
end
|
404
|
-
|
404
|
+
|
405
405
|
def test_translate_given_an_abbr_day_name_format_it_returns_the_correct_abbrevated_day_name
|
406
406
|
assert_equal 'Di', @backend.localize('de-DE', @morning, '%a')
|
407
407
|
end
|
408
|
-
|
408
|
+
|
409
409
|
def test_translate_given_a_month_name_format_it_returns_the_correct_month_name
|
410
410
|
assert_equal 'Januar', @backend.localize('de-DE', @morning, '%B')
|
411
411
|
end
|
412
|
-
|
412
|
+
|
413
413
|
def test_translate_given_an_abbr_month_name_format_it_returns_the_correct_abbrevated_month_name
|
414
414
|
assert_equal 'Jan', @backend.localize('de-DE', @morning, '%b')
|
415
415
|
end
|
416
|
-
|
416
|
+
|
417
417
|
def test_translate_given_a_meridian_indicator_format_it_returns_the_correct_meridian_indicator
|
418
418
|
assert_equal 'am', @backend.localize('de-DE', @morning, '%p')
|
419
419
|
assert_equal 'pm', @backend.localize('de-DE', @evening, '%p')
|
420
420
|
end
|
421
|
-
|
421
|
+
|
422
422
|
def test_translate_given_no_format_it_does_not_fail
|
423
423
|
assert_nothing_raised{ @backend.localize 'de-DE', @morning }
|
424
424
|
end
|
425
|
-
|
425
|
+
|
426
426
|
def test_translate_given_an_unknown_format_it_does_not_fail
|
427
427
|
assert_nothing_raised{ @backend.localize 'de-DE', @morning, '%x' }
|
428
428
|
end
|
@@ -432,7 +432,7 @@ class I18nSimpleBackendHelperMethodsTest < Test::Unit::TestCase
|
|
432
432
|
def setup
|
433
433
|
@backend = I18n::Backend::Simple.new
|
434
434
|
end
|
435
|
-
|
435
|
+
|
436
436
|
def test_deep_symbolize_keys_works
|
437
437
|
result = @backend.send :deep_symbolize_keys, 'foo' => {'bar' => {'baz' => 'bar'}}
|
438
438
|
expected = {:foo => {:bar => {:baz => 'bar'}}}
|
@@ -460,7 +460,7 @@ class I18nSimpleBackendLoadTranslationsTest < Test::Unit::TestCase
|
|
460
460
|
data = @backend.send :load_yml, "#{@locale_dir}/en-US.yml"
|
461
461
|
assert_equal({'en-US-Yaml' => {'foo' => {'bar' => 'baz'}}}, data)
|
462
462
|
end
|
463
|
-
|
463
|
+
|
464
464
|
def test_load_translations_loads_from_different_file_formats
|
465
465
|
@backend = I18n::Backend::Simple.new
|
466
466
|
@backend.load_translations "#{@locale_dir}/en-US.rb", "#{@locale_dir}/en-US.yml"
|
@@ -470,4 +470,33 @@ class I18nSimpleBackendLoadTranslationsTest < Test::Unit::TestCase
|
|
470
470
|
}
|
471
471
|
assert_equal expected, backend_get_translations
|
472
472
|
end
|
473
|
+
end
|
474
|
+
|
475
|
+
class I18nSimpleBackendReloadTranslationsTest < Test::Unit::TestCase
|
476
|
+
include I18nSimpleBackendTestSetup
|
477
|
+
|
478
|
+
def setup
|
479
|
+
@backend = I18n::Backend::Simple.new
|
480
|
+
I18n.load_path = [File.dirname(__FILE__) + '/locale/en-US.yml']
|
481
|
+
assert_nil backend_get_translations
|
482
|
+
@backend.send :init_translations
|
483
|
+
end
|
484
|
+
|
485
|
+
def teardown
|
486
|
+
I18n.load_path = []
|
487
|
+
end
|
488
|
+
|
489
|
+
def test_setup
|
490
|
+
assert_not_nil backend_get_translations
|
491
|
+
end
|
492
|
+
|
493
|
+
def test_reload_translations_unloads_translations
|
494
|
+
@backend.reload!
|
495
|
+
assert_nil backend_get_translations
|
496
|
+
end
|
497
|
+
|
498
|
+
def test_reload_translations_uninitializes_translations
|
499
|
+
@backend.reload!
|
500
|
+
assert_equal @backend.initialized?, false
|
501
|
+
end
|
473
502
|
end
|