i18n 1.1.1 → 1.2.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 +4 -0
- data/lib/i18n/backend.rb +1 -0
- data/lib/i18n/backend/base.rb +12 -1
- data/lib/i18n/backend/cache_file.rb +36 -0
- data/lib/i18n/backend/chain.rb +22 -0
- data/lib/i18n/backend/key_value.rb +24 -0
- data/lib/i18n/backend/simple.rb +1 -1
- data/lib/i18n/config.rb +16 -0
- data/lib/i18n/core_ext/hash.rb +8 -0
- data/lib/i18n/interpolate/ruby.rb +5 -3
- data/lib/i18n/version.rb +1 -1
- metadata +16 -52
- 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/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 -211
- data/test/backend/interpolation_compiler_test.rb +0 -118
- data/test/backend/key_value_test.rb +0 -85
- 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 -111
- 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.yaml +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
@@ -1,20 +0,0 @@
|
|
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
|
@@ -1,91 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
# thanks to Masao's String extensions, some tests taken from Masao's tests
|
4
|
-
# http://github.com/mutoh/gettext/blob/edbbe1fa8238fa12c7f26f2418403015f0270e47/test/test_string.rb
|
5
|
-
|
6
|
-
class I18nInterpolateTest < I18n::TestCase
|
7
|
-
test "String interpolates a hash argument w/ named placeholders" do
|
8
|
-
assert_equal "Masao Mutoh", I18n.interpolate("%{first} %{last}", :first => 'Masao', :last => 'Mutoh' )
|
9
|
-
end
|
10
|
-
|
11
|
-
test "String interpolates a hash argument w/ named placeholders (reverse order)" do
|
12
|
-
assert_equal "Mutoh, Masao", I18n.interpolate("%{last}, %{first}", :first => 'Masao', :last => 'Mutoh' )
|
13
|
-
end
|
14
|
-
|
15
|
-
test "String interpolates named placeholders with sprintf syntax" do
|
16
|
-
assert_equal "10, 43.4", I18n.interpolate("%<integer>d, %<float>.1f", :integer => 10, :float => 43.4)
|
17
|
-
end
|
18
|
-
|
19
|
-
test "String interpolates named placeholders with sprintf syntax, does not recurse" do
|
20
|
-
assert_equal "%<not_translated>s", I18n.interpolate("%{msg}", :msg => '%<not_translated>s', :not_translated => 'should not happen' )
|
21
|
-
end
|
22
|
-
|
23
|
-
test "String interpolation does not replace anything when no placeholders are given" do
|
24
|
-
assert_equal "aaa", I18n.interpolate("aaa", :num => 1)
|
25
|
-
end
|
26
|
-
|
27
|
-
test "String interpolation sprintf behaviour equals Ruby 1.9 behaviour" do
|
28
|
-
assert_equal "1", I18n.interpolate("%<num>d", :num => 1)
|
29
|
-
assert_equal "0b1", I18n.interpolate("%<num>#b", :num => 1)
|
30
|
-
assert_equal "foo", I18n.interpolate("%<msg>s", :msg => "foo")
|
31
|
-
assert_equal "1.000000", I18n.interpolate("%<num>f", :num => 1.0)
|
32
|
-
assert_equal " 1", I18n.interpolate("%<num>3.0f", :num => 1.0)
|
33
|
-
assert_equal "100.00", I18n.interpolate("%<num>2.2f", :num => 100.0)
|
34
|
-
assert_equal "0x64", I18n.interpolate("%<num>#x", :num => 100.0)
|
35
|
-
assert_raise(ArgumentError) { I18n.interpolate("%<num>,d", :num => 100) }
|
36
|
-
assert_raise(ArgumentError) { I18n.interpolate("%<num>/d", :num => 100) }
|
37
|
-
end
|
38
|
-
|
39
|
-
test "String interpolation raises an I18n::MissingInterpolationArgument when the string has extra placeholders" do
|
40
|
-
assert_raise(I18n::MissingInterpolationArgument) do # Ruby 1.9 msg: "key not found"
|
41
|
-
I18n.interpolate("%{first} %{last}", :first => 'Masao')
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
test "String interpolation does not raise when extra values were passed" do
|
46
|
-
assert_nothing_raised do
|
47
|
-
assert_equal "Masao Mutoh", I18n.interpolate("%{first} %{last}", :first => 'Masao', :last => 'Mutoh', :salutation => 'Mr.' )
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
test "% acts as escape character in String interpolation" do
|
52
|
-
assert_equal "%{first}", I18n.interpolate("%%{first}", :first => 'Masao')
|
53
|
-
assert_equal "% 1", I18n.interpolate("%% %<num>d", :num => 1.0)
|
54
|
-
assert_equal "%{num} %<num>d", I18n.interpolate("%%{num} %%<num>d", :num => 1)
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_sprintf_mix_unformatted_and_formatted_named_placeholders
|
58
|
-
assert_equal "foo 1.000000", I18n.interpolate("%{name} %<num>f", :name => "foo", :num => 1.0)
|
59
|
-
end
|
60
|
-
|
61
|
-
class RailsSafeBuffer < String
|
62
|
-
|
63
|
-
def gsub(*args, &block)
|
64
|
-
to_str.gsub(*args, &block)
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
test "with String subclass that redefined gsub method" do
|
69
|
-
assert_equal "Hello mars world", I18n.interpolate(RailsSafeBuffer.new("Hello %{planet} world"), :planet => 'mars')
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
class I18nMissingInterpolationCustomHandlerTest < I18n::TestCase
|
74
|
-
def setup
|
75
|
-
super
|
76
|
-
@old_handler = I18n.config.missing_interpolation_argument_handler
|
77
|
-
I18n.config.missing_interpolation_argument_handler = lambda do |key, values, string|
|
78
|
-
"missing key is #{key}, values are #{values.inspect}, given string is '#{string}'"
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def teardown
|
83
|
-
I18n.config.missing_interpolation_argument_handler = @old_handler
|
84
|
-
super
|
85
|
-
end
|
86
|
-
|
87
|
-
test "String interpolation can use custom missing interpolation handler" do
|
88
|
-
assert_equal %|Masao missing key is last, values are {:first=>"Masao"}, given string is '%{first} %{last}'|,
|
89
|
-
I18n.interpolate("%{first} %{last}", :first => 'Masao')
|
90
|
-
end
|
91
|
-
end
|
data/test/i18n/load_path_test.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class I18nLoadPathTest < I18n::TestCase
|
4
|
-
def setup
|
5
|
-
super
|
6
|
-
I18n.locale = :en
|
7
|
-
I18n.backend = I18n::Backend::Simple.new
|
8
|
-
store_translations(:en, :foo => {:bar => 'bar', :baz => 'baz'})
|
9
|
-
end
|
10
|
-
|
11
|
-
test "nested load paths do not break locale loading" do
|
12
|
-
I18n.load_path = [[locales_dir + '/en.yml']]
|
13
|
-
assert_equal "baz", I18n.t(:'foo.bar')
|
14
|
-
end
|
15
|
-
|
16
|
-
test "loading an empty yml file raises an InvalidLocaleData exception" do
|
17
|
-
assert_raise I18n::InvalidLocaleData do
|
18
|
-
I18n.load_path = [[locales_dir + '/invalid/empty.yml']]
|
19
|
-
I18n.t(:'foo.bar', :default => "baz")
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
test "loading an invalid yml file raises an InvalidLocaleData exception" do
|
24
|
-
assert_raise I18n::InvalidLocaleData do
|
25
|
-
I18n.load_path = [[locales_dir + '/invalid/syntax.yml']]
|
26
|
-
I18n.t(:'foo.bar', :default => "baz")
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
test "adding arrays of filenames to the load path does not break locale loading" do
|
31
|
-
I18n.load_path << Dir[locales_dir + '/*.{rb,yml}']
|
32
|
-
assert_equal "baz", I18n.t(:'foo.bar')
|
33
|
-
end
|
34
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class I18nMiddlewareTest < I18n::TestCase
|
4
|
-
def setup
|
5
|
-
super
|
6
|
-
I18n.default_locale = :fr
|
7
|
-
@app = DummyRackApp.new
|
8
|
-
@middleware = I18n::Middleware.new(@app)
|
9
|
-
end
|
10
|
-
|
11
|
-
test "middleware initializes new config object after request" do
|
12
|
-
old_i18n_config_object_id = Thread.current[:i18n_config].object_id
|
13
|
-
@middleware.call({})
|
14
|
-
|
15
|
-
updated_i18n_config_object_id = Thread.current[:i18n_config].object_id
|
16
|
-
assert_not_equal updated_i18n_config_object_id, old_i18n_config_object_id
|
17
|
-
end
|
18
|
-
|
19
|
-
test "succesfully resets i18n locale to default locale by defining new config" do
|
20
|
-
@middleware.call({})
|
21
|
-
|
22
|
-
assert_equal :fr, I18n.locale
|
23
|
-
end
|
24
|
-
end
|
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
|