i18n 0.8.3 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e5dfb6b01e690ee96c8fff66953f1ba5d9f5e8b
4
- data.tar.gz: 92cdb82e1c6e4dcccc73c3321f0b32cfc07cdca9
3
+ metadata.gz: 7aea28fdffb1b83ffc558cca097cb9ddd692a5e5
4
+ data.tar.gz: 1143c46c544e1ca82f014f6995df8170f13d896d
5
5
  SHA512:
6
- metadata.gz: ce6de9b2f93d878ad9b605400123a0d07882f37e2a46bf63ac010322b7d071ddfee00d4ca7f27648e5f00784d3dbfd334db3d4f6ccf01a4c5a42e7e469c76478
7
- data.tar.gz: 514e89dd67ee76be070862f2381bd66411e5f82c75d72adcd458d345d5b1c740d214d5c32e99dc7f33d30cfc0bc87179d903c978dae683cdb96f80d6752132f4
6
+ metadata.gz: 835ea057465196d791bba7a9d1affdf4d80e6ef4321fc08ff704571106d112eb3387cc757c8be8e115d9ffcfff808f38b9d05740ce68b63c873a7bbe4eb21646
7
+ data.tar.gz: 4ccba735b7f85e8b755d8f9308c36d2c31d6aabb7051a162c917997e47cfd016b3ffddda27de5a4262165c6cb602be45f0e32c30686b8ee5f067f387faf36056
@@ -149,7 +149,7 @@ module I18n
149
149
  handling = options.delete(:throw) && :throw || options.delete(:raise) && :raise # TODO deprecate :raise
150
150
 
151
151
  enforce_available_locales!(locale)
152
- raise I18n::ArgumentError if key.nil? || (key.is_a?(String) && key.empty?)
152
+ raise I18n::ArgumentError if key.is_a?(String) && key.empty?
153
153
 
154
154
  result = catch(:exception) do
155
155
  if key.is_a?(Array)
@@ -171,7 +171,7 @@ module I18n
171
171
 
172
172
  # Returns true if a translation exists for a given key, otherwise returns false.
173
173
  def exists?(key, locale = config.locale)
174
- raise I18n::ArgumentError if key.nil? || (key.is_a?(String) && key.empty?)
174
+ raise I18n::ArgumentError if key.is_a?(String) && key.empty?
175
175
  config.backend.exists?(locale, key)
176
176
  end
177
177
 
@@ -55,7 +55,7 @@ module I18n
55
55
  @fallback_locked = false
56
56
  end
57
57
 
58
- return super(locale, key, options.merge(:default => default)) if default
58
+ return super(locale, nil, options.merge(:default => default)) if default
59
59
  throw(:exception, I18n::MissingTranslation.new(locale, key, options))
60
60
  end
61
61
 
@@ -9,11 +9,11 @@ module I18n
9
9
  end
10
10
 
11
11
  test "defaults: given nil as a key it returns the given default" do
12
- assert_equal 'default', I18n.t(:does_not_exist, :default => 'default')
12
+ assert_equal 'default', I18n.t(nil, :default => 'default')
13
13
  end
14
14
 
15
15
  test "defaults: given a symbol as a default it translates the symbol" do
16
- assert_equal 'bar', I18n.t(:does_not_exist, :default => :'foo.bar')
16
+ assert_equal 'bar', I18n.t(nil, :default => :'foo.bar')
17
17
  end
18
18
 
19
19
  test "defaults: given a symbol as a default and a scope it stays inside the scope when looking up the symbol" do
@@ -41,7 +41,7 @@ module I18n
41
41
  test "defaults: using a custom scope separator" do
42
42
  # data must have been stored using the custom separator when using the ActiveRecord backend
43
43
  I18n.backend.store_translations(:en, { :foo => { :bar => 'bar' } }, { :separator => '|' })
44
- assert_equal 'bar', I18n.t(:does_not_exist, :default => :'foo|bar', :separator => '|')
44
+ assert_equal 'bar', I18n.t(nil, :default => :'foo|bar', :separator => '|')
45
45
  end
46
46
  end
47
47
  end
@@ -4,31 +4,31 @@ module I18n
4
4
  module Tests
5
5
  module Pluralization
6
6
  test "pluralization: given 0 it returns the :zero translation if it is defined" do
7
- assert_equal 'zero', I18n.t(:does_not_exist, :default => { :zero => 'zero' }, :count => 0)
7
+ assert_equal 'zero', I18n.t(:default => { :zero => 'zero' }, :count => 0)
8
8
  end
9
9
 
10
10
  test "pluralization: given 0 it returns the :other translation if :zero is not defined" do
11
- assert_equal 'bars', I18n.t(:does_not_exist, :default => { :other => 'bars' }, :count => 0)
11
+ assert_equal 'bars', I18n.t(:default => { :other => 'bars' }, :count => 0)
12
12
  end
13
13
 
14
14
  test "pluralization: given 1 it returns the singular translation" do
15
- assert_equal 'bar', I18n.t(:does_not_exist, :default => { :one => 'bar' }, :count => 1)
15
+ assert_equal 'bar', I18n.t(:default => { :one => 'bar' }, :count => 1)
16
16
  end
17
17
 
18
18
  test "pluralization: given 2 it returns the :other translation" do
19
- assert_equal 'bars', I18n.t(:does_not_exist, :default => { :other => 'bars' }, :count => 2)
19
+ assert_equal 'bars', I18n.t(:default => { :other => 'bars' }, :count => 2)
20
20
  end
21
21
 
22
22
  test "pluralization: given 3 it returns the :other translation" do
23
- assert_equal 'bars', I18n.t(:does_not_exist, :default => { :other => 'bars' }, :count => 3)
23
+ assert_equal 'bars', I18n.t(:default => { :other => 'bars' }, :count => 3)
24
24
  end
25
25
 
26
26
  test "pluralization: given nil it returns the whole entry" do
27
- assert_equal({ :one => 'bar' }, I18n.t(:does_not_exist, :default => { :one => 'bar' }, :count => nil))
27
+ assert_equal({ :one => 'bar' }, I18n.t(:default => { :one => 'bar' }, :count => nil))
28
28
  end
29
29
 
30
30
  test "pluralization: given incomplete pluralization data it raises I18n::InvalidPluralizationData" do
31
- assert_raise(I18n::InvalidPluralizationData) { I18n.t(:does_not_exist, :default => { :one => 'bar' }, :count => 2) }
31
+ assert_raise(I18n::InvalidPluralizationData) { I18n.t(:default => { :one => 'bar' }, :count => 2) }
32
32
  end
33
33
  end
34
34
  end
@@ -3,47 +3,47 @@
3
3
  module I18n
4
4
  module Tests
5
5
  module Procs
6
- test "lookup: given a translation is a Proc it calls the Proc with the key and interpolation values" do
6
+ test "lookup: given a translation is a proc it calls the proc with the key and interpolation values" do
7
7
  I18n.backend.store_translations(:en, :a_lambda => lambda { |*args| I18n::Tests::Procs.filter_args(*args) })
8
8
  assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(:a_lambda, :foo => 'foo')
9
9
  end
10
10
 
11
11
  test "defaults: given a default is a Proc it calls it with the key and interpolation values" do
12
12
  proc = lambda { |*args| I18n::Tests::Procs.filter_args(*args) }
13
- assert_equal '[:does_not_exist, {:foo=>"foo"}]', I18n.t(:does_not_exist, :default => proc, :foo => 'foo')
13
+ assert_equal '[nil, {:foo=>"foo"}]', I18n.t(nil, :default => proc, :foo => 'foo')
14
14
  end
15
15
 
16
16
  test "defaults: given a default is a key that resolves to a Proc it calls it with the key and interpolation values" do
17
17
  the_lambda = lambda { |*args| I18n::Tests::Procs.filter_args(*args) }
18
18
  I18n.backend.store_translations(:en, :a_lambda => the_lambda)
19
- assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(:does_not_exist, :default => :a_lambda, :foo => 'foo')
20
- assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(:does_not_exist, :default => [nil, :a_lambda], :foo => 'foo')
19
+ assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(nil, :default => :a_lambda, :foo => 'foo')
20
+ assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(nil, :default => [nil, :a_lambda], :foo => 'foo')
21
21
  end
22
22
 
23
23
  test "interpolation: given an interpolation value is a lambda it calls it with key and values before interpolating it" do
24
24
  proc = lambda { |*args| I18n::Tests::Procs.filter_args(*args) }
25
- assert_match %r(\[\{:foo=>#<Proc.*>\}\]), I18n.t(:does_not_exist, :default => '%{foo}', :foo => proc)
25
+ assert_match %r(\[\{:foo=>#<Proc.*>\}\]), I18n.t(nil, :default => '%{foo}', :foo => proc)
26
26
  end
27
27
 
28
28
  test "interpolation: given a key resolves to a Proc that returns a string then interpolation still works" do
29
29
  proc = lambda { |*args| "%{foo}: " + I18n::Tests::Procs.filter_args(*args) }
30
- assert_equal 'foo: [:does_not_exist, {:foo=>"foo"}]', I18n.t(:does_not_exist, :default => proc, :foo => 'foo')
30
+ assert_equal 'foo: [nil, {:foo=>"foo"}]', I18n.t(nil, :default => proc, :foo => 'foo')
31
31
  end
32
32
 
33
33
  test "pluralization: given a key resolves to a Proc that returns valid data then pluralization still works" do
34
34
  proc = lambda { |*args| { :zero => 'zero', :one => 'one', :other => 'other' } }
35
- assert_equal 'zero', I18n.t(:does_not_exist, :default => proc, :count => 0)
36
- assert_equal 'one', I18n.t(:does_not_exist, :default => proc, :count => 1)
37
- assert_equal 'other', I18n.t(:does_not_exist, :default => proc, :count => 2)
35
+ assert_equal 'zero', I18n.t(:default => proc, :count => 0)
36
+ assert_equal 'one', I18n.t(:default => proc, :count => 1)
37
+ assert_equal 'other', I18n.t(:default => proc, :count => 2)
38
38
  end
39
39
 
40
- test "lookup: given the option :resolve => false was passed it does not resolve Proc translations" do
40
+ test "lookup: given the option :resolve => false was passed it does not resolve proc translations" do
41
41
  I18n.backend.store_translations(:en, :a_lambda => lambda { |*args| I18n::Tests::Procs.filter_args(*args) })
42
42
  assert_equal Proc, I18n.t(:a_lambda, :resolve => false).class
43
43
  end
44
44
 
45
- test "lookup: given the option :resolve => false was passed it does not resolve Proc default" do
46
- assert_equal Proc, I18n.t(:does_not_exist, :default => lambda { |*args| I18n::Tests::Procs.filter_args(*args) }, :resolve => false).class
45
+ test "lookup: given the option :resolve => false was passed it does not resolve proc default" do
46
+ assert_equal Proc, I18n.t(nil, :default => lambda { |*args| I18n::Tests::Procs.filter_args(*args) }, :resolve => false).class
47
47
  end
48
48
 
49
49
 
@@ -1,3 +1,3 @@
1
1
  module I18n
2
- VERSION = "0.8.3"
2
+ VERSION = "0.8.4"
3
3
  end
@@ -39,7 +39,7 @@ class I18nBackendCascadeTest < I18n::TestCase
39
39
  end
40
40
 
41
41
  test "cascades defaults, too" do
42
- assert_equal 'foo', lookup(:does_not_exist, :default => [:'missing.missing', :'missing.foo'])
42
+ assert_equal 'foo', lookup(nil, :default => [:'missing.missing', :'missing.foo'])
43
43
  end
44
44
 
45
45
  test "works with :offset => 2 and a single key" do
@@ -39,10 +39,10 @@ class I18nBackendChainTest < I18n::TestCase
39
39
  end
40
40
 
41
41
  test "default" do
42
- assert_equal 'Fuh', I18n.t(:does_not_exist, :default => 'Fuh')
43
- assert_equal 'Zero', I18n.t(:does_not_exist, :default => { :zero => 'Zero' }, :count => 0)
44
- assert_equal({ :zero => 'Zero' }, I18n.t(:does_not_exist, :default => { :zero => 'Zero' }))
45
- assert_equal 'Foo', I18n.t(:does_not_exist, :default => :foo)
42
+ assert_equal 'Fuh', I18n.t(:default => 'Fuh')
43
+ assert_equal 'Zero', I18n.t(:default => { :zero => 'Zero' }, :count => 0)
44
+ assert_equal({ :zero => 'Zero' }, I18n.t(:default => { :zero => 'Zero' }))
45
+ assert_equal 'Foo', I18n.t(:default => :foo)
46
46
  end
47
47
 
48
48
  test 'default is returned if translation is missing' do
@@ -19,24 +19,24 @@ class I18nBackendPluralizationTest < I18n::TestCase
19
19
  end
20
20
 
21
21
  test "pluralization picks :one for 1" do
22
- assert_equal 'one', I18n.t(:does_not_exist, :count => 1, :default => @entry, :locale => :xx)
22
+ assert_equal 'one', I18n.t(:count => 1, :default => @entry, :locale => :xx)
23
23
  end
24
24
 
25
25
  test "pluralization picks :few for 2" do
26
- assert_equal 'few', I18n.t(:does_not_exist, :count => 2, :default => @entry, :locale => :xx)
26
+ assert_equal 'few', I18n.t(:count => 2, :default => @entry, :locale => :xx)
27
27
  end
28
28
 
29
29
  test "pluralization picks :many for 11" do
30
- assert_equal 'many', I18n.t(:does_not_exist, :count => 11, :default => @entry, :locale => :xx)
30
+ assert_equal 'many', I18n.t(:count => 11, :default => @entry, :locale => :xx)
31
31
  end
32
32
 
33
33
  test "pluralization picks zero for 0 if the key is contained in the data" do
34
- assert_equal 'zero', I18n.t(:does_not_exist, :count => 0, :default => @entry, :locale => :xx)
34
+ assert_equal 'zero', I18n.t(:count => 0, :default => @entry, :locale => :xx)
35
35
  end
36
36
 
37
37
  test "pluralization picks few for 0 if the key is not contained in the data" do
38
38
  @entry.delete(:zero)
39
- assert_equal 'few', I18n.t(:does_not_exist, :count => 0, :default => @entry, :locale => :xx)
39
+ assert_equal 'few', I18n.t(:count => 0, :default => @entry, :locale => :xx)
40
40
  end
41
41
 
42
42
  test "Fallbacks can pick up rules from fallback locales, too" do
@@ -8,8 +8,8 @@ class I18nBackendSimpleTest < I18n::TestCase
8
8
  end
9
9
 
10
10
  # useful because this way we can use the backend with no key for interpolation/pluralization
11
- test "simple backend translate: given an invalid key it still interpolates the default value" do
12
- assert_equal "Hi David", I18n.t(:does_not_exist, :default => "Hi %{name}", :name => "David")
11
+ test "simple backend translate: given nil as a key it still interpolations the default value" do
12
+ assert_equal "Hi David", I18n.t(nil, :default => "Hi %{name}", :name => "David")
13
13
  end
14
14
 
15
15
  # loading translations
@@ -216,10 +216,6 @@ class I18nTest < I18n::TestCase
216
216
  assert_raise(I18n::ArgumentError) { I18n.t("") }
217
217
  end
218
218
 
219
- test "translate given nil as a key raises an I18n::ArgumentError" do
220
- assert_raise(I18n::ArgumentError) { I18n.t(nil) }
221
- end
222
-
223
219
  test "translate given an unavailable locale rases an I18n::InvalidLocale" do
224
220
  begin
225
221
  I18n.config.enforce_available_locales = true
@@ -262,14 +258,6 @@ class I18nTest < I18n::TestCase
262
258
  assert_equal false, I18n.exists?(:bogus)
263
259
  end
264
260
 
265
- test "exists? given an empty string will raise an error" do
266
- assert_raise(I18n::ArgumentError) { I18n.exists?("") }
267
- end
268
-
269
- test "exists? given nil will raise an error" do
270
- assert_raise(I18n::ArgumentError) { I18n.exists?(nil) }
271
- end
272
-
273
261
  test "exists? given an existing dot-separated key will return true" do
274
262
  assert_equal true, I18n.exists?('currency.format.delimiter')
275
263
  end
@@ -417,7 +405,7 @@ class I18nTest < I18n::TestCase
417
405
  I18n.config.enforce_available_locales = false
418
406
  end
419
407
  end
420
-
408
+
421
409
  test 'I18n.reload! reloads the set of locales that are enforced' do
422
410
  begin
423
411
  # Clear the backend that affects the available locales and somehow can remain
@@ -425,9 +413,9 @@ class I18nTest < I18n::TestCase
425
413
  # For instance, it contains enough translations to cause a false positive with
426
414
  # this test when ran with --seed=50992
427
415
  I18n.backend = I18n::Backend::Simple.new
428
-
416
+
429
417
  assert !I18n.available_locales.include?(:de), "Available locales should not include :de at this point"
430
-
418
+
431
419
  I18n.enforce_available_locales = true
432
420
 
433
421
  assert_raise(I18n::InvalidLocale) { I18n.default_locale = :de }
@@ -443,11 +431,11 @@ class I18nTest < I18n::TestCase
443
431
  store_translations(:en, :foo => 'Foo in :en')
444
432
  store_translations(:de, :foo => 'Foo in :de')
445
433
  store_translations(:pl, :foo => 'Foo in :pl')
446
-
434
+
447
435
  assert I18n.available_locales.include?(:de), ":de should now be allowed"
448
436
  assert I18n.available_locales.include?(:en), ":en should now be allowed"
449
437
  assert I18n.available_locales.include?(:pl), ":pl should now be allowed"
450
-
438
+
451
439
  assert_nothing_raised { I18n.default_locale = I18n.locale = :en }
452
440
  assert_nothing_raised { I18n.default_locale = I18n.locale = :de }
453
441
  assert_nothing_raised { I18n.default_locale = I18n.locale = :pl }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Fuchs
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2017-05-30 00:00:00.000000000 Z
15
+ date: 2017-05-31 00:00:00.000000000 Z
16
16
  dependencies: []
17
17
  description: New wave Internationalization support for Ruby.
18
18
  email: rails-i18n@googlegroups.com