i18n 0.5.0beta1 → 0.5.0beta2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of i18n might be problematic. Click here for more details.
- data/README.textile +4 -17
- data/ci/Gemfile.no-rails +5 -0
- data/ci/Gemfile.no-rails.lock +17 -0
- data/ci/Gemfile.rails-2.3.x +9 -0
- data/ci/Gemfile.rails-2.3.x.lock +26 -0
- data/ci/Gemfile.rails-3.x +9 -0
- data/ci/Gemfile.rails-3.x.lock +26 -0
- data/lib/i18n.rb +4 -8
- data/lib/i18n/backend.rb +0 -1
- data/lib/i18n/backend/base.rb +4 -32
- data/lib/i18n/backend/gettext.rb +3 -3
- data/lib/i18n/backend/interpolation_compiler.rb +1 -1
- data/lib/i18n/backend/metadata.rb +1 -1
- data/lib/i18n/config.rb +1 -1
- data/lib/i18n/core_ext/kernel/surpress_warnings.rb +9 -0
- data/lib/i18n/core_ext/string/interpolate.rb +0 -96
- data/lib/i18n/exceptions.rb +0 -6
- data/lib/i18n/interpolate/ruby.rb +31 -0
- data/lib/i18n/locale/fallbacks.rb +3 -3
- data/lib/i18n/tests/localization/procs.rb +32 -19
- data/lib/i18n/tests/localization/time.rb +2 -2
- data/lib/i18n/version.rb +1 -1
- data/test/all.rb +8 -0
- data/test/api/all_features_test.rb +58 -0
- data/test/api/cascade_test.rb +28 -0
- data/test/api/chain_test.rb +24 -0
- data/test/api/fallbacks_test.rb +30 -0
- data/test/api/key_value_test.rb +28 -0
- data/test/api/memoize_test.rb +60 -0
- data/test/api/pluralization_test.rb +30 -0
- data/test/api/simple_test.rb +28 -0
- data/test/backend/cache_test.rb +83 -0
- data/test/backend/cascade_test.rb +85 -0
- data/test/backend/chain_test.rb +67 -0
- data/test/backend/exceptions_test.rb +23 -0
- data/test/backend/fallbacks_test.rb +116 -0
- data/test/backend/interpolation_compiler_test.rb +102 -0
- data/test/backend/key_value_test.rb +46 -0
- data/test/backend/memoize_test.rb +47 -0
- data/test/backend/metadata_test.rb +67 -0
- data/test/backend/pluralization_test.rb +44 -0
- data/test/backend/simple_test.rb +79 -0
- data/test/backend/transliterator_test.rb +81 -0
- data/test/core_ext/hash_test.rb +30 -0
- data/test/gettext/api_test.rb +206 -0
- data/test/gettext/backend_test.rb +93 -0
- data/test/i18n/exceptions_test.rb +116 -0
- data/test/i18n/interpolate_test.rb +60 -0
- data/test/i18n/load_path_test.rb +26 -0
- data/test/i18n_test.rb +236 -0
- data/test/locale/fallbacks_test.rb +124 -0
- data/test/locale/tag/rfc4646_test.rb +142 -0
- data/test/locale/tag/simple_test.rb +32 -0
- data/test/run_all.rb +21 -0
- data/test/test_data/locales/de.po +72 -0
- data/test/test_data/locales/en.rb +3 -0
- data/test/test_data/locales/en.yml +3 -0
- data/test/test_data/locales/invalid/empty.yml +1 -0
- data/test/test_data/locales/plurals.rb +113 -0
- data/test/test_helper.rb +56 -0
- metadata +116 -14
- data/lib/i18n/backend/cldr.rb +0 -99
@@ -6,23 +6,23 @@ module I18n
|
|
6
6
|
module Procs
|
7
7
|
test "localize: using day names from lambdas" do
|
8
8
|
setup_time_proc_translations
|
9
|
-
time = ::Time.
|
10
|
-
assert_match
|
11
|
-
assert_match
|
9
|
+
time = ::Time.utc(2008, 3, 1, 6, 0)
|
10
|
+
assert_match(/Суббота/, I18n.l(time, :format => "%A, %d %B", :locale => :ru))
|
11
|
+
assert_match(/суббота/, I18n.l(time, :format => "%d %B (%A)", :locale => :ru))
|
12
12
|
end
|
13
13
|
|
14
14
|
test "localize: using month names from lambdas" do
|
15
15
|
setup_time_proc_translations
|
16
|
-
time = ::Time.
|
17
|
-
assert_match
|
18
|
-
assert_match
|
16
|
+
time = ::Time.utc(2008, 3, 1, 6, 0)
|
17
|
+
assert_match(/марта/, I18n.l(time, :format => "%d %B %Y", :locale => :ru))
|
18
|
+
assert_match(/Март /, I18n.l(time, :format => "%B %Y", :locale => :ru))
|
19
19
|
end
|
20
20
|
|
21
21
|
test "localize: using abbreviated day names from lambdas" do
|
22
22
|
setup_time_proc_translations
|
23
|
-
time = ::Time.
|
24
|
-
assert_match
|
25
|
-
assert_match
|
23
|
+
time = ::Time.utc(2008, 3, 1, 6, 0)
|
24
|
+
assert_match(/марта/, I18n.l(time, :format => "%d %b %Y", :locale => :ru))
|
25
|
+
assert_match(/март /, I18n.l(time, :format => "%b %Y", :locale => :ru))
|
26
26
|
end
|
27
27
|
|
28
28
|
test "localize Date: given a format that resolves to a Proc it calls the Proc with the object" do
|
@@ -40,44 +40,57 @@ module I18n
|
|
40
40
|
test "localize DateTime: given a format that resolves to a Proc it calls the Proc with the object" do
|
41
41
|
setup_time_proc_translations
|
42
42
|
datetime = ::DateTime.new(2008, 3, 1, 6)
|
43
|
-
assert_equal '[Sat, 01 Mar 2008 06:00:00 +
|
43
|
+
assert_equal '[Sat, 01 Mar 2008 06:00:00 +00:00, {}]', I18n.l(datetime, :format => :proc, :locale => :ru)
|
44
44
|
end
|
45
45
|
|
46
46
|
test "localize DateTime: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
|
47
47
|
setup_time_proc_translations
|
48
48
|
datetime = ::DateTime.new(2008, 3, 1, 6)
|
49
|
-
assert_equal '[Sat, 01 Mar 2008 06:00:00 +
|
49
|
+
assert_equal '[Sat, 01 Mar 2008 06:00:00 +00:00, {:foo=>"foo"}]', I18n.l(datetime, :format => :proc, :foo => 'foo', :locale => :ru)
|
50
50
|
end
|
51
51
|
|
52
52
|
test "localize Time: given a format that resolves to a Proc it calls the Proc with the object" do
|
53
53
|
setup_time_proc_translations
|
54
|
-
time = ::Time.
|
55
|
-
assert_equal [time, {}]
|
54
|
+
time = ::Time.utc(2008, 3, 1, 6, 0)
|
55
|
+
assert_equal inspect_args([time, {}]), I18n.l(time, :format => :proc, :locale => :ru)
|
56
56
|
end
|
57
57
|
|
58
58
|
test "localize Time: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
|
59
59
|
setup_time_proc_translations
|
60
|
-
time
|
60
|
+
time = ::Time.utc(2008, 3, 1, 6, 0)
|
61
61
|
options = { :foo => 'foo' }
|
62
|
-
assert_equal [time, options]
|
62
|
+
assert_equal inspect_args([time, options]), I18n.l(time, options.merge(:format => :proc, :locale => :ru))
|
63
63
|
end
|
64
64
|
|
65
65
|
protected
|
66
66
|
|
67
|
-
def
|
68
|
-
args.map
|
67
|
+
def inspect_args(args)
|
68
|
+
args = args.map do |arg|
|
69
|
+
case arg
|
70
|
+
when ::Time, ::DateTime
|
71
|
+
arg.strftime('%a, %d %b %Y %H:%M:%S %Z').sub('+0000', '+00:00')
|
72
|
+
when ::Date
|
73
|
+
arg.strftime('%a, %d %b %Y')
|
74
|
+
when Hash
|
75
|
+
arg.delete(:fallback)
|
76
|
+
arg.inspect
|
77
|
+
else
|
78
|
+
arg.inspect
|
79
|
+
end
|
80
|
+
end
|
81
|
+
"[#{args.join(', ')}]"
|
69
82
|
end
|
70
83
|
|
71
84
|
def setup_time_proc_translations
|
72
85
|
I18n.backend.store_translations :ru, {
|
73
86
|
:time => {
|
74
87
|
:formats => {
|
75
|
-
:proc => lambda { |*args|
|
88
|
+
:proc => lambda { |*args| inspect_args(args) }
|
76
89
|
}
|
77
90
|
},
|
78
91
|
:date => {
|
79
92
|
:formats => {
|
80
|
-
:proc => lambda { |*args|
|
93
|
+
:proc => lambda { |*args| inspect_args(args) }
|
81
94
|
},
|
82
95
|
:'day_names' => lambda { |key, options|
|
83
96
|
(options[:format] =~ /^%A/) ?
|
@@ -7,8 +7,8 @@ module I18n
|
|
7
7
|
def setup
|
8
8
|
super
|
9
9
|
setup_time_translations
|
10
|
-
@time = ::Time.
|
11
|
-
@other_time = ::Time.
|
10
|
+
@time = ::Time.utc(2008, 3, 1, 6, 0)
|
11
|
+
@other_time = ::Time.utc(2008, 3, 1, 18, 0)
|
12
12
|
end
|
13
13
|
|
14
14
|
test "localize Time: given the short format it uses it" do
|
data/lib/i18n/version.rb
CHANGED
data/test/all.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'rubygems'
|
5
|
+
require 'active_support'
|
6
|
+
rescue LoadError
|
7
|
+
puts "not testing with Cache enabled because active_support can not be found"
|
8
|
+
end
|
9
|
+
|
10
|
+
class I18nAllFeaturesApiTest < Test::Unit::TestCase
|
11
|
+
class Backend < I18n::Backend::Simple
|
12
|
+
include I18n::Backend::Metadata
|
13
|
+
include I18n::Backend::Cache
|
14
|
+
include I18n::Backend::Cascade
|
15
|
+
include I18n::Backend::Fallbacks
|
16
|
+
include I18n::Backend::Pluralization
|
17
|
+
include I18n::Backend::Memoize
|
18
|
+
end
|
19
|
+
|
20
|
+
def setup
|
21
|
+
I18n.backend = I18n::Backend::Chain.new(Backend.new, I18n::Backend::Simple.new)
|
22
|
+
I18n.cache_store = cache_store
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
26
|
+
def teardown
|
27
|
+
I18n.cache_store.clear if I18n.cache_store
|
28
|
+
I18n.cache_store = nil
|
29
|
+
super
|
30
|
+
end
|
31
|
+
|
32
|
+
def cache_store
|
33
|
+
ActiveSupport::Cache.lookup_store(:memory_store) if cache_available?
|
34
|
+
end
|
35
|
+
|
36
|
+
def cache_available?
|
37
|
+
defined?(ActiveSupport) && defined?(ActiveSupport::Cache)
|
38
|
+
end
|
39
|
+
|
40
|
+
include I18n::Tests::Basics
|
41
|
+
include I18n::Tests::Defaults
|
42
|
+
include I18n::Tests::Interpolation
|
43
|
+
include I18n::Tests::Link
|
44
|
+
include I18n::Tests::Lookup
|
45
|
+
include I18n::Tests::Pluralization
|
46
|
+
include I18n::Tests::Procs
|
47
|
+
include I18n::Tests::Localization::Date
|
48
|
+
include I18n::Tests::Localization::DateTime
|
49
|
+
include I18n::Tests::Localization::Time
|
50
|
+
include I18n::Tests::Localization::Procs
|
51
|
+
|
52
|
+
test "make sure we use a Chain backend with an all features backend" do
|
53
|
+
assert_equal I18n::Backend::Chain, I18n.backend.class
|
54
|
+
assert_equal Backend, I18n.backend.backends.first.class
|
55
|
+
end
|
56
|
+
|
57
|
+
# links: test that keys stored on one backend can link to keys stored on another backend
|
58
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class I18nCascadeApiTest < Test::Unit::TestCase
|
4
|
+
class Backend < I18n::Backend::Simple
|
5
|
+
include I18n::Backend::Cascade
|
6
|
+
end
|
7
|
+
|
8
|
+
def setup
|
9
|
+
I18n.backend = Backend.new
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
include I18n::Tests::Basics
|
14
|
+
include I18n::Tests::Defaults
|
15
|
+
include I18n::Tests::Interpolation
|
16
|
+
include I18n::Tests::Link
|
17
|
+
include I18n::Tests::Lookup
|
18
|
+
include I18n::Tests::Pluralization
|
19
|
+
include I18n::Tests::Procs
|
20
|
+
include I18n::Tests::Localization::Date
|
21
|
+
include I18n::Tests::Localization::DateTime
|
22
|
+
include I18n::Tests::Localization::Time
|
23
|
+
include I18n::Tests::Localization::Procs
|
24
|
+
|
25
|
+
test "make sure we use a backend with Cascade included" do
|
26
|
+
assert_equal Backend, I18n.backend.class
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class I18nApiChainTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
I18n.backend = I18n::Backend::Chain.new(I18n::Backend::Simple.new, I18n.backend)
|
7
|
+
end
|
8
|
+
|
9
|
+
include I18n::Tests::Basics
|
10
|
+
include I18n::Tests::Defaults
|
11
|
+
include I18n::Tests::Interpolation
|
12
|
+
include I18n::Tests::Link
|
13
|
+
include I18n::Tests::Lookup
|
14
|
+
include I18n::Tests::Pluralization
|
15
|
+
include I18n::Tests::Procs
|
16
|
+
include I18n::Tests::Localization::Date
|
17
|
+
include I18n::Tests::Localization::DateTime
|
18
|
+
include I18n::Tests::Localization::Time
|
19
|
+
include I18n::Tests::Localization::Procs
|
20
|
+
|
21
|
+
test "make sure we use the Chain backend" do
|
22
|
+
assert_equal I18n::Backend::Chain, I18n.backend.class
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class I18nFallbacksApiTest < Test::Unit::TestCase
|
4
|
+
class Backend < I18n::Backend::Simple
|
5
|
+
include I18n::Backend::Fallbacks
|
6
|
+
end
|
7
|
+
|
8
|
+
def setup
|
9
|
+
I18n.backend = Backend.new
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
include I18n::Tests::Basics
|
14
|
+
include I18n::Tests::Defaults
|
15
|
+
include I18n::Tests::Interpolation
|
16
|
+
include I18n::Tests::Link
|
17
|
+
include I18n::Tests::Lookup
|
18
|
+
include I18n::Tests::Pluralization
|
19
|
+
include I18n::Tests::Procs
|
20
|
+
include I18n::Tests::Localization::Date
|
21
|
+
include I18n::Tests::Localization::DateTime
|
22
|
+
include I18n::Tests::Localization::Time
|
23
|
+
include I18n::Tests::Localization::Procs
|
24
|
+
|
25
|
+
test "make sure we use a backend with Fallbacks included" do
|
26
|
+
assert_equal Backend, I18n.backend.class
|
27
|
+
end
|
28
|
+
|
29
|
+
# links: test that keys stored on one backend can link to keys stored on another backend
|
30
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
I18n::Tests.setup_rufus_tokyo
|
4
|
+
|
5
|
+
class I18nKeyValueApiTest < Test::Unit::TestCase
|
6
|
+
include I18n::Tests::Basics
|
7
|
+
include I18n::Tests::Defaults
|
8
|
+
include I18n::Tests::Interpolation
|
9
|
+
include I18n::Tests::Link
|
10
|
+
include I18n::Tests::Lookup
|
11
|
+
include I18n::Tests::Pluralization
|
12
|
+
# include Tests::Api::Procs
|
13
|
+
include I18n::Tests::Localization::Date
|
14
|
+
include I18n::Tests::Localization::DateTime
|
15
|
+
include I18n::Tests::Localization::Time
|
16
|
+
# include Tests::Api::Localization::Procs
|
17
|
+
|
18
|
+
STORE = Rufus::Tokyo::Cabinet.new('*')
|
19
|
+
|
20
|
+
def setup
|
21
|
+
I18n.backend = I18n::Backend::KeyValue.new(STORE)
|
22
|
+
super
|
23
|
+
end
|
24
|
+
|
25
|
+
test "make sure we use the KeyValue backend" do
|
26
|
+
assert_equal I18n::Backend::KeyValue, I18n.backend.class
|
27
|
+
end
|
28
|
+
end if defined?(Rufus::Tokyo::Cabinet)
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class I18nMemoizeBackendWithSimpleApiTest < Test::Unit::TestCase
|
4
|
+
include I18n::Tests::Basics
|
5
|
+
include I18n::Tests::Defaults
|
6
|
+
include I18n::Tests::Interpolation
|
7
|
+
include I18n::Tests::Link
|
8
|
+
include I18n::Tests::Lookup
|
9
|
+
include I18n::Tests::Pluralization
|
10
|
+
include I18n::Tests::Procs
|
11
|
+
include I18n::Tests::Localization::Date
|
12
|
+
include I18n::Tests::Localization::DateTime
|
13
|
+
include I18n::Tests::Localization::Time
|
14
|
+
include I18n::Tests::Localization::Procs
|
15
|
+
|
16
|
+
class MemoizeBackend < I18n::Backend::Simple
|
17
|
+
include I18n::Backend::Memoize
|
18
|
+
end
|
19
|
+
|
20
|
+
def setup
|
21
|
+
I18n.backend = MemoizeBackend.new
|
22
|
+
super
|
23
|
+
end
|
24
|
+
|
25
|
+
test "make sure we use the MemoizeBackend backend" do
|
26
|
+
assert_equal MemoizeBackend, I18n.backend.class
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
I18n::Tests.setup_rufus_tokyo
|
31
|
+
|
32
|
+
class I18nMemoizeBackendWithKeyValueApiTest < Test::Unit::TestCase
|
33
|
+
include I18n::Tests::Basics
|
34
|
+
include I18n::Tests::Defaults
|
35
|
+
include I18n::Tests::Interpolation
|
36
|
+
include I18n::Tests::Link
|
37
|
+
include I18n::Tests::Lookup
|
38
|
+
include I18n::Tests::Pluralization
|
39
|
+
include I18n::Tests::Localization::Date
|
40
|
+
include I18n::Tests::Localization::DateTime
|
41
|
+
include I18n::Tests::Localization::Time
|
42
|
+
|
43
|
+
# include I18n::Tests::Procs
|
44
|
+
# include I18n::Tests::Localization::Procs
|
45
|
+
|
46
|
+
class MemoizeBackend < I18n::Backend::KeyValue
|
47
|
+
include I18n::Backend::Memoize
|
48
|
+
end
|
49
|
+
|
50
|
+
STORE = Rufus::Tokyo::Cabinet.new('*')
|
51
|
+
|
52
|
+
def setup
|
53
|
+
I18n.backend = MemoizeBackend.new(STORE)
|
54
|
+
super
|
55
|
+
end
|
56
|
+
|
57
|
+
test "make sure we use the MemoizeBackend backend" do
|
58
|
+
assert_equal MemoizeBackend, I18n.backend.class
|
59
|
+
end
|
60
|
+
end if defined?(Rufus::Tokyo::Cabinet)
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class I18nPluralizationApiTest < Test::Unit::TestCase
|
4
|
+
class Backend < I18n::Backend::Simple
|
5
|
+
include I18n::Backend::Pluralization
|
6
|
+
end
|
7
|
+
|
8
|
+
def setup
|
9
|
+
I18n.backend = Backend.new
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
include I18n::Tests::Basics
|
14
|
+
include I18n::Tests::Defaults
|
15
|
+
include I18n::Tests::Interpolation
|
16
|
+
include I18n::Tests::Link
|
17
|
+
include I18n::Tests::Lookup
|
18
|
+
include I18n::Tests::Pluralization
|
19
|
+
include I18n::Tests::Procs
|
20
|
+
include I18n::Tests::Localization::Date
|
21
|
+
include I18n::Tests::Localization::DateTime
|
22
|
+
include I18n::Tests::Localization::Time
|
23
|
+
include I18n::Tests::Localization::Procs
|
24
|
+
|
25
|
+
test "make sure we use a backend with Pluralization included" do
|
26
|
+
assert_equal Backend, I18n.backend.class
|
27
|
+
end
|
28
|
+
|
29
|
+
# links: test that keys stored on one backend can link to keys stored on another backend
|
30
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class I18nSimpleBackendApiTest < Test::Unit::TestCase
|
4
|
+
class Backend < I18n::Backend::Simple
|
5
|
+
include I18n::Backend::Pluralization
|
6
|
+
end
|
7
|
+
|
8
|
+
def setup
|
9
|
+
I18n.backend = I18n::Backend::Simple.new
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
include I18n::Tests::Basics
|
14
|
+
include I18n::Tests::Defaults
|
15
|
+
include I18n::Tests::Interpolation
|
16
|
+
include I18n::Tests::Link
|
17
|
+
include I18n::Tests::Lookup
|
18
|
+
include I18n::Tests::Pluralization
|
19
|
+
include I18n::Tests::Procs
|
20
|
+
include I18n::Tests::Localization::Date
|
21
|
+
include I18n::Tests::Localization::DateTime
|
22
|
+
include I18n::Tests::Localization::Time
|
23
|
+
include I18n::Tests::Localization::Procs
|
24
|
+
|
25
|
+
test "make sure we use the Simple backend" do
|
26
|
+
assert_equal I18n::Backend::Simple, I18n.backend.class
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'active_support'
|
5
|
+
rescue LoadError
|
6
|
+
$stderr.puts "Skipping cache tests using ActiveSupport"
|
7
|
+
else
|
8
|
+
|
9
|
+
class I18nBackendCacheTest < Test::Unit::TestCase
|
10
|
+
class Backend < I18n::Backend::Simple
|
11
|
+
include I18n::Backend::Cache
|
12
|
+
end
|
13
|
+
|
14
|
+
def setup
|
15
|
+
I18n.backend = Backend.new
|
16
|
+
super
|
17
|
+
I18n.cache_store = ActiveSupport::Cache.lookup_store(:memory_store)
|
18
|
+
end
|
19
|
+
|
20
|
+
def teardown
|
21
|
+
I18n.cache_store = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
test "it uses the cache" do
|
25
|
+
assert I18n.cache_store.is_a?(ActiveSupport::Cache::MemoryStore)
|
26
|
+
end
|
27
|
+
|
28
|
+
test "translate hits the backend and caches the response" do
|
29
|
+
I18n.backend.expects(:lookup).returns('Foo')
|
30
|
+
assert_equal 'Foo', I18n.t(:foo)
|
31
|
+
|
32
|
+
I18n.backend.expects(:lookup).never
|
33
|
+
assert_equal 'Foo', I18n.t(:foo)
|
34
|
+
|
35
|
+
I18n.backend.expects(:lookup).returns('Bar')
|
36
|
+
assert_equal 'Bar', I18n.t(:bar)
|
37
|
+
end
|
38
|
+
|
39
|
+
test "still raises MissingTranslationData but also caches it" do
|
40
|
+
I18n.backend.expects(:lookup).returns(nil)
|
41
|
+
assert_raise(I18n::MissingTranslationData) { I18n.t(:missing, :raise => true) }
|
42
|
+
|
43
|
+
I18n.cache_store.expects(:write).never
|
44
|
+
I18n.backend.expects(:lookup).never
|
45
|
+
assert_raise(I18n::MissingTranslationData) { I18n.t(:missing, :raise => true) }
|
46
|
+
end
|
47
|
+
|
48
|
+
test "uses 'i18n' as a cache key namespace by default" do
|
49
|
+
assert_equal 0, I18n.backend.send(:cache_key, :en, :foo, {}).index('i18n')
|
50
|
+
end
|
51
|
+
|
52
|
+
test "adds a custom cache key namespace" do
|
53
|
+
with_cache_namespace('bar') do
|
54
|
+
assert_equal 0, I18n.backend.send(:cache_key, :en, :foo, {}).index('i18n/bar/')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
test "adds locale and hash of key and hash of options" do
|
59
|
+
options = { :bar=>1 }
|
60
|
+
options_hash = I18n::Backend::Cache::USE_INSPECT_HASH ? options.inspect.hash : options.hash
|
61
|
+
assert_equal "i18n//en/#{:foo.hash}/#{options_hash}", I18n.backend.send(:cache_key, :en, :foo, options)
|
62
|
+
end
|
63
|
+
|
64
|
+
test "keys should not be equal" do
|
65
|
+
interpolation_values1 = { :foo => 1, :bar => 2 }
|
66
|
+
interpolation_values2 = { :foo => 2, :bar => 1 }
|
67
|
+
|
68
|
+
key1 = I18n.backend.send(:cache_key, :en, :some_key, interpolation_values1)
|
69
|
+
key2 = I18n.backend.send(:cache_key, :en, :some_key, interpolation_values2)
|
70
|
+
|
71
|
+
assert key1 != key2
|
72
|
+
end
|
73
|
+
|
74
|
+
protected
|
75
|
+
|
76
|
+
def with_cache_namespace(namespace)
|
77
|
+
I18n.cache_namespace = namespace
|
78
|
+
yield
|
79
|
+
I18n.cache_namespace = nil
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end # AS cache check
|