i18n 0.5.0 → 0.5.2
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/CHANGELOG.textile +3 -12
- data/README.textile +17 -4
- data/lib/i18n.rb +37 -5
- data/lib/i18n/backend.rb +1 -0
- data/lib/i18n/backend/base.rb +32 -4
- data/lib/i18n/backend/cldr.rb +99 -0
- 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 +13 -1
- data/lib/i18n/core_ext/string/interpolate.rb +0 -9
- data/lib/i18n/exceptions.rb +31 -3
- data/lib/i18n/locale/fallbacks.rb +3 -3
- data/lib/i18n/tests/localization/procs.rb +24 -25
- data/lib/i18n/version.rb +1 -1
- metadata +16 -121
- data/ci/Gemfile.no-rails +0 -5
- data/ci/Gemfile.no-rails.lock +0 -14
- data/ci/Gemfile.rails-2.3.x +0 -9
- data/ci/Gemfile.rails-2.3.x.lock +0 -23
- data/ci/Gemfile.rails-3.x +0 -9
- data/ci/Gemfile.rails-3.x.lock +0 -23
- data/lib/i18n/core_ext/kernel/surpress_warnings.rb +0 -9
- data/lib/i18n/interpolate/ruby.rb +0 -31
- data/test/all.rb +0 -8
- 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 -28
- data/test/api/memoize_test.rb +0 -60
- data/test/api/pluralization_test.rb +0 -30
- data/test/api/simple_test.rb +0 -28
- data/test/backend/cache_test.rb +0 -83
- data/test/backend/cascade_test.rb +0 -85
- data/test/backend/chain_test.rb +0 -67
- data/test/backend/exceptions_test.rb +0 -23
- data/test/backend/fallbacks_test.rb +0 -116
- data/test/backend/interpolation_compiler_test.rb +0 -102
- data/test/backend/key_value_test.rb +0 -46
- data/test/backend/memoize_test.rb +0 -47
- data/test/backend/metadata_test.rb +0 -67
- data/test/backend/pluralization_test.rb +0 -44
- data/test/backend/simple_test.rb +0 -79
- data/test/backend/transliterator_test.rb +0 -81
- data/test/core_ext/hash_test.rb +0 -30
- data/test/core_ext/string/interpolate_test.rb +0 -99
- data/test/gettext/api_test.rb +0 -206
- data/test/gettext/backend_test.rb +0 -93
- data/test/i18n/exceptions_test.rb +0 -116
- data/test/i18n/interpolate_test.rb +0 -61
- data/test/i18n/load_path_test.rb +0 -26
- data/test/i18n_test.rb +0 -236
- data/test/locale/fallbacks_test.rb +0 -124
- data/test/locale/tag/rfc4646_test.rb +0 -142
- data/test/locale/tag/simple_test.rb +0 -32
- data/test/run_all.rb +0 -21
- data/test/test_data/locales/de.po +0 -72
- data/test/test_data/locales/en.rb +0 -3
- data/test/test_data/locales/en.yml +0 -3
- data/test/test_data/locales/invalid/empty.yml +0 -1
- data/test/test_data/locales/plurals.rb +0 -113
- data/test/test_helper.rb +0 -56
data/test/backend/chain_test.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class I18nBackendChainTest < Test::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
@first = backend(:en => {
|
6
|
-
:foo => 'Foo', :formats => { :short => 'short' }, :plural_1 => { :one => '%{count}' }
|
7
|
-
})
|
8
|
-
@second = backend(:en => {
|
9
|
-
:bar => 'Bar', :formats => { :long => 'long' }, :plural_2 => { :one => 'one' }
|
10
|
-
})
|
11
|
-
@chain = I18n.backend = I18n::Backend::Chain.new(@first, @second)
|
12
|
-
end
|
13
|
-
|
14
|
-
test "looks up translations from the first chained backend" do
|
15
|
-
assert_equal 'Foo', @first.send(:translations)[:en][:foo]
|
16
|
-
assert_equal 'Foo', I18n.t(:foo)
|
17
|
-
end
|
18
|
-
|
19
|
-
test "looks up translations from the second chained backend" do
|
20
|
-
assert_equal 'Bar', @second.send(:translations)[:en][:bar]
|
21
|
-
assert_equal 'Bar', I18n.t(:bar)
|
22
|
-
end
|
23
|
-
|
24
|
-
test "defaults only apply to lookups on the last backend in the chain" do
|
25
|
-
assert_equal 'Foo', I18n.t(:foo, :default => 'Bah')
|
26
|
-
assert_equal 'Bar', I18n.t(:bar, :default => 'Bah')
|
27
|
-
assert_equal 'Bah', I18n.t(:bah, :default => 'Bah') # default kicks in only here
|
28
|
-
end
|
29
|
-
|
30
|
-
test "default" do
|
31
|
-
assert_equal 'Fuh', I18n.t(:default => 'Fuh')
|
32
|
-
assert_equal 'Zero', I18n.t(:default => { :zero => 'Zero' }, :count => 0)
|
33
|
-
assert_equal({ :zero => 'Zero' }, I18n.t(:default => { :zero => 'Zero' }))
|
34
|
-
assert_equal 'Foo', I18n.t(:default => :foo)
|
35
|
-
end
|
36
|
-
|
37
|
-
test 'default is returned if translation is missing' do
|
38
|
-
assert_equal({}, I18n.t(:'i18n.transliterate.rule', :locale => 'en', :default => {}))
|
39
|
-
end
|
40
|
-
|
41
|
-
test "namespace lookup collects results from all backends" do
|
42
|
-
assert_equal({ :short => 'short', :long => 'long' }, I18n.t(:formats))
|
43
|
-
end
|
44
|
-
|
45
|
-
test "namespace lookup with only the first backend returning a result" do
|
46
|
-
assert_equal({ :one => '%{count}' }, I18n.t(:plural_1))
|
47
|
-
end
|
48
|
-
|
49
|
-
test "pluralization still works" do
|
50
|
-
assert_equal '1', I18n.t(:plural_1, :count => 1)
|
51
|
-
assert_equal 'one', I18n.t(:plural_2, :count => 1)
|
52
|
-
end
|
53
|
-
|
54
|
-
test "bulk lookup collects results from all backends" do
|
55
|
-
assert_equal ['Foo', 'Bar'], I18n.t([:foo, :bar])
|
56
|
-
assert_equal ['Foo', 'Bar', 'Bah'], I18n.t([:foo, :bar, :bah], :default => 'Bah')
|
57
|
-
assert_equal [{ :short => 'short', :long => 'long' }, { :one => 'one' }, 'Bah'], I18n.t([:formats, :plural_2, :bah], :default => 'Bah')
|
58
|
-
end
|
59
|
-
|
60
|
-
protected
|
61
|
-
|
62
|
-
def backend(translations)
|
63
|
-
backend = I18n::Backend::Simple.new
|
64
|
-
translations.each { |locale, data| backend.store_translations(locale, data) }
|
65
|
-
backend
|
66
|
-
end
|
67
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class I18nBackendExceptionsTest < Test::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
I18n.backend = I18n::Backend::Simple.new
|
6
|
-
end
|
7
|
-
|
8
|
-
test "exceptions: MissingTranslationData message from #translate includes the given scope and full key" do
|
9
|
-
begin
|
10
|
-
I18n.t(:'baz.missing', :scope => :'foo.bar', :raise => true)
|
11
|
-
rescue I18n::MissingTranslationData => exception
|
12
|
-
end
|
13
|
-
assert_equal "translation missing: en.foo.bar.baz.missing", exception.message
|
14
|
-
end
|
15
|
-
|
16
|
-
test "exceptions: MissingTranslationData message from #localize includes the given scope and full key" do
|
17
|
-
begin
|
18
|
-
I18n.l(Time.now, :format => :foo)
|
19
|
-
rescue I18n::MissingTranslationData => exception
|
20
|
-
end
|
21
|
-
assert_equal "translation missing: en.time.formats.foo", exception.message
|
22
|
-
end
|
23
|
-
end
|
@@ -1,116 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class I18nBackendFallbacksTranslateTest < 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
|
-
store_translations(:en, :foo => 'Foo in :en', :bar => 'Bar in :en', :buz => 'Buz in :en')
|
11
|
-
store_translations(:de, :bar => 'Bar in :de', :baz => 'Baz in :de')
|
12
|
-
store_translations(:'de-DE', :baz => 'Baz in :de-DE')
|
13
|
-
end
|
14
|
-
|
15
|
-
test "still returns an existing translation as usual" do
|
16
|
-
assert_equal 'Foo in :en', I18n.t(:foo, :locale => :en)
|
17
|
-
assert_equal 'Bar in :de', I18n.t(:bar, :locale => :de)
|
18
|
-
assert_equal 'Baz in :de-DE', I18n.t(:baz, :locale => :'de-DE')
|
19
|
-
end
|
20
|
-
|
21
|
-
test "returns the :en translation for a missing :de translation" do
|
22
|
-
assert_equal 'Foo in :en', I18n.t(:foo, :locale => :de)
|
23
|
-
end
|
24
|
-
|
25
|
-
test "returns the :de translation for a missing :'de-DE' translation" do
|
26
|
-
assert_equal 'Bar in :de', I18n.t(:bar, :locale => :'de-DE')
|
27
|
-
end
|
28
|
-
|
29
|
-
test "returns the :en translation for translation missing in both :de and :'de-De'" do
|
30
|
-
assert_equal 'Buz in :en', I18n.t(:buz, :locale => :'de-DE')
|
31
|
-
end
|
32
|
-
|
33
|
-
test "returns the :de translation for a missing :'de-DE' when :default is a String" do
|
34
|
-
assert_equal 'Bar in :de', I18n.t(:bar, :locale => :'de-DE', :default => "Default Bar")
|
35
|
-
assert_equal "Default Bar", I18n.t(:missing_bar, :locale => :'de-DE', :default => "Default Bar")
|
36
|
-
end
|
37
|
-
|
38
|
-
test "returns the :de translation for a missing :'de-DE' when defaults is a Symbol (which exists in :en)" do
|
39
|
-
assert_equal "Bar in :de", I18n.t(:bar, :locale => :'de-DE', :default => [:buz])
|
40
|
-
end
|
41
|
-
|
42
|
-
test "returns the :'de-DE' default :baz translation for a missing :'de-DE' (which exists in :de)" do
|
43
|
-
assert_equal "Baz in :de-DE", I18n.t(:bar, :locale => :'de-DE', :default => [:baz])
|
44
|
-
end
|
45
|
-
|
46
|
-
test "returns the :de translation for a missing :'de-DE' when :default is a Proc" do
|
47
|
-
assert_equal 'Bar in :de', I18n.t(:bar, :locale => :'de-DE', :default => Proc.new { "Default Bar" })
|
48
|
-
assert_equal "Default Bar", I18n.t(:missing_bar, :locale => :'de-DE', :default => Proc.new { "Default Bar" })
|
49
|
-
end
|
50
|
-
|
51
|
-
test "returns the :'de-DE' default :baz translation for a missing :'de-DE' when defaults contains Symbol" do
|
52
|
-
assert_equal 'Baz in :de-DE', I18n.t(:missing_foo, :locale => :'de-DE', :default => [:baz, "Default Bar"])
|
53
|
-
end
|
54
|
-
|
55
|
-
test "returns the defaults translation for a missing :'de-DE' when defaults contains a String or Proc before Symbol" do
|
56
|
-
assert_equal "Default Bar", I18n.t(:missing_foo, :locale => :'de-DE', :default => [:missing_bar, "Default Bar", :baz])
|
57
|
-
assert_equal "Default Bar", I18n.t(:missing_foo, :locale => :'de-DE', :default => [:missing_bar, Proc.new { "Default Bar" }, :baz])
|
58
|
-
end
|
59
|
-
|
60
|
-
test "returns the default translation for a missing :'de-DE' and existing :de when default is a Hash" do
|
61
|
-
assert_equal 'Default 6 Bars', I18n.t(:missing_foo, :locale => :'de-DE', :default => [:missing_bar, {:other => "Default %{count} Bars"}, "Default Bar"], :count => 6)
|
62
|
-
end
|
63
|
-
|
64
|
-
test "raises I18n::MissingTranslationData exception when no translation was found" do
|
65
|
-
assert_raise(I18n::MissingTranslationData) { I18n.t(:faa, :locale => :en, :raise => true) }
|
66
|
-
assert_raise(I18n::MissingTranslationData) { I18n.t(:faa, :locale => :de, :raise => true) }
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
class I18nBackendFallbacksLocalizeTest < Test::Unit::TestCase
|
71
|
-
class Backend < I18n::Backend::Simple
|
72
|
-
include I18n::Backend::Fallbacks
|
73
|
-
end
|
74
|
-
|
75
|
-
def setup
|
76
|
-
I18n.backend = Backend.new
|
77
|
-
store_translations(:en, :date => { :formats => { :en => 'en' }, :day_names => %w(Sunday) })
|
78
|
-
store_translations(:de, :date => { :formats => { :de => 'de' } })
|
79
|
-
end
|
80
|
-
|
81
|
-
test "still uses an existing format as usual" do
|
82
|
-
assert_equal 'en', I18n.l(Date.today, :format => :en, :locale => :en)
|
83
|
-
end
|
84
|
-
|
85
|
-
test "looks up and uses a fallback locale's format for a key missing in the given locale (1)" do
|
86
|
-
assert_equal 'en', I18n.l(Date.today, :format => :en, :locale => :de)
|
87
|
-
end
|
88
|
-
|
89
|
-
test "looks up and uses a fallback locale's format for a key missing in the given locale (2)" do
|
90
|
-
assert_equal 'de', I18n.l(Date.today, :format => :de, :locale => :'de-DE')
|
91
|
-
end
|
92
|
-
|
93
|
-
test "still uses an existing day name translation as usual" do
|
94
|
-
assert_equal 'Sunday', I18n.l(Date.new(2010, 1, 3), :format => '%A', :locale => :en)
|
95
|
-
end
|
96
|
-
|
97
|
-
test "uses a fallback locale's translation for a key missing in the given locale" do
|
98
|
-
assert_equal 'Sunday', I18n.l(Date.new(2010, 1, 3), :format => '%A', :locale => :de)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
class I18nBackendFallbacksWithChainTest < Test::Unit::TestCase
|
103
|
-
class Backend < I18n::Backend::Simple
|
104
|
-
include I18n::Backend::Fallbacks
|
105
|
-
end
|
106
|
-
|
107
|
-
def setup
|
108
|
-
backend = Backend.new
|
109
|
-
backend.store_translations(:de, :foo => 'FOO')
|
110
|
-
I18n.backend = I18n::Backend::Chain.new(I18n::Backend::Simple.new, backend)
|
111
|
-
end
|
112
|
-
|
113
|
-
test "falls back from de-DE to de when there is no translation for de-DE available" do
|
114
|
-
assert_equal 'FOO', I18n.t(:foo, :locale => :'de-DE')
|
115
|
-
end
|
116
|
-
end
|
@@ -1,102 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class InterpolationCompilerTest < Test::Unit::TestCase
|
4
|
-
Compiler = I18n::Backend::InterpolationCompiler::Compiler
|
5
|
-
|
6
|
-
def compile_and_interpolate(str, values = {})
|
7
|
-
Compiler.compile_if_an_interpolation(str).i18n_interpolate(values)
|
8
|
-
end
|
9
|
-
|
10
|
-
def assert_escapes_interpolation_key(expected, malicious_str)
|
11
|
-
assert_equal(expected, Compiler.send(:escape_key_sym, malicious_str))
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_escape_key_properly_escapes
|
15
|
-
assert_escapes_interpolation_key ':"\""', '"'
|
16
|
-
assert_escapes_interpolation_key ':"\\\\"', '\\'
|
17
|
-
assert_escapes_interpolation_key ':"\\\\\""', '\\"'
|
18
|
-
assert_escapes_interpolation_key ':"\#{}"', '#{}'
|
19
|
-
assert_escapes_interpolation_key ':"\\\\\#{}"', '\#{}'
|
20
|
-
end
|
21
|
-
|
22
|
-
def assert_escapes_plain_string(expected, plain_str)
|
23
|
-
assert_equal expected, Compiler.send(:escape_plain_str, plain_str)
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_escape_plain_string_properly_escapes
|
27
|
-
assert_escapes_plain_string '\\"', '"'
|
28
|
-
assert_escapes_plain_string '\'', '\''
|
29
|
-
assert_escapes_plain_string '\\#', '#'
|
30
|
-
assert_escapes_plain_string '\\#{}', '#{}'
|
31
|
-
assert_escapes_plain_string '\\\\\\"','\\"'
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_non_interpolated_strings_or_arrays_dont_get_compiled
|
35
|
-
['abc', '\\{a}}', '{a}}', []].each do |obj|
|
36
|
-
Compiler.compile_if_an_interpolation(obj)
|
37
|
-
assert_equal false, obj.respond_to?(:i18n_interpolate)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_interpolated_string_gets_compiled
|
42
|
-
assert_equal '-A-', compile_and_interpolate('-%{a}-', :a => 'A')
|
43
|
-
end
|
44
|
-
|
45
|
-
def assert_handles_key(str, key)
|
46
|
-
assert_equal 'A', compile_and_interpolate(str, key => 'A')
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_compiles_fancy_keys
|
50
|
-
assert_handles_key('%{\}', :'\\' )
|
51
|
-
assert_handles_key('%{#}', :'#' )
|
52
|
-
assert_handles_key('%{#{}', :'#{' )
|
53
|
-
assert_handles_key('%{#$SAFE}', :'#$SAFE')
|
54
|
-
assert_handles_key('%{\000}', :'\000' )
|
55
|
-
assert_handles_key('%{\'}', :'\'' )
|
56
|
-
assert_handles_key('%{\'\'}', :'\'\'' )
|
57
|
-
assert_handles_key('%{a.b}', :'a.b' )
|
58
|
-
assert_handles_key('%{ }', :' ' )
|
59
|
-
assert_handles_key('%{:}', :':' )
|
60
|
-
assert_handles_key("%{:''}", :":''" )
|
61
|
-
assert_handles_key('%{:"}', :':"' )
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_str_containing_only_escaped_interpolation_is_handled_correctly
|
65
|
-
assert_equal 'abc %{x}', compile_and_interpolate('abc %%{x}')
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_handles_weird_strings
|
69
|
-
assert_equal '#{} a', compile_and_interpolate('#{} %{a}', :a => 'a')
|
70
|
-
assert_equal '"#{abc}"', compile_and_interpolate('"#{ab%{a}c}"', :a => '' )
|
71
|
-
assert_equal 'a}', compile_and_interpolate('%{{a}}', :'{a' => 'a')
|
72
|
-
assert_equal '"', compile_and_interpolate('"%{a}', :a => '' )
|
73
|
-
assert_equal 'a%{a}', compile_and_interpolate('%{a}%%{a}', :a => 'a')
|
74
|
-
assert_equal '%%{a}', compile_and_interpolate('%%%{a}')
|
75
|
-
assert_equal '\";eval("a")', compile_and_interpolate('\";eval("%{a}")', :a => 'a')
|
76
|
-
assert_equal '\";eval("a")', compile_and_interpolate('\";eval("a")%{a}', :a => '' )
|
77
|
-
assert_equal "\na", compile_and_interpolate("\n%{a}", :a => 'a')
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
class I18nBackendInterpolationCompilerTest < Test::Unit::TestCase
|
82
|
-
class Backend < I18n::Backend::Simple
|
83
|
-
include I18n::Backend::InterpolationCompiler
|
84
|
-
end
|
85
|
-
|
86
|
-
include I18n::Tests::Interpolation
|
87
|
-
|
88
|
-
def setup
|
89
|
-
I18n.backend = Backend.new
|
90
|
-
super
|
91
|
-
end
|
92
|
-
|
93
|
-
# pre-compile default strings to make sure we are testing I18n::Backend::InterpolationCompiler
|
94
|
-
def interpolate(*args)
|
95
|
-
options = args.last.kind_of?(Hash) ? args.last : {}
|
96
|
-
if default_str = options[:default]
|
97
|
-
I18n::Backend::InterpolationCompiler::Compiler.compile_if_an_interpolation(default_str)
|
98
|
-
end
|
99
|
-
super
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
I18n::Tests.setup_rufus_tokyo
|
4
|
-
|
5
|
-
class I18nBackendKeyValueTest < Test::Unit::TestCase
|
6
|
-
def setup_backend!(subtree=true)
|
7
|
-
I18n.backend = I18n::Backend::KeyValue.new(Rufus::Tokyo::Cabinet.new('*'), subtree)
|
8
|
-
store_translations(:en, :foo => { :bar => 'bar', :baz => 'baz' })
|
9
|
-
end
|
10
|
-
|
11
|
-
def assert_flattens(expected, nested, escape=true, subtree=true)
|
12
|
-
assert_equal expected, I18n.backend.flatten_translations("en", nested, escape, subtree)
|
13
|
-
end
|
14
|
-
|
15
|
-
test "hash flattening works" do
|
16
|
-
setup_backend!
|
17
|
-
assert_flattens(
|
18
|
-
{:a=>'a', :b=>{:c=>'c', :d=>'d', :f=>{:x=>'x'}}, :"b.f" => {:x=>"x"}, :"b.c"=>"c", :"b.f.x"=>"x", :"b.d"=>"d"},
|
19
|
-
{:a=>'a', :b=>{:c=>'c', :d=>'d', :f=>{:x=>'x'}}}
|
20
|
-
)
|
21
|
-
assert_flattens({:a=>{:b =>['a', 'b']}, :"a.b"=>['a', 'b']}, {:a=>{:b =>['a', 'b']}})
|
22
|
-
assert_flattens({:"a\001b" => "c"}, {:"a.b" => "c"})
|
23
|
-
assert_flattens({:"a.b"=>['a', 'b']}, {:a=>{:b =>['a', 'b']}}, true, false)
|
24
|
-
assert_flattens({:"a.b" => "c"}, {:"a.b" => "c"}, false)
|
25
|
-
end
|
26
|
-
|
27
|
-
test "store_translations handle subtrees by default" do
|
28
|
-
setup_backend!
|
29
|
-
assert_equal({ :bar => 'bar', :baz => 'baz' }, I18n.t("foo"))
|
30
|
-
end
|
31
|
-
|
32
|
-
test "store_translations merge subtrees accordingly" do
|
33
|
-
setup_backend!
|
34
|
-
store_translations(:en, :foo => { :baz => "BAZ"})
|
35
|
-
assert_equal('BAZ', I18n.t("foo.baz"))
|
36
|
-
assert_equal({ :bar => 'bar', :baz => 'BAZ' }, I18n.t("foo"))
|
37
|
-
end
|
38
|
-
|
39
|
-
test "store_translations does not handle subtrees if desired" do
|
40
|
-
setup_backend!(false)
|
41
|
-
assert_raise I18n::MissingTranslationData do
|
42
|
-
I18n.t("foo", :raise => true)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
end if defined?(Rufus::Tokyo::Cabinet)
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
require 'backend/simple_test'
|
4
|
-
|
5
|
-
class I18nBackendMemoizeTest < I18nBackendSimpleTest
|
6
|
-
module MemoizeSpy
|
7
|
-
attr_accessor :spy_calls
|
8
|
-
|
9
|
-
def available_locales
|
10
|
-
self.spy_calls = (self.spy_calls || 0) + 1
|
11
|
-
super
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
class MemoizeBackend < I18n::Backend::Simple
|
16
|
-
include MemoizeSpy
|
17
|
-
include I18n::Backend::Memoize
|
18
|
-
end
|
19
|
-
|
20
|
-
def setup
|
21
|
-
super
|
22
|
-
I18n.backend = MemoizeBackend.new
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_memoizes_available_locales
|
26
|
-
I18n.backend.spy_calls = 0
|
27
|
-
assert_equal I18n.available_locales, I18n.available_locales
|
28
|
-
assert_equal 1, I18n.backend.spy_calls
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_resets_available_locales_on_reload!
|
32
|
-
I18n.available_locales
|
33
|
-
I18n.backend.spy_calls = 0
|
34
|
-
I18n.reload!
|
35
|
-
assert_equal I18n.available_locales, I18n.available_locales
|
36
|
-
assert_equal 1, I18n.backend.spy_calls
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_resets_available_locales_on_store_translations
|
40
|
-
I18n.available_locales
|
41
|
-
I18n.backend.spy_calls = 0
|
42
|
-
I18n.backend.store_translations(:copa, :ca => :bana)
|
43
|
-
assert_equal I18n.available_locales, I18n.available_locales
|
44
|
-
assert I18n.available_locales.include?(:copa)
|
45
|
-
assert_equal 1, I18n.backend.spy_calls
|
46
|
-
end
|
47
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class I18nBackendMetadataTest < Test::Unit::TestCase
|
4
|
-
class Backend < I18n::Backend::Simple
|
5
|
-
include I18n::Backend::Metadata
|
6
|
-
end
|
7
|
-
|
8
|
-
def setup
|
9
|
-
I18n.backend = Backend.new
|
10
|
-
store_translations(:en, :foo => 'Hi %{name}')
|
11
|
-
end
|
12
|
-
|
13
|
-
test "translation strings carry metadata" do
|
14
|
-
translation = I18n.t(:foo, :name => 'David')
|
15
|
-
assert translation.respond_to?(:translation_metadata)
|
16
|
-
assert translation.translation_metadata.is_a?(Hash)
|
17
|
-
end
|
18
|
-
|
19
|
-
test "translate preserves metadata stored on original Strings" do
|
20
|
-
store_metadata(:foo, :bar, 'bar')
|
21
|
-
assert_equal 'bar', I18n.t(:foo, :name => 'David').translation_metadata[:bar]
|
22
|
-
end
|
23
|
-
|
24
|
-
test "translate preserves metadata stored on original Strings (when interpolated)" do
|
25
|
-
store_metadata(:foo, :bar, 'bar')
|
26
|
-
assert_equal 'bar', I18n.t(:foo, :name => 'David').translation_metadata[:bar]
|
27
|
-
end
|
28
|
-
|
29
|
-
test "translate adds the locale to metadata on Strings" do
|
30
|
-
assert_equal :en, I18n.t(:foo, :name => 'David', :locale => :en).translation_metadata[:locale]
|
31
|
-
end
|
32
|
-
|
33
|
-
test "translate adds the key to metadata on Strings" do
|
34
|
-
assert_equal :foo, I18n.t(:foo, :name => 'David').translation_metadata[:key]
|
35
|
-
end
|
36
|
-
#
|
37
|
-
test "translate adds the default to metadata on Strings" do
|
38
|
-
assert_equal 'bar', I18n.t(:foo, :default => 'bar', :name => '').translation_metadata[:default]
|
39
|
-
end
|
40
|
-
|
41
|
-
test "translation adds the interpolation values to metadata on Strings" do
|
42
|
-
assert_equal({:name => 'David'}, I18n.t(:foo, :name => 'David').translation_metadata[:values])
|
43
|
-
end
|
44
|
-
|
45
|
-
test "interpolation adds the original string to metadata on Strings" do
|
46
|
-
assert_equal('Hi %{name}', I18n.t(:foo, :name => 'David').translation_metadata[:original])
|
47
|
-
end
|
48
|
-
|
49
|
-
test "pluralization adds the count to metadata on Strings" do
|
50
|
-
assert_equal(1, I18n.t(:missing, :count => 1, :default => { :one => 'foo' }).translation_metadata[:count])
|
51
|
-
end
|
52
|
-
|
53
|
-
test "metadata works with frozen values" do
|
54
|
-
assert_equal(1, I18n.t(:missing, :count => 1, :default => 'foo'.freeze).translation_metadata[:count])
|
55
|
-
end
|
56
|
-
|
57
|
-
protected
|
58
|
-
|
59
|
-
def translations
|
60
|
-
I18n.backend.instance_variable_get(:@translations)
|
61
|
-
end
|
62
|
-
|
63
|
-
def store_metadata(key, name, value)
|
64
|
-
translations[:en][key].translation_metadata[name] = value
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|