i18n 0.8.1 → 0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/gemfiles/Gemfile.rails-3.2.x.lock +32 -0
- data/gemfiles/Gemfile.rails-4.0.x.lock +37 -0
- data/gemfiles/Gemfile.rails-4.1.x.lock +38 -0
- data/gemfiles/Gemfile.rails-4.2.x.lock +36 -0
- data/gemfiles/Gemfile.rails-5.0.x.lock +37 -0
- data/gemfiles/Gemfile.rails-master.lock +43 -0
- data/lib/i18n.rb +2 -2
- data/lib/i18n/backend/base.rb +1 -1
- data/lib/i18n/backend/fallbacks.rb +1 -1
- data/lib/i18n/gettext.rb +5 -4
- 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/gettext_plural_keys_test.rb +20 -0
- data/test/i18n_test.rb +26 -5
- metadata +10 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e5dfb6b01e690ee96c8fff66953f1ba5d9f5e8b
|
4
|
+
data.tar.gz: 92cdb82e1c6e4dcccc73c3321f0b32cfc07cdca9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce6de9b2f93d878ad9b605400123a0d07882f37e2a46bf63ac010322b7d071ddfee00d4ca7f27648e5f00784d3dbfd334db3d4f6ccf01a4c5a42e7e469c76478
|
7
|
+
data.tar.gz: 514e89dd67ee76be070862f2381bd66411e5f82c75d72adcd458d345d5b1c740d214d5c32e99dc7f33d30cfc0bc87179d903c978dae683cdb96f80d6752132f4
|
@@ -0,0 +1,32 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
i18n (0.8.2)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activesupport (3.2.22.5)
|
10
|
+
i18n (~> 0.6, >= 0.6.4)
|
11
|
+
multi_json (~> 1.0)
|
12
|
+
metaclass (0.0.4)
|
13
|
+
minitest (5.10.1)
|
14
|
+
mocha (1.2.1)
|
15
|
+
metaclass (~> 0.0.1)
|
16
|
+
multi_json (1.12.1)
|
17
|
+
rake (12.0.0)
|
18
|
+
test_declarative (0.0.5)
|
19
|
+
|
20
|
+
PLATFORMS
|
21
|
+
ruby
|
22
|
+
|
23
|
+
DEPENDENCIES
|
24
|
+
activesupport (~> 3.2.0)
|
25
|
+
i18n!
|
26
|
+
minitest
|
27
|
+
mocha
|
28
|
+
rake
|
29
|
+
test_declarative
|
30
|
+
|
31
|
+
BUNDLED WITH
|
32
|
+
1.14.6
|
@@ -0,0 +1,37 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
i18n (0.8.2)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activesupport (4.0.13)
|
10
|
+
i18n (~> 0.6, >= 0.6.9)
|
11
|
+
minitest (~> 4.2)
|
12
|
+
multi_json (~> 1.3)
|
13
|
+
thread_safe (~> 0.1)
|
14
|
+
tzinfo (~> 0.3.37)
|
15
|
+
metaclass (0.0.4)
|
16
|
+
minitest (4.7.5)
|
17
|
+
mocha (1.2.1)
|
18
|
+
metaclass (~> 0.0.1)
|
19
|
+
multi_json (1.12.1)
|
20
|
+
rake (12.0.0)
|
21
|
+
test_declarative (0.0.5)
|
22
|
+
thread_safe (0.3.6)
|
23
|
+
tzinfo (0.3.53)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
activesupport (~> 4.0.0)
|
30
|
+
i18n!
|
31
|
+
minitest
|
32
|
+
mocha
|
33
|
+
rake
|
34
|
+
test_declarative
|
35
|
+
|
36
|
+
BUNDLED WITH
|
37
|
+
1.14.6
|
@@ -0,0 +1,38 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
i18n (0.8.2)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activesupport (4.1.16)
|
10
|
+
i18n (~> 0.6, >= 0.6.9)
|
11
|
+
json (~> 1.7, >= 1.7.7)
|
12
|
+
minitest (~> 5.1)
|
13
|
+
thread_safe (~> 0.1)
|
14
|
+
tzinfo (~> 1.1)
|
15
|
+
json (1.8.6)
|
16
|
+
metaclass (0.0.4)
|
17
|
+
minitest (5.10.1)
|
18
|
+
mocha (1.2.1)
|
19
|
+
metaclass (~> 0.0.1)
|
20
|
+
rake (12.0.0)
|
21
|
+
test_declarative (0.0.5)
|
22
|
+
thread_safe (0.3.6)
|
23
|
+
tzinfo (1.2.2)
|
24
|
+
thread_safe (~> 0.1)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
activesupport (~> 4.1.0)
|
31
|
+
i18n!
|
32
|
+
minitest
|
33
|
+
mocha
|
34
|
+
rake
|
35
|
+
test_declarative
|
36
|
+
|
37
|
+
BUNDLED WITH
|
38
|
+
1.14.6
|
@@ -0,0 +1,36 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
i18n (0.8.2)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activesupport (4.2.8)
|
10
|
+
i18n (~> 0.7)
|
11
|
+
minitest (~> 5.1)
|
12
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
13
|
+
tzinfo (~> 1.1)
|
14
|
+
metaclass (0.0.4)
|
15
|
+
minitest (5.10.1)
|
16
|
+
mocha (1.2.1)
|
17
|
+
metaclass (~> 0.0.1)
|
18
|
+
rake (12.0.0)
|
19
|
+
test_declarative (0.0.5)
|
20
|
+
thread_safe (0.3.6)
|
21
|
+
tzinfo (1.2.2)
|
22
|
+
thread_safe (~> 0.1)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
activesupport (~> 4.2.0)
|
29
|
+
i18n!
|
30
|
+
minitest
|
31
|
+
mocha
|
32
|
+
rake
|
33
|
+
test_declarative
|
34
|
+
|
35
|
+
BUNDLED WITH
|
36
|
+
1.14.6
|
@@ -0,0 +1,37 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
i18n (0.8.2)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activesupport (5.0.2)
|
10
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
11
|
+
i18n (~> 0.7)
|
12
|
+
minitest (~> 5.1)
|
13
|
+
tzinfo (~> 1.1)
|
14
|
+
concurrent-ruby (1.0.5)
|
15
|
+
metaclass (0.0.4)
|
16
|
+
minitest (5.10.1)
|
17
|
+
mocha (1.2.1)
|
18
|
+
metaclass (~> 0.0.1)
|
19
|
+
rake (12.0.0)
|
20
|
+
test_declarative (0.0.5)
|
21
|
+
thread_safe (0.3.6)
|
22
|
+
tzinfo (1.2.2)
|
23
|
+
thread_safe (~> 0.1)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
activesupport (~> 5.0.0)
|
30
|
+
i18n!
|
31
|
+
minitest
|
32
|
+
mocha
|
33
|
+
rake
|
34
|
+
test_declarative
|
35
|
+
|
36
|
+
BUNDLED WITH
|
37
|
+
1.14.6
|
@@ -0,0 +1,43 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/rails/rails.git
|
3
|
+
revision: 49aa974ec8b15721d53b3b6abea88bd6ba433a68
|
4
|
+
branch: master
|
5
|
+
specs:
|
6
|
+
activesupport (5.1.0.alpha)
|
7
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
8
|
+
i18n (~> 0.7)
|
9
|
+
minitest (~> 5.1)
|
10
|
+
tzinfo (~> 1.1)
|
11
|
+
|
12
|
+
PATH
|
13
|
+
remote: ..
|
14
|
+
specs:
|
15
|
+
i18n (0.8.2)
|
16
|
+
|
17
|
+
GEM
|
18
|
+
remote: https://rubygems.org/
|
19
|
+
specs:
|
20
|
+
concurrent-ruby (1.0.5)
|
21
|
+
metaclass (0.0.4)
|
22
|
+
minitest (5.10.1)
|
23
|
+
mocha (1.2.1)
|
24
|
+
metaclass (~> 0.0.1)
|
25
|
+
rake (12.0.0)
|
26
|
+
test_declarative (0.0.5)
|
27
|
+
thread_safe (0.3.6)
|
28
|
+
tzinfo (1.2.2)
|
29
|
+
thread_safe (~> 0.1)
|
30
|
+
|
31
|
+
PLATFORMS
|
32
|
+
ruby
|
33
|
+
|
34
|
+
DEPENDENCIES
|
35
|
+
activesupport!
|
36
|
+
i18n!
|
37
|
+
minitest
|
38
|
+
mocha
|
39
|
+
rake
|
40
|
+
test_declarative
|
41
|
+
|
42
|
+
BUNDLED WITH
|
43
|
+
1.14.6
|
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.is_a?(String) && key.empty?
|
152
|
+
raise I18n::ArgumentError if key.nil? || (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.is_a?(String) && key.empty?
|
174
|
+
raise I18n::ArgumentError if key.nil? || (key.is_a?(String) && key.empty?)
|
175
175
|
config.backend.exists?(locale, key)
|
176
176
|
end
|
177
177
|
|
data/lib/i18n/backend/base.rb
CHANGED
@@ -23,7 +23,7 @@ module I18n
|
|
23
23
|
|
24
24
|
def translate(locale, key, options = {})
|
25
25
|
raise InvalidLocale.new(locale) unless locale
|
26
|
-
entry =
|
26
|
+
entry = lookup(locale, key, options[:scope], options) unless key.nil?
|
27
27
|
|
28
28
|
if entry.nil? && options.key?(:default)
|
29
29
|
entry = default(locale, key, options[:default], options)
|
@@ -55,7 +55,7 @@ module I18n
|
|
55
55
|
@fallback_locked = false
|
56
56
|
end
|
57
57
|
|
58
|
-
return super(locale,
|
58
|
+
return super(locale, key, options.merge(:default => default)) if default
|
59
59
|
throw(:exception, I18n::MissingTranslation.new(locale, key, options))
|
60
60
|
end
|
61
61
|
|
data/lib/i18n/gettext.rb
CHANGED
@@ -8,11 +8,12 @@ module I18n
|
|
8
8
|
@@plural_keys = { :en => [:one, :other] }
|
9
9
|
|
10
10
|
class << self
|
11
|
-
# returns an array of plural keys for the given locale
|
12
|
-
# convert from gettext's
|
11
|
+
# returns an array of plural keys for the given locale or the whole hash
|
12
|
+
# of locale mappings to plural keys so that we can convert from gettext's
|
13
|
+
# integer-index based style
|
13
14
|
# TODO move this information to the pluralization module
|
14
|
-
def plural_keys(
|
15
|
-
@@plural_keys[
|
15
|
+
def plural_keys(*args)
|
16
|
+
args.empty? ? @@plural_keys : @@plural_keys[args.first] || @@plural_keys[:en]
|
16
17
|
end
|
17
18
|
|
18
19
|
def extract_scope(msgid, separator)
|
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(:does_not_exist, :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(:does_not_exist, :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(:does_not_exist, :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(:default => { :zero => 'zero' }, :count => 0)
|
7
|
+
assert_equal 'zero', I18n.t(:does_not_exist, :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(:default => { :other => 'bars' }, :count => 0)
|
11
|
+
assert_equal 'bars', I18n.t(:does_not_exist, :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(:default => { :one => 'bar' }, :count => 1)
|
15
|
+
assert_equal 'bar', I18n.t(:does_not_exist, :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(:default => { :other => 'bars' }, :count => 2)
|
19
|
+
assert_equal 'bars', I18n.t(:does_not_exist, :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(:default => { :other => 'bars' }, :count => 3)
|
23
|
+
assert_equal 'bars', I18n.t(:does_not_exist, :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(:default => { :one => 'bar' }, :count => nil))
|
27
|
+
assert_equal({ :one => 'bar' }, I18n.t(:does_not_exist, :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(:default => { :one => 'bar' }, :count => 2) }
|
31
|
+
assert_raise(I18n::InvalidPluralizationData) { I18n.t(:does_not_exist, :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 '[:does_not_exist, {:foo=>"foo"}]', I18n.t(:does_not_exist, :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(: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')
|
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(:does_not_exist, :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: [:does_not_exist, {:foo=>"foo"}]', I18n.t(:does_not_exist, :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(:default => proc, :count => 0)
|
36
|
-
assert_equal 'one', I18n.t(:default => proc, :count => 1)
|
37
|
-
assert_equal 'other', I18n.t(:default => proc, :count => 2)
|
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)
|
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(:does_not_exist, :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(:does_not_exist, :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(: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)
|
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)
|
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(:count => 1, :default => @entry, :locale => :xx)
|
22
|
+
assert_equal 'one', I18n.t(:does_not_exist, :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(:count => 2, :default => @entry, :locale => :xx)
|
26
|
+
assert_equal 'few', I18n.t(:does_not_exist, :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(:count => 11, :default => @entry, :locale => :xx)
|
30
|
+
assert_equal 'many', I18n.t(:does_not_exist, :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(:count => 0, :default => @entry, :locale => :xx)
|
34
|
+
assert_equal 'zero', I18n.t(:does_not_exist, :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(:count => 0, :default => @entry, :locale => :xx)
|
39
|
+
assert_equal 'few', I18n.t(:does_not_exist, :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 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")
|
13
13
|
end
|
14
14
|
|
15
15
|
# loading translations
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class I18nGettextPluralKeysTest < I18n::TestCase
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
I18n::Gettext.plural_keys[:zz] = [:value1, :value2]
|
7
|
+
end
|
8
|
+
|
9
|
+
test "Returns the plural keys of the given locale if present" do
|
10
|
+
assert_equal I18n::Gettext.plural_keys(:zz), [:value1, :value2]
|
11
|
+
end
|
12
|
+
|
13
|
+
test "Returns the plural keys of :en if given locale not present" do
|
14
|
+
assert_equal I18n::Gettext.plural_keys(:yy), [:one, :other]
|
15
|
+
end
|
16
|
+
|
17
|
+
test "Returns the whole hash with no arguments" do
|
18
|
+
assert_equal I18n::Gettext.plural_keys, { :en => [:one, :other], :zz => [:value1, :value2] }
|
19
|
+
end
|
20
|
+
end
|
data/test/i18n_test.rb
CHANGED
@@ -6,6 +6,7 @@ class I18nTest < I18n::TestCase
|
|
6
6
|
super
|
7
7
|
store_translations(:en, :currency => { :format => { :separator => '.', :delimiter => ',', } })
|
8
8
|
store_translations(:nl, :currency => { :format => { :separator => ',', :delimiter => '.', } })
|
9
|
+
store_translations(:en, "true" => "Yes", "false" => "No")
|
9
10
|
end
|
10
11
|
|
11
12
|
test "exposes its VERSION constant" do
|
@@ -215,6 +216,10 @@ class I18nTest < I18n::TestCase
|
|
215
216
|
assert_raise(I18n::ArgumentError) { I18n.t("") }
|
216
217
|
end
|
217
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
|
+
|
218
223
|
test "translate given an unavailable locale rases an I18n::InvalidLocale" do
|
219
224
|
begin
|
220
225
|
I18n.config.enforce_available_locales = true
|
@@ -224,6 +229,14 @@ class I18nTest < I18n::TestCase
|
|
224
229
|
end
|
225
230
|
end
|
226
231
|
|
232
|
+
test "translate given true as a key works" do
|
233
|
+
assert_equal "Yes", I18n.t(true)
|
234
|
+
end
|
235
|
+
|
236
|
+
test "translate given false as a key works" do
|
237
|
+
assert_equal "No", I18n.t(false)
|
238
|
+
end
|
239
|
+
|
227
240
|
test "available_locales can be replaced at runtime" do
|
228
241
|
begin
|
229
242
|
I18n.config.enforce_available_locales = true
|
@@ -249,6 +262,14 @@ class I18nTest < I18n::TestCase
|
|
249
262
|
assert_equal false, I18n.exists?(:bogus)
|
250
263
|
end
|
251
264
|
|
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
|
+
|
252
273
|
test "exists? given an existing dot-separated key will return true" do
|
253
274
|
assert_equal true, I18n.exists?('currency.format.delimiter')
|
254
275
|
end
|
@@ -396,7 +417,7 @@ class I18nTest < I18n::TestCase
|
|
396
417
|
I18n.config.enforce_available_locales = false
|
397
418
|
end
|
398
419
|
end
|
399
|
-
|
420
|
+
|
400
421
|
test 'I18n.reload! reloads the set of locales that are enforced' do
|
401
422
|
begin
|
402
423
|
# Clear the backend that affects the available locales and somehow can remain
|
@@ -404,9 +425,9 @@ class I18nTest < I18n::TestCase
|
|
404
425
|
# For instance, it contains enough translations to cause a false positive with
|
405
426
|
# this test when ran with --seed=50992
|
406
427
|
I18n.backend = I18n::Backend::Simple.new
|
407
|
-
|
428
|
+
|
408
429
|
assert !I18n.available_locales.include?(:de), "Available locales should not include :de at this point"
|
409
|
-
|
430
|
+
|
410
431
|
I18n.enforce_available_locales = true
|
411
432
|
|
412
433
|
assert_raise(I18n::InvalidLocale) { I18n.default_locale = :de }
|
@@ -422,11 +443,11 @@ class I18nTest < I18n::TestCase
|
|
422
443
|
store_translations(:en, :foo => 'Foo in :en')
|
423
444
|
store_translations(:de, :foo => 'Foo in :de')
|
424
445
|
store_translations(:pl, :foo => 'Foo in :pl')
|
425
|
-
|
446
|
+
|
426
447
|
assert I18n.available_locales.include?(:de), ":de should now be allowed"
|
427
448
|
assert I18n.available_locales.include?(:en), ":en should now be allowed"
|
428
449
|
assert I18n.available_locales.include?(:pl), ":pl should now be allowed"
|
429
|
-
|
450
|
+
|
430
451
|
assert_nothing_raised { I18n.default_locale = I18n.locale = :en }
|
431
452
|
assert_nothing_raised { I18n.default_locale = I18n.locale = :de }
|
432
453
|
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.3
|
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-
|
15
|
+
date: 2017-05-30 00:00:00.000000000 Z
|
16
16
|
dependencies: []
|
17
17
|
description: New wave Internationalization support for Ruby.
|
18
18
|
email: rails-i18n@googlegroups.com
|
@@ -23,11 +23,17 @@ files:
|
|
23
23
|
- MIT-LICENSE
|
24
24
|
- README.md
|
25
25
|
- gemfiles/Gemfile.rails-3.2.x
|
26
|
+
- gemfiles/Gemfile.rails-3.2.x.lock
|
26
27
|
- gemfiles/Gemfile.rails-4.0.x
|
28
|
+
- gemfiles/Gemfile.rails-4.0.x.lock
|
27
29
|
- gemfiles/Gemfile.rails-4.1.x
|
30
|
+
- gemfiles/Gemfile.rails-4.1.x.lock
|
28
31
|
- gemfiles/Gemfile.rails-4.2.x
|
32
|
+
- gemfiles/Gemfile.rails-4.2.x.lock
|
29
33
|
- gemfiles/Gemfile.rails-5.0.x
|
34
|
+
- gemfiles/Gemfile.rails-5.0.x.lock
|
30
35
|
- gemfiles/Gemfile.rails-master
|
36
|
+
- gemfiles/Gemfile.rails-master.lock
|
31
37
|
- lib/i18n.rb
|
32
38
|
- lib/i18n/backend.rb
|
33
39
|
- lib/i18n/backend/base.rb
|
@@ -98,6 +104,7 @@ files:
|
|
98
104
|
- test/gettext/api_test.rb
|
99
105
|
- test/gettext/backend_test.rb
|
100
106
|
- test/i18n/exceptions_test.rb
|
107
|
+
- test/i18n/gettext_plural_keys_test.rb
|
101
108
|
- test/i18n/interpolate_test.rb
|
102
109
|
- test/i18n/load_path_test.rb
|
103
110
|
- test/i18n_test.rb
|
@@ -132,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
139
|
version: 1.3.5
|
133
140
|
requirements: []
|
134
141
|
rubyforge_project: "[none]"
|
135
|
-
rubygems_version: 2.6.
|
142
|
+
rubygems_version: 2.6.10
|
136
143
|
signing_key:
|
137
144
|
specification_version: 4
|
138
145
|
summary: New wave Internationalization support for Ruby
|