i18n 0.8.3 → 0.8.4
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.
- checksums.yaml +4 -4
- data/lib/i18n.rb +2 -2
- data/lib/i18n/backend/fallbacks.rb +1 -1
- data/lib/i18n/tests/defaults.rb +3 -3
- data/lib/i18n/tests/pluralization.rb +7 -7
- data/lib/i18n/tests/procs.rb +12 -12
- data/lib/i18n/version.rb +1 -1
- data/test/backend/cascade_test.rb +1 -1
- data/test/backend/chain_test.rb +4 -4
- data/test/backend/pluralization_test.rb +5 -5
- data/test/backend/simple_test.rb +2 -2
- data/test/i18n_test.rb +5 -17
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7aea28fdffb1b83ffc558cca097cb9ddd692a5e5
|
4
|
+
data.tar.gz: 1143c46c544e1ca82f014f6995df8170f13d896d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 835ea057465196d791bba7a9d1affdf4d80e6ef4321fc08ff704571106d112eb3387cc757c8be8e115d9ffcfff808f38b9d05740ce68b63c873a7bbe4eb21646
|
7
|
+
data.tar.gz: 4ccba735b7f85e8b755d8f9308c36d2c31d6aabb7051a162c917997e47cfd016b3ffddda27de5a4262165c6cb602be45f0e32c30686b8ee5f067f387faf36056
|
data/lib/i18n.rb
CHANGED
@@ -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.
|
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.
|
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,
|
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
|
|
data/lib/i18n/tests/defaults.rb
CHANGED
@@ -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(
|
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(
|
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(
|
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(:
|
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(:
|
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(:
|
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(:
|
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(:
|
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(:
|
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(:
|
31
|
+
assert_raise(I18n::InvalidPluralizationData) { I18n.t(:default => { :one => 'bar' }, :count => 2) }
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
data/lib/i18n/tests/procs.rb
CHANGED
@@ -3,47 +3,47 @@
|
|
3
3
|
module I18n
|
4
4
|
module Tests
|
5
5
|
module Procs
|
6
|
-
test "lookup: given a translation is a
|
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 '[
|
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(
|
20
|
-
assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(
|
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(
|
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: [
|
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(:
|
36
|
-
assert_equal 'one', I18n.t(:
|
37
|
-
assert_equal 'other', I18n.t(:
|
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
|
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
|
46
|
-
assert_equal Proc, I18n.t(
|
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
|
|
data/lib/i18n/version.rb
CHANGED
@@ -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(
|
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
|
data/test/backend/chain_test.rb
CHANGED
@@ -39,10 +39,10 @@ class I18nBackendChainTest < I18n::TestCase
|
|
39
39
|
end
|
40
40
|
|
41
41
|
test "default" do
|
42
|
-
assert_equal 'Fuh', I18n.t(:
|
43
|
-
assert_equal 'Zero', I18n.t(:
|
44
|
-
assert_equal({ :zero => 'Zero' }, I18n.t(:
|
45
|
-
assert_equal 'Foo', I18n.t(:
|
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(:
|
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(:
|
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(:
|
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(:
|
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(:
|
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
|
data/test/backend/simple_test.rb
CHANGED
@@ -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
|
12
|
-
assert_equal "Hi David", I18n.t(
|
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
|
data/test/i18n_test.rb
CHANGED
@@ -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.
|
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-
|
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
|