sayso-i18n 0.5.0.001
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.textile +152 -0
- data/MIT-LICENSE +20 -0
- data/README.textile +103 -0
- data/ci/Gemfile.no-rails +5 -0
- data/ci/Gemfile.no-rails.lock +14 -0
- data/ci/Gemfile.rails-2.3.x +9 -0
- data/ci/Gemfile.rails-2.3.x.lock +23 -0
- data/ci/Gemfile.rails-3.x +9 -0
- data/ci/Gemfile.rails-3.x.lock +23 -0
- data/lib/i18n.rb +324 -0
- data/lib/i18n/backend.rb +19 -0
- data/lib/i18n/backend/base.rb +174 -0
- data/lib/i18n/backend/cache.rb +102 -0
- data/lib/i18n/backend/cascade.rb +53 -0
- data/lib/i18n/backend/chain.rb +80 -0
- data/lib/i18n/backend/fallbacks.rb +70 -0
- data/lib/i18n/backend/flatten.rb +113 -0
- data/lib/i18n/backend/flatten_yml.rb +70 -0
- data/lib/i18n/backend/gettext.rb +71 -0
- data/lib/i18n/backend/interpolation_compiler.rb +121 -0
- data/lib/i18n/backend/key_value.rb +100 -0
- data/lib/i18n/backend/memoize.rb +46 -0
- data/lib/i18n/backend/metadata.rb +65 -0
- data/lib/i18n/backend/pluralization.rb +55 -0
- data/lib/i18n/backend/simple.rb +87 -0
- data/lib/i18n/backend/transliterator.rb +98 -0
- data/lib/i18n/config.rb +86 -0
- data/lib/i18n/core_ext/hash.rb +29 -0
- data/lib/i18n/core_ext/kernel/surpress_warnings.rb +9 -0
- data/lib/i18n/core_ext/string/interpolate.rb +105 -0
- data/lib/i18n/exceptions.rb +88 -0
- data/lib/i18n/gettext.rb +25 -0
- data/lib/i18n/gettext/helpers.rb +64 -0
- data/lib/i18n/gettext/po_parser.rb +329 -0
- data/lib/i18n/interpolate/ruby.rb +31 -0
- data/lib/i18n/locale.rb +6 -0
- data/lib/i18n/locale/fallbacks.rb +96 -0
- data/lib/i18n/locale/tag.rb +28 -0
- data/lib/i18n/locale/tag/parents.rb +22 -0
- data/lib/i18n/locale/tag/rfc4646.rb +74 -0
- data/lib/i18n/locale/tag/simple.rb +39 -0
- data/lib/i18n/tests.rb +12 -0
- data/lib/i18n/tests/basics.rb +54 -0
- data/lib/i18n/tests/defaults.rb +40 -0
- data/lib/i18n/tests/interpolation.rb +133 -0
- data/lib/i18n/tests/link.rb +56 -0
- data/lib/i18n/tests/localization.rb +19 -0
- data/lib/i18n/tests/localization/date.rb +84 -0
- data/lib/i18n/tests/localization/date_time.rb +77 -0
- data/lib/i18n/tests/localization/procs.rb +116 -0
- data/lib/i18n/tests/localization/time.rb +76 -0
- data/lib/i18n/tests/lookup.rb +74 -0
- data/lib/i18n/tests/pluralization.rb +35 -0
- data/lib/i18n/tests/procs.rb +55 -0
- data/lib/i18n/version.rb +3 -0
- 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/flatten_yml_test.rb +32 -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 +72 -0
- data/test/backend/exceptions_test.rb +23 -0
- data/test/backend/fallbacks_test.rb +120 -0
- data/test/backend/flatten_yml_test.rb +49 -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 +83 -0
- data/test/backend/transliterator_test.rb +81 -0
- data/test/core_ext/hash_test.rb +30 -0
- data/test/core_ext/string/interpolate_test.rb +99 -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 +61 -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 +194 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module I18n
|
4
|
+
module Tests
|
5
|
+
module Pluralization
|
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)
|
8
|
+
end
|
9
|
+
|
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)
|
12
|
+
end
|
13
|
+
|
14
|
+
test "pluralization: given 1 it returns the singular translation" do
|
15
|
+
assert_equal 'bar', I18n.t(:default => { :one => 'bar' }, :count => 1)
|
16
|
+
end
|
17
|
+
|
18
|
+
test "pluralization: given 2 it returns the :other translation" do
|
19
|
+
assert_equal 'bars', I18n.t(:default => { :other => 'bars' }, :count => 2)
|
20
|
+
end
|
21
|
+
|
22
|
+
test "pluralization: given 3 it returns the :other translation" do
|
23
|
+
assert_equal 'bars', I18n.t(:default => { :other => 'bars' }, :count => 3)
|
24
|
+
end
|
25
|
+
|
26
|
+
test "pluralization: given nil it returns the whole entry" do
|
27
|
+
assert_equal({ :one => 'bar' }, I18n.t(:default => { :one => 'bar' }, :count => nil))
|
28
|
+
end
|
29
|
+
|
30
|
+
test "pluralization: given incomplete pluralization data it raises I18n::InvalidPluralizationData" do
|
31
|
+
assert_raise(I18n::InvalidPluralizationData) { I18n.t(:default => { :one => 'bar' }, :count => 2) }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module I18n
|
4
|
+
module Tests
|
5
|
+
module Procs
|
6
|
+
test "lookup: given a translation is a proc it calls the proc with the key and interpolation values" do
|
7
|
+
I18n.backend.store_translations(:en, :a_lambda => lambda { |*args| filter_args(*args) })
|
8
|
+
assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(:a_lambda, :foo => 'foo')
|
9
|
+
end
|
10
|
+
|
11
|
+
test "defaults: given a default is a Proc it calls it with the key and interpolation values" do
|
12
|
+
proc = lambda { |*args| filter_args(*args) }
|
13
|
+
assert_equal '[nil, {:foo=>"foo"}]', I18n.t(nil, :default => proc, :foo => 'foo')
|
14
|
+
end
|
15
|
+
|
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
|
+
I18n.backend.store_translations(:en, :a_lambda => lambda { |*args| filter_args(*args) })
|
18
|
+
assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(nil, :default => :a_lambda, :foo => 'foo')
|
19
|
+
assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(nil, :default => [nil, :a_lambda], :foo => 'foo')
|
20
|
+
end
|
21
|
+
|
22
|
+
test "interpolation: given an interpolation value is a lambda it calls it with key and values before interpolating it" do
|
23
|
+
proc = lambda { |*args| filter_args(*args) }
|
24
|
+
assert_match %r(\[\{:foo=>#<Proc.*>\}\]), I18n.t(nil, :default => '%{foo}', :foo => proc)
|
25
|
+
end
|
26
|
+
|
27
|
+
test "interpolation: given a key resolves to a Proc that returns a string then interpolation still works" do
|
28
|
+
proc = lambda { |*args| "%{foo}: " + filter_args(*args) }
|
29
|
+
assert_equal 'foo: [nil, {:foo=>"foo"}]', I18n.t(nil, :default => proc, :foo => 'foo')
|
30
|
+
end
|
31
|
+
|
32
|
+
test "pluralization: given a key resolves to a Proc that returns valid data then pluralization still works" do
|
33
|
+
proc = lambda { |*args| { :zero => 'zero', :one => 'one', :other => 'other' } }
|
34
|
+
assert_equal 'zero', I18n.t(:default => proc, :count => 0)
|
35
|
+
assert_equal 'one', I18n.t(:default => proc, :count => 1)
|
36
|
+
assert_equal 'other', I18n.t(:default => proc, :count => 2)
|
37
|
+
end
|
38
|
+
|
39
|
+
test "lookup: given the option :resolve => false was passed it does not resolve proc translations" do
|
40
|
+
I18n.backend.store_translations(:en, :a_lambda => lambda { |*args| filter_args(*args) })
|
41
|
+
assert_equal Proc, I18n.t(:a_lambda, :resolve => false).class
|
42
|
+
end
|
43
|
+
|
44
|
+
test "lookup: given the option :resolve => false was passed it does not resolve proc default" do
|
45
|
+
assert_equal Proc, I18n.t(nil, :default => lambda { |*args| filter_args(*args) }, :resolve => false).class
|
46
|
+
end
|
47
|
+
|
48
|
+
protected
|
49
|
+
|
50
|
+
def filter_args(*args)
|
51
|
+
args.map {|arg| arg.delete(:fallback) if arg.is_a?(Hash) ; arg }.inspect
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/i18n/version.rb
ADDED
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,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
|
3
|
+
require 'test_helper'
|
4
|
+
require 'api'
|
5
|
+
|
6
|
+
class I18nFlattenYmlBackendApiTest < Test::Unit::TestCase
|
7
|
+
include Tests::Api::Basics
|
8
|
+
include Tests::Api::Defaults
|
9
|
+
include Tests::Api::Interpolation
|
10
|
+
include Tests::Api::Link
|
11
|
+
include Tests::Api::Lookup
|
12
|
+
include Tests::Api::Pluralization
|
13
|
+
include Tests::Api::Procs
|
14
|
+
include Tests::Api::Localization::Date
|
15
|
+
include Tests::Api::Localization::DateTime
|
16
|
+
include Tests::Api::Localization::Time
|
17
|
+
include Tests::Api::Localization::Procs
|
18
|
+
|
19
|
+
class FlattenYmlBackend
|
20
|
+
include I18n::Backend::Base
|
21
|
+
include I18n::Backend::FlattenYml
|
22
|
+
end
|
23
|
+
|
24
|
+
def setup
|
25
|
+
I18n.backend = FlattenYmlBackend.new
|
26
|
+
super
|
27
|
+
end
|
28
|
+
|
29
|
+
test "make sure we use the FlattenYmlBackend backend" do
|
30
|
+
assert_equal FlattenYmlBackend, I18n.backend.class
|
31
|
+
end
|
32
|
+
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
|