i18n 0.9.5 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +54 -13
- data/lib/i18n/backend/base.rb +46 -17
- data/lib/i18n/backend/cache.rb +8 -9
- data/lib/i18n/backend/cache_file.rb +36 -0
- data/lib/i18n/backend/cascade.rb +3 -1
- data/lib/i18n/backend/chain.rb +33 -3
- data/lib/i18n/backend/fallbacks.rb +11 -13
- data/lib/i18n/backend/flatten.rb +2 -0
- data/lib/i18n/backend/gettext.rb +4 -0
- data/lib/i18n/backend/interpolation_compiler.rb +3 -1
- data/lib/i18n/backend/key_value.rb +31 -2
- data/lib/i18n/backend/memoize.rb +10 -2
- data/lib/i18n/backend/metadata.rb +5 -3
- data/lib/i18n/backend/pluralization.rb +2 -0
- data/lib/i18n/backend/simple.rb +26 -8
- data/lib/i18n/backend/transliterator.rb +2 -0
- data/lib/i18n/backend.rb +3 -0
- data/lib/i18n/config.rb +20 -2
- data/lib/i18n/core_ext/hash.rb +42 -24
- data/lib/i18n/exceptions.rb +23 -16
- data/lib/i18n/gettext/helpers.rb +3 -1
- data/lib/i18n/gettext/po_parser.rb +7 -7
- data/lib/i18n/gettext.rb +2 -0
- data/lib/i18n/interpolate/ruby.rb +5 -3
- data/lib/i18n/locale/fallbacks.rb +1 -1
- data/lib/i18n/locale.rb +2 -0
- data/lib/i18n/middleware.rb +2 -0
- data/lib/i18n/tests/interpolation.rb +5 -4
- data/lib/i18n/tests/localization/date.rb +28 -6
- data/lib/i18n/tests/localization/date_time.rb +27 -6
- data/lib/i18n/tests/localization/time.rb +26 -4
- data/lib/i18n/tests.rb +2 -0
- data/lib/i18n/version.rb +3 -1
- data/lib/i18n.rb +72 -30
- metadata +24 -58
- data/gemfiles/Gemfile.rails-3.2.x +0 -10
- data/gemfiles/Gemfile.rails-4.0.x +0 -10
- data/gemfiles/Gemfile.rails-4.1.x +0 -10
- data/gemfiles/Gemfile.rails-4.2.x +0 -10
- data/gemfiles/Gemfile.rails-5.0.x +0 -10
- data/gemfiles/Gemfile.rails-5.1.x +0 -10
- data/gemfiles/Gemfile.rails-master +0 -10
- data/lib/i18n/core_ext/kernel/suppress_warnings.rb +0 -8
- data/lib/i18n/core_ext/string/interpolate.rb +0 -9
- data/test/api/all_features_test.rb +0 -58
- data/test/api/cascade_test.rb +0 -28
- data/test/api/chain_test.rb +0 -24
- data/test/api/fallbacks_test.rb +0 -30
- data/test/api/key_value_test.rb +0 -24
- data/test/api/memoize_test.rb +0 -56
- data/test/api/override_test.rb +0 -42
- data/test/api/pluralization_test.rb +0 -30
- data/test/api/simple_test.rb +0 -28
- data/test/backend/cache_test.rb +0 -109
- data/test/backend/cascade_test.rb +0 -86
- data/test/backend/chain_test.rb +0 -122
- data/test/backend/exceptions_test.rb +0 -36
- data/test/backend/fallbacks_test.rb +0 -219
- data/test/backend/interpolation_compiler_test.rb +0 -118
- data/test/backend/key_value_test.rb +0 -61
- data/test/backend/memoize_test.rb +0 -79
- data/test/backend/metadata_test.rb +0 -48
- data/test/backend/pluralization_test.rb +0 -45
- data/test/backend/simple_test.rb +0 -103
- data/test/backend/transliterator_test.rb +0 -84
- data/test/core_ext/hash_test.rb +0 -36
- data/test/gettext/api_test.rb +0 -214
- data/test/gettext/backend_test.rb +0 -92
- data/test/i18n/exceptions_test.rb +0 -117
- data/test/i18n/gettext_plural_keys_test.rb +0 -20
- data/test/i18n/interpolate_test.rb +0 -91
- data/test/i18n/load_path_test.rb +0 -34
- data/test/i18n/middleware_test.rb +0 -24
- data/test/i18n_test.rb +0 -462
- data/test/locale/fallbacks_test.rb +0 -133
- data/test/locale/tag/rfc4646_test.rb +0 -143
- data/test/locale/tag/simple_test.rb +0 -32
- data/test/run_all.rb +0 -20
- data/test/test_data/locales/de.po +0 -82
- data/test/test_data/locales/en.rb +0 -3
- data/test/test_data/locales/en.yml +0 -3
- data/test/test_data/locales/invalid/empty.yml +0 -0
- data/test/test_data/locales/invalid/syntax.yml +0 -4
- data/test/test_data/locales/plurals.rb +0 -113
- data/test/test_helper.rb +0 -61
data/test/i18n_test.rb
DELETED
@@ -1,462 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'test_helper'
|
3
|
-
|
4
|
-
class I18nTest < I18n::TestCase
|
5
|
-
def setup
|
6
|
-
super
|
7
|
-
store_translations(:en, :currency => { :format => { :separator => '.', :delimiter => ',', } })
|
8
|
-
store_translations(:nl, :currency => { :format => { :separator => ',', :delimiter => '.', } })
|
9
|
-
store_translations(:en, "true" => "Yes", "false" => "No")
|
10
|
-
end
|
11
|
-
|
12
|
-
test "exposes its VERSION constant" do
|
13
|
-
assert I18n::VERSION
|
14
|
-
end
|
15
|
-
|
16
|
-
test "uses the simple backend by default" do
|
17
|
-
assert I18n.backend.is_a?(I18n::Backend::Simple)
|
18
|
-
end
|
19
|
-
|
20
|
-
test "can set the backend" do
|
21
|
-
begin
|
22
|
-
assert_nothing_raised { I18n.backend = self }
|
23
|
-
assert_equal self, I18n.backend
|
24
|
-
ensure
|
25
|
-
I18n.backend = I18n::Backend::Simple.new
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
test "uses :en as a default_locale by default" do
|
30
|
-
assert_equal :en, I18n.default_locale
|
31
|
-
end
|
32
|
-
|
33
|
-
test "can set the default locale" do
|
34
|
-
begin
|
35
|
-
assert_nothing_raised { I18n.default_locale = 'de' }
|
36
|
-
assert_equal :de, I18n.default_locale
|
37
|
-
ensure
|
38
|
-
I18n.default_locale = :en
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
test "default_locale= doesn't ignore junk" do
|
43
|
-
assert_raise(NoMethodError) { I18n.default_locale = Class }
|
44
|
-
end
|
45
|
-
|
46
|
-
test "raises an I18n::InvalidLocale exception when setting an unavailable default locale" do
|
47
|
-
begin
|
48
|
-
I18n.config.enforce_available_locales = true
|
49
|
-
assert_raise(I18n::InvalidLocale) { I18n.default_locale = :klingon }
|
50
|
-
ensure
|
51
|
-
I18n.config.enforce_available_locales = false
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
test "uses the default locale as a locale by default" do
|
56
|
-
assert_equal I18n.default_locale, I18n.locale
|
57
|
-
end
|
58
|
-
|
59
|
-
test "sets the current locale to Thread.current" do
|
60
|
-
assert_nothing_raised { I18n.locale = 'de' }
|
61
|
-
assert_equal :de, I18n.locale
|
62
|
-
assert_equal :de, Thread.current[:i18n_config].locale
|
63
|
-
I18n.locale = :en
|
64
|
-
end
|
65
|
-
|
66
|
-
test "locale= doesn't ignore junk" do
|
67
|
-
assert_raise(NoMethodError) { I18n.locale = Class }
|
68
|
-
end
|
69
|
-
|
70
|
-
test "raises an I18n::InvalidLocale exception when setting an unavailable locale" do
|
71
|
-
begin
|
72
|
-
I18n.config.enforce_available_locales = true
|
73
|
-
assert_raise(I18n::InvalidLocale) { I18n.locale = :klingon }
|
74
|
-
ensure
|
75
|
-
I18n.config.enforce_available_locales = false
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
test "can set the configuration object" do
|
80
|
-
begin
|
81
|
-
I18n.config = self
|
82
|
-
assert_equal self, I18n.config
|
83
|
-
assert_equal self, Thread.current[:i18n_config]
|
84
|
-
ensure
|
85
|
-
I18n.config = ::I18n::Config.new
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
test "locale is not shared between configurations" do
|
90
|
-
a = I18n::Config.new
|
91
|
-
b = I18n::Config.new
|
92
|
-
a.locale = :fr
|
93
|
-
b.locale = :es
|
94
|
-
assert_equal :fr, a.locale
|
95
|
-
assert_equal :es, b.locale
|
96
|
-
assert_equal :en, I18n.locale
|
97
|
-
end
|
98
|
-
|
99
|
-
test "other options are shared between configurations" do
|
100
|
-
begin
|
101
|
-
a = I18n::Config.new
|
102
|
-
b = I18n::Config.new
|
103
|
-
a.default_locale = :fr
|
104
|
-
b.default_locale = :es
|
105
|
-
assert_equal :es, a.default_locale
|
106
|
-
assert_equal :es, b.default_locale
|
107
|
-
assert_equal :es, I18n.default_locale
|
108
|
-
ensure
|
109
|
-
I18n.default_locale = :en
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
test "uses a dot as a default_separator by default" do
|
114
|
-
assert_equal '.', I18n.default_separator
|
115
|
-
end
|
116
|
-
|
117
|
-
test "can set the default_separator" do
|
118
|
-
begin
|
119
|
-
assert_nothing_raised { I18n.default_separator = "\001" }
|
120
|
-
ensure
|
121
|
-
I18n.default_separator = '.'
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
test "normalize_keys normalizes given locale, keys and scope to an array of single-key symbols" do
|
126
|
-
assert_equal [:en, :foo, :bar], I18n.normalize_keys(:en, :bar, :foo)
|
127
|
-
assert_equal [:en, :foo, :bar, :baz, :buz], I18n.normalize_keys(:en, :'baz.buz', :'foo.bar')
|
128
|
-
assert_equal [:en, :foo, :bar, :baz, :buz], I18n.normalize_keys(:en, 'baz.buz', 'foo.bar')
|
129
|
-
assert_equal [:en, :foo, :bar, :baz, :buz], I18n.normalize_keys(:en, %w(baz buz), %w(foo bar))
|
130
|
-
assert_equal [:en, :foo, :bar, :baz, :buz], I18n.normalize_keys(:en, [:baz, :buz], [:foo, :bar])
|
131
|
-
end
|
132
|
-
|
133
|
-
test "normalize_keys discards empty keys" do
|
134
|
-
assert_equal [:en, :foo, :bar, :baz, :buz], I18n.normalize_keys(:en, :'baz..buz', :'foo..bar')
|
135
|
-
assert_equal [:en, :foo, :bar, :baz, :buz], I18n.normalize_keys(:en, :'baz......buz', :'foo......bar')
|
136
|
-
assert_equal [:en, :foo, :bar, :baz, :buz], I18n.normalize_keys(:en, ['baz', nil, '', 'buz'], ['foo', nil, '', 'bar'])
|
137
|
-
end
|
138
|
-
|
139
|
-
test "normalize_keys uses a given separator" do
|
140
|
-
assert_equal [:en, :foo, :bar, :baz, :buz], I18n.normalize_keys(:en, :'baz|buz', :'foo|bar', '|')
|
141
|
-
end
|
142
|
-
|
143
|
-
test "can set the exception_handler" do
|
144
|
-
begin
|
145
|
-
previous_exception_handler = I18n.exception_handler
|
146
|
-
assert_nothing_raised { I18n.exception_handler = :custom_exception_handler }
|
147
|
-
ensure
|
148
|
-
I18n.exception_handler = previous_exception_handler
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
test "uses a custom exception handler set to I18n.exception_handler" do
|
153
|
-
begin
|
154
|
-
previous_exception_handler = I18n.exception_handler
|
155
|
-
I18n.exception_handler = :custom_exception_handler
|
156
|
-
I18n.expects(:custom_exception_handler)
|
157
|
-
I18n.translate :bogus
|
158
|
-
ensure
|
159
|
-
I18n.exception_handler = previous_exception_handler
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
test "uses a custom exception handler passed as an option" do
|
164
|
-
I18n.expects(:custom_exception_handler)
|
165
|
-
I18n.translate(:bogus, :exception_handler => :custom_exception_handler)
|
166
|
-
end
|
167
|
-
|
168
|
-
test "delegates translate calls to the backend" do
|
169
|
-
I18n.backend.expects(:translate).with('de', :foo, {})
|
170
|
-
I18n.translate :foo, :locale => 'de'
|
171
|
-
end
|
172
|
-
|
173
|
-
test "delegates localize calls to the backend" do
|
174
|
-
I18n.backend.expects(:localize).with('de', :whatever, :default, {})
|
175
|
-
I18n.localize :whatever, :locale => 'de'
|
176
|
-
end
|
177
|
-
|
178
|
-
test "translate given no locale uses the current locale" do
|
179
|
-
I18n.backend.expects(:translate).with(:en, :foo, {})
|
180
|
-
I18n.translate :foo
|
181
|
-
end
|
182
|
-
|
183
|
-
test "translate works with nested symbol keys" do
|
184
|
-
assert_equal ".", I18n.t(:'currency.format.separator')
|
185
|
-
end
|
186
|
-
|
187
|
-
test "translate works with nested string keys" do
|
188
|
-
assert_equal ".", I18n.t('currency.format.separator')
|
189
|
-
end
|
190
|
-
|
191
|
-
test "translate with an array as a scope works" do
|
192
|
-
assert_equal ".", I18n.t(:separator, :scope => %w(currency format))
|
193
|
-
end
|
194
|
-
|
195
|
-
test "translate with an array containing dot separated strings as a scope works" do
|
196
|
-
assert_equal ".", I18n.t(:separator, :scope => ['currency.format'])
|
197
|
-
end
|
198
|
-
|
199
|
-
test "translate with an array of keys and a dot separated string as a scope works" do
|
200
|
-
assert_equal [".", ","], I18n.t(%w(separator delimiter), :scope => 'currency.format')
|
201
|
-
end
|
202
|
-
|
203
|
-
test "translate with an array of dot separated keys and a scope works" do
|
204
|
-
assert_equal [".", ","], I18n.t(%w(format.separator format.delimiter), :scope => 'currency')
|
205
|
-
end
|
206
|
-
|
207
|
-
# def test_translate_given_no_args_raises_missing_translation_data
|
208
|
-
# assert_equal "translation missing: en, no key", I18n.t
|
209
|
-
# end
|
210
|
-
|
211
|
-
test "translate given a bogus key returns an error message" do
|
212
|
-
assert_equal "translation missing: en.bogus", I18n.t(:bogus)
|
213
|
-
end
|
214
|
-
|
215
|
-
test "translate given an empty string as a key raises an I18n::ArgumentError" do
|
216
|
-
assert_raise(I18n::ArgumentError) { I18n.t("") }
|
217
|
-
end
|
218
|
-
|
219
|
-
test "translate given an empty symbol as a key raises an I18n::ArgumentError" do
|
220
|
-
assert_raise(I18n::ArgumentError) { I18n.t(:"") }
|
221
|
-
end
|
222
|
-
|
223
|
-
test "translate given an array with empty string as a key raises an I18n::ArgumentError" do
|
224
|
-
assert_raise(I18n::ArgumentError) { I18n.t(["", :foo]) }
|
225
|
-
end
|
226
|
-
|
227
|
-
test "translate given an empty array as a key returns empty array" do
|
228
|
-
assert_equal [], I18n.t([])
|
229
|
-
end
|
230
|
-
|
231
|
-
test "translate given nil returns nil" do
|
232
|
-
assert_nil I18n.t(nil)
|
233
|
-
end
|
234
|
-
|
235
|
-
test "translate given an unavailable locale rases an I18n::InvalidLocale" do
|
236
|
-
begin
|
237
|
-
I18n.config.enforce_available_locales = true
|
238
|
-
assert_raise(I18n::InvalidLocale) { I18n.t(:foo, :locale => 'klingon') }
|
239
|
-
ensure
|
240
|
-
I18n.config.enforce_available_locales = false
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
test "translate given true as a key works" do
|
245
|
-
assert_equal "Yes", I18n.t(true)
|
246
|
-
end
|
247
|
-
|
248
|
-
test "translate given false as a key works" do
|
249
|
-
assert_equal "No", I18n.t(false)
|
250
|
-
end
|
251
|
-
|
252
|
-
test "available_locales can be replaced at runtime" do
|
253
|
-
begin
|
254
|
-
I18n.config.enforce_available_locales = true
|
255
|
-
assert_raise(I18n::InvalidLocale) { I18n.t(:foo, :locale => 'klingon') }
|
256
|
-
old_locales, I18n.config.available_locales = I18n.config.available_locales, [:klingon]
|
257
|
-
I18n.t(:foo, :locale => 'klingon')
|
258
|
-
ensure
|
259
|
-
I18n.config.enforce_available_locales = false
|
260
|
-
I18n.config.available_locales = old_locales
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
test "available_locales_set should return a set" do
|
265
|
-
assert_equal Set, I18n.config.available_locales_set.class
|
266
|
-
assert_equal I18n.config.available_locales.size * 2, I18n.config.available_locales_set.size
|
267
|
-
end
|
268
|
-
|
269
|
-
test "exists? given an existing key will return true" do
|
270
|
-
assert_equal true, I18n.exists?(:currency)
|
271
|
-
end
|
272
|
-
|
273
|
-
test "exists? given a non-existing key will return false" do
|
274
|
-
assert_equal false, I18n.exists?(:bogus)
|
275
|
-
end
|
276
|
-
|
277
|
-
test "exists? given an existing dot-separated key will return true" do
|
278
|
-
assert_equal true, I18n.exists?('currency.format.delimiter')
|
279
|
-
end
|
280
|
-
|
281
|
-
test "exists? given a non-existing dot-separated key will return false" do
|
282
|
-
assert_equal false, I18n.exists?('currency.format.bogus')
|
283
|
-
end
|
284
|
-
|
285
|
-
test "exists? given an existing key and an existing locale will return true" do
|
286
|
-
assert_equal true, I18n.exists?(:currency, :nl)
|
287
|
-
end
|
288
|
-
|
289
|
-
test "exists? given a non-existing key and an existing locale will return false" do
|
290
|
-
assert_equal false, I18n.exists?(:bogus, :nl)
|
291
|
-
end
|
292
|
-
|
293
|
-
test "localize given nil raises an I18n::ArgumentError" do
|
294
|
-
assert_raise(I18n::ArgumentError) { I18n.l nil }
|
295
|
-
end
|
296
|
-
|
297
|
-
test "localize given nil and default returns default" do
|
298
|
-
assert_nil I18n.l(nil, :default => nil)
|
299
|
-
end
|
300
|
-
|
301
|
-
test "localize given an Object raises an I18n::ArgumentError" do
|
302
|
-
assert_raise(I18n::ArgumentError) { I18n.l Object.new }
|
303
|
-
end
|
304
|
-
|
305
|
-
test "localize given an unavailable locale rases an I18n::InvalidLocale" do
|
306
|
-
begin
|
307
|
-
I18n.config.enforce_available_locales = true
|
308
|
-
assert_raise(I18n::InvalidLocale) { I18n.l(Time.now, :locale => 'klingon') }
|
309
|
-
ensure
|
310
|
-
I18n.config.enforce_available_locales = false
|
311
|
-
end
|
312
|
-
end
|
313
|
-
|
314
|
-
test "can use a lambda as an exception handler" do
|
315
|
-
begin
|
316
|
-
previous_exception_handler = I18n.exception_handler
|
317
|
-
I18n.exception_handler = Proc.new { |exception, locale, key, options| key }
|
318
|
-
assert_equal :test_proc_handler, I18n.translate(:test_proc_handler)
|
319
|
-
ensure
|
320
|
-
I18n.exception_handler = previous_exception_handler
|
321
|
-
end
|
322
|
-
end
|
323
|
-
|
324
|
-
test "can use an object responding to #call as an exception handler" do
|
325
|
-
begin
|
326
|
-
previous_exception_handler = I18n.exception_handler
|
327
|
-
I18n.exception_handler = Class.new do
|
328
|
-
def call(exception, locale, key, options); key; end
|
329
|
-
end.new
|
330
|
-
assert_equal :test_proc_handler, I18n.translate(:test_proc_handler)
|
331
|
-
ensure
|
332
|
-
I18n.exception_handler = previous_exception_handler
|
333
|
-
end
|
334
|
-
end
|
335
|
-
|
336
|
-
test "I18n.with_locale temporarily sets the given locale" do
|
337
|
-
store_translations(:en, :foo => 'Foo in :en')
|
338
|
-
store_translations(:de, :foo => 'Foo in :de')
|
339
|
-
store_translations(:pl, :foo => 'Foo in :pl')
|
340
|
-
|
341
|
-
I18n.with_locale { assert_equal [:en, 'Foo in :en'], [I18n.locale, I18n.t(:foo)] }
|
342
|
-
I18n.with_locale(:de) { assert_equal [:de, 'Foo in :de'], [I18n.locale, I18n.t(:foo)] }
|
343
|
-
I18n.with_locale(:pl) { assert_equal [:pl, 'Foo in :pl'], [I18n.locale, I18n.t(:foo)] }
|
344
|
-
I18n.with_locale(:en) { assert_equal [:en, 'Foo in :en'], [I18n.locale, I18n.t(:foo)] }
|
345
|
-
|
346
|
-
assert_equal I18n.default_locale, I18n.locale
|
347
|
-
end
|
348
|
-
|
349
|
-
test "I18n.with_locale resets the locale in case of errors" do
|
350
|
-
assert_raise(I18n::ArgumentError) { I18n.with_locale(:pl) { raise I18n::ArgumentError } }
|
351
|
-
assert_equal I18n.default_locale, I18n.locale
|
352
|
-
end
|
353
|
-
|
354
|
-
test "I18n.translitarate handles I18n::ArgumentError exception" do
|
355
|
-
I18n::Backend::Transliterator.stubs(:get).raises(I18n::ArgumentError)
|
356
|
-
I18n.exception_handler.expects(:call).raises(I18n::ArgumentError)
|
357
|
-
assert_raise(I18n::ArgumentError) {
|
358
|
-
I18n.transliterate("ąćó")
|
359
|
-
}
|
360
|
-
end
|
361
|
-
|
362
|
-
test "I18n.translitarate raises I18n::ArgumentError exception" do
|
363
|
-
I18n::Backend::Transliterator.stubs(:get).raises(I18n::ArgumentError)
|
364
|
-
I18n.exception_handler.expects(:call).never
|
365
|
-
assert_raise(I18n::ArgumentError) {
|
366
|
-
I18n.transliterate("ąćó", :raise => true)
|
367
|
-
}
|
368
|
-
end
|
369
|
-
|
370
|
-
test "transliterate given an unavailable locale rases an I18n::InvalidLocale" do
|
371
|
-
begin
|
372
|
-
I18n.config.enforce_available_locales = true
|
373
|
-
assert_raise(I18n::InvalidLocale) { I18n.transliterate('string', :locale => 'klingon') }
|
374
|
-
ensure
|
375
|
-
I18n.config.enforce_available_locales = false
|
376
|
-
end
|
377
|
-
end
|
378
|
-
|
379
|
-
test "transliterate non-ASCII chars not in map with default replacement char" do
|
380
|
-
assert_equal "???", I18n.transliterate("日本語")
|
381
|
-
end
|
382
|
-
|
383
|
-
test "I18n.locale_available? returns true when the passed locale is available" do
|
384
|
-
I18n.available_locales = [:en, :de]
|
385
|
-
assert_equal true, I18n.locale_available?(:de)
|
386
|
-
end
|
387
|
-
|
388
|
-
test "I18n.locale_available? returns true when the passed locale is a string and is available" do
|
389
|
-
I18n.available_locales = [:en, :de]
|
390
|
-
assert_equal true, I18n.locale_available?('de')
|
391
|
-
end
|
392
|
-
|
393
|
-
test "I18n.locale_available? returns false when the passed locale is unavailable" do
|
394
|
-
assert_equal false, I18n.locale_available?(:klingon)
|
395
|
-
end
|
396
|
-
|
397
|
-
test "I18n.enforce_available_locales! raises an I18n::InvalidLocale when the passed locale is unavailable" do
|
398
|
-
begin
|
399
|
-
I18n.config.enforce_available_locales = true
|
400
|
-
assert_raise(I18n::InvalidLocale) { I18n.enforce_available_locales!(:klingon) }
|
401
|
-
ensure
|
402
|
-
I18n.config.enforce_available_locales = false
|
403
|
-
end
|
404
|
-
end
|
405
|
-
|
406
|
-
test "I18n.enforce_available_locales! does nothing when the passed locale is available" do
|
407
|
-
I18n.available_locales = [:en, :de]
|
408
|
-
begin
|
409
|
-
I18n.config.enforce_available_locales = true
|
410
|
-
assert_nothing_raised { I18n.enforce_available_locales!(:en) }
|
411
|
-
ensure
|
412
|
-
I18n.config.enforce_available_locales = false
|
413
|
-
end
|
414
|
-
end
|
415
|
-
|
416
|
-
test "I18n.enforce_available_locales config can be set to false" do
|
417
|
-
begin
|
418
|
-
I18n.config.enforce_available_locales = false
|
419
|
-
assert_equal false, I18n.config.enforce_available_locales
|
420
|
-
ensure
|
421
|
-
I18n.config.enforce_available_locales = false
|
422
|
-
end
|
423
|
-
end
|
424
|
-
|
425
|
-
test 'I18n.reload! reloads the set of locales that are enforced' do
|
426
|
-
begin
|
427
|
-
# Clear the backend that affects the available locales and somehow can remain
|
428
|
-
# set from the last running test.
|
429
|
-
# For instance, it contains enough translations to cause a false positive with
|
430
|
-
# this test when ran with --seed=50992
|
431
|
-
I18n.backend = I18n::Backend::Simple.new
|
432
|
-
|
433
|
-
assert !I18n.available_locales.include?(:de), "Available locales should not include :de at this point"
|
434
|
-
|
435
|
-
I18n.enforce_available_locales = true
|
436
|
-
|
437
|
-
assert_raise(I18n::InvalidLocale) { I18n.default_locale = :de }
|
438
|
-
assert_raise(I18n::InvalidLocale) { I18n.locale = :de }
|
439
|
-
|
440
|
-
store_translations(:de, :foo => 'Foo in :de')
|
441
|
-
|
442
|
-
assert_raise(I18n::InvalidLocale) { I18n.default_locale = :de }
|
443
|
-
assert_raise(I18n::InvalidLocale) { I18n.locale = :de }
|
444
|
-
|
445
|
-
I18n.reload!
|
446
|
-
|
447
|
-
store_translations(:en, :foo => 'Foo in :en')
|
448
|
-
store_translations(:de, :foo => 'Foo in :de')
|
449
|
-
store_translations(:pl, :foo => 'Foo in :pl')
|
450
|
-
|
451
|
-
assert I18n.available_locales.include?(:de), ":de should now be allowed"
|
452
|
-
assert I18n.available_locales.include?(:en), ":en should now be allowed"
|
453
|
-
assert I18n.available_locales.include?(:pl), ":pl should now be allowed"
|
454
|
-
|
455
|
-
assert_nothing_raised { I18n.default_locale = I18n.locale = :en }
|
456
|
-
assert_nothing_raised { I18n.default_locale = I18n.locale = :de }
|
457
|
-
assert_nothing_raised { I18n.default_locale = I18n.locale = :pl }
|
458
|
-
ensure
|
459
|
-
I18n.enforce_available_locales = false
|
460
|
-
end
|
461
|
-
end
|
462
|
-
end
|
@@ -1,133 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
include I18n::Locale
|
4
|
-
|
5
|
-
class I18nFallbacksDefaultsTest < I18n::TestCase
|
6
|
-
test "defaults reflect the I18n.default_locale if no default has been set manually" do
|
7
|
-
I18n.default_locale = :'en-US'
|
8
|
-
fallbacks = Fallbacks.new
|
9
|
-
assert_equal [:'en-US', :en], fallbacks.defaults
|
10
|
-
end
|
11
|
-
|
12
|
-
test "defaults reflect a manually passed default locale if any" do
|
13
|
-
fallbacks = Fallbacks.new(:'fi-FI')
|
14
|
-
assert_equal [:'fi-FI', :fi], fallbacks.defaults
|
15
|
-
I18n.default_locale = :'de-DE'
|
16
|
-
assert_equal [:'fi-FI', :fi], fallbacks.defaults
|
17
|
-
end
|
18
|
-
|
19
|
-
test "defaults allows to set multiple defaults" do
|
20
|
-
fallbacks = Fallbacks.new(:'fi-FI', :'se-FI')
|
21
|
-
assert_equal [:'fi-FI', :fi, :'se-FI', :se], fallbacks.defaults
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class I18nFallbacksComputationTest < I18n::TestCase
|
26
|
-
def setup
|
27
|
-
super
|
28
|
-
@fallbacks = Fallbacks.new(:'en-US')
|
29
|
-
end
|
30
|
-
|
31
|
-
test "with no mappings defined it returns [:es, :en-US] for :es" do
|
32
|
-
assert_equal [:es, :"en-US", :en], @fallbacks[:es]
|
33
|
-
end
|
34
|
-
|
35
|
-
test "with no mappings defined it returns [:es-ES, :es, :en-US] for :es-ES" do
|
36
|
-
assert_equal [:"es-ES", :es, :"en-US", :en], @fallbacks[:"es-ES"]
|
37
|
-
end
|
38
|
-
|
39
|
-
test "with no mappings defined it returns [:es-MX, :es, :en-US] for :es-MX" do
|
40
|
-
assert_equal [:"es-MX", :es, :"en-US", :en], @fallbacks[:"es-MX"]
|
41
|
-
end
|
42
|
-
|
43
|
-
test "with no mappings defined it returns [:es-Latn-ES, :es-Latn, :es, :en-US] for :es-Latn-ES" do
|
44
|
-
assert_equal [:"es-Latn-ES", :"es-Latn", :es, :"en-US", :en], @fallbacks[:'es-Latn-ES']
|
45
|
-
end
|
46
|
-
|
47
|
-
test "with no mappings defined it returns [:en, :en-US] for :en" do
|
48
|
-
assert_equal [:en, :"en-US"], @fallbacks[:en]
|
49
|
-
end
|
50
|
-
|
51
|
-
test "with no mappings defined it returns [:en-US, :en] for :en-US (special case: locale == default)" do
|
52
|
-
assert_equal [:"en-US", :en], @fallbacks[:"en-US"]
|
53
|
-
end
|
54
|
-
|
55
|
-
# Most people who speak Catalan also live in Spain, so it is safe to assume
|
56
|
-
# that they also speak Spanish as spoken in Spain.
|
57
|
-
test "with a Catalan mapping defined it returns [:ca, :es-ES, :es, :en-US] for :ca" do
|
58
|
-
@fallbacks.map(:ca => :"es-ES")
|
59
|
-
assert_equal [:ca, :"es-ES", :es, :"en-US", :en], @fallbacks[:ca]
|
60
|
-
end
|
61
|
-
|
62
|
-
test "with a Catalan mapping defined it returns [:ca-ES, :ca, :es-ES, :es, :en-US] for :ca-ES" do
|
63
|
-
@fallbacks.map(:ca => :"es-ES")
|
64
|
-
assert_equal [:"ca-ES", :ca, :"es-ES", :es, :"en-US", :en], @fallbacks[:"ca-ES"]
|
65
|
-
end
|
66
|
-
|
67
|
-
# People who speak Arabic as spoken in Palestine often times also speak
|
68
|
-
# Hebrew as spoken in Israel. However it is in no way safe to assume that
|
69
|
-
# everybody who speaks Arabic also speaks Hebrew.
|
70
|
-
|
71
|
-
test "with a Hebrew mapping defined it returns [:ar, :en-US] for :ar" do
|
72
|
-
@fallbacks.map(:"ar-PS" => :"he-IL")
|
73
|
-
assert_equal [:ar, :"en-US", :en], @fallbacks[:ar]
|
74
|
-
end
|
75
|
-
|
76
|
-
test "with a Hebrew mapping defined it returns [:ar-EG, :ar, :en-US] for :ar-EG" do
|
77
|
-
@fallbacks.map(:"ar-PS" => :"he-IL")
|
78
|
-
assert_equal [:"ar-EG", :ar, :"en-US", :en], @fallbacks[:"ar-EG"]
|
79
|
-
end
|
80
|
-
|
81
|
-
test "with a Hebrew mapping defined it returns [:ar-PS, :ar, :he-IL, :he, :en-US] for :ar-PS" do
|
82
|
-
@fallbacks.map(:"ar-PS" => :"he-IL")
|
83
|
-
assert_equal [:"ar-PS", :ar, :"he-IL", :he, :"en-US", :en], @fallbacks[:"ar-PS"]
|
84
|
-
end
|
85
|
-
|
86
|
-
# Sami people live in several scandinavian countries. In Finnland many people
|
87
|
-
# know Swedish and Finnish. Thus, it can be assumed that Sami living in
|
88
|
-
# Finnland also speak Swedish and Finnish.
|
89
|
-
|
90
|
-
test "with a Sami mapping defined it returns [:sms-FI, :sms, :se-FI, :se, :fi-FI, :fi, :en-US] for :sms-FI" do
|
91
|
-
@fallbacks.map(:sms => [:"se-FI", :"fi-FI"])
|
92
|
-
assert_equal [:"sms-FI", :sms, :"se-FI", :se, :"fi-FI", :fi, :"en-US", :en], @fallbacks[:"sms-FI"]
|
93
|
-
end
|
94
|
-
|
95
|
-
# Austrian people understand German as spoken in Germany
|
96
|
-
|
97
|
-
test "with a German mapping defined it returns [:de, :en-US] for de" do
|
98
|
-
@fallbacks.map(:"de-AT" => :"de-DE")
|
99
|
-
assert_equal [:de, :"en-US", :en], @fallbacks[:"de"]
|
100
|
-
end
|
101
|
-
|
102
|
-
test "with a German mapping defined it returns [:de-DE, :de, :en-US] for de-DE" do
|
103
|
-
@fallbacks.map(:"de-AT" => :"de-DE")
|
104
|
-
assert_equal [:"de-DE", :de, :"en-US", :en], @fallbacks[:"de-DE"]
|
105
|
-
end
|
106
|
-
|
107
|
-
test "with a German mapping defined it returns [:de-AT, :de, :de-DE, :en-US] for de-AT" do
|
108
|
-
@fallbacks.map(:"de-AT" => :"de-DE")
|
109
|
-
assert_equal [:"de-AT", :de, :"de-DE", :"en-US", :en], @fallbacks[:"de-AT"]
|
110
|
-
end
|
111
|
-
|
112
|
-
# Mapping :de => :en, :he => :en
|
113
|
-
|
114
|
-
test "with a mapping :de => :en, :he => :en defined it returns [:de, :en] for :de" do
|
115
|
-
assert_equal [:de, :"en-US", :en], @fallbacks[:de]
|
116
|
-
end
|
117
|
-
|
118
|
-
test "with a mapping :de => :en, :he => :en defined it [:he, :en] for :de" do
|
119
|
-
assert_equal [:he, :"en-US", :en], @fallbacks[:he]
|
120
|
-
end
|
121
|
-
|
122
|
-
# Test allowing mappings that fallback to each other
|
123
|
-
|
124
|
-
test "with :no => :nb, :nb => :no defined :no returns [:no, :nb, :en-US, :en]" do
|
125
|
-
@fallbacks.map(:no => :nb, :nb => :no)
|
126
|
-
assert_equal [:no, :nb, :"en-US", :en], @fallbacks[:no]
|
127
|
-
end
|
128
|
-
|
129
|
-
test "with :no => :nb, :nb => :no defined :nb returns [:nb, :no, :en-US, :en]" do
|
130
|
-
@fallbacks.map(:no => :nb, :nb => :no)
|
131
|
-
assert_equal [:nb, :no, :"en-US", :en], @fallbacks[:nb]
|
132
|
-
end
|
133
|
-
end
|