thedarkone-i18n 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/CHANGELOG.textile +57 -0
  2. data/README.textile +43 -9
  3. data/Rakefile +21 -0
  4. data/VERSION +1 -0
  5. data/lib/i18n.rb +87 -16
  6. data/lib/i18n/backend/base.rb +251 -0
  7. data/lib/i18n/backend/cache.rb +71 -0
  8. data/lib/i18n/backend/chain.rb +64 -0
  9. data/lib/i18n/backend/fallbacks.rb +53 -0
  10. data/lib/i18n/backend/fast.rb +53 -22
  11. data/lib/i18n/backend/fast/interpolation_compiler.rb +84 -0
  12. data/lib/i18n/backend/gettext.rb +65 -0
  13. data/lib/i18n/backend/lazy_reloading.rb +60 -0
  14. data/lib/i18n/backend/pluralization.rb +56 -0
  15. data/lib/i18n/backend/simple.rb +17 -240
  16. data/lib/i18n/exceptions.rb +13 -5
  17. data/lib/i18n/gettext.rb +25 -0
  18. data/lib/i18n/helpers/gettext.rb +35 -0
  19. data/lib/i18n/locale/fallbacks.rb +100 -0
  20. data/lib/i18n/locale/tag.rb +27 -0
  21. data/lib/i18n/locale/tag/parents.rb +24 -0
  22. data/lib/i18n/locale/tag/rfc4646.rb +78 -0
  23. data/lib/i18n/locale/tag/simple.rb +44 -0
  24. data/test/all.rb +5 -7
  25. data/test/api/basics.rb +15 -0
  26. data/test/api/interpolation.rb +85 -0
  27. data/test/api/lambda.rb +52 -0
  28. data/test/api/link.rb +47 -0
  29. data/test/api/localization/date.rb +65 -0
  30. data/test/api/localization/date_time.rb +63 -0
  31. data/test/api/localization/lambda.rb +26 -0
  32. data/test/api/localization/time.rb +63 -0
  33. data/test/api/pluralization.rb +37 -0
  34. data/test/api/translation.rb +51 -0
  35. data/test/backend/cache/cache_test.rb +57 -0
  36. data/test/backend/chain/api_test.rb +80 -0
  37. data/test/backend/chain/chain_test.rb +64 -0
  38. data/test/backend/fallbacks/api_test.rb +79 -0
  39. data/test/backend/fallbacks/fallbacks_test.rb +29 -0
  40. data/test/backend/fast/all.rb +5 -0
  41. data/test/backend/fast/api_test.rb +91 -0
  42. data/test/backend/fast/interpolation_compiler_test.rb +84 -0
  43. data/test/backend/fast/lookup_test.rb +24 -0
  44. data/test/backend/fast/setup.rb +22 -0
  45. data/test/backend/fast/translations_test.rb +89 -0
  46. data/test/backend/lazy_reloading/reloading_test.rb +67 -0
  47. data/test/backend/pluralization/api_test.rb +81 -0
  48. data/test/backend/pluralization/pluralization_test.rb +39 -0
  49. data/test/backend/simple/all.rb +5 -0
  50. data/test/backend/simple/api_test.rb +90 -0
  51. data/test/backend/simple/lookup_test.rb +24 -0
  52. data/test/backend/simple/setup.rb +151 -0
  53. data/test/backend/simple/translations_test.rb +89 -0
  54. data/test/fixtures/locales/de.po +61 -0
  55. data/test/fixtures/locales/en.rb +3 -0
  56. data/test/fixtures/locales/en.yml +3 -0
  57. data/test/fixtures/locales/plurals.rb +112 -0
  58. data/test/gettext/api_test.rb +78 -0
  59. data/test/gettext/backend_test.rb +35 -0
  60. data/test/i18n_exceptions_test.rb +6 -25
  61. data/test/i18n_load_path_test.rb +23 -0
  62. data/test/i18n_test.rb +56 -18
  63. data/test/locale/fallbacks_test.rb +128 -0
  64. data/test/locale/tag/rfc4646_test.rb +147 -0
  65. data/test/locale/tag/simple_test.rb +35 -0
  66. data/test/test_helper.rb +72 -0
  67. data/test/with_options.rb +34 -0
  68. metadata +109 -19
  69. data/i18n.gemspec +0 -31
  70. data/lib/i18n/backend/fast/pluralization_compiler.rb +0 -50
  71. data/test/backend_test.rb +0 -633
  72. data/test/fast_backend_test.rb +0 -34
  73. data/test/locale/en.rb +0 -1
  74. data/test/locale/en.yml +0 -3
  75. data/test/pluralization_compiler_test.rb +0 -35
@@ -0,0 +1,64 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
4
+ require 'i18n/backend/chain'
5
+
6
+ class I18nChainBackendTest < Test::Unit::TestCase
7
+ def setup
8
+ @first = backend(:en => {
9
+ :foo => 'Foo', :formats => { :short => 'short' }, :plural_1 => { :one => '{{count}}' }
10
+ })
11
+ @second = backend(:en => {
12
+ :bar => 'Bar', :formats => { :long => 'long' }, :plural_2 => { :one => 'one' }
13
+ })
14
+ @chain = I18n.backend = I18n::Backend::Chain.new(@first, @second)
15
+ end
16
+
17
+ define_method "test: looks up translations from the first chained backend" do
18
+ assert_equal 'Foo', @first.send(:translations)[:en][:foo]
19
+ assert_equal 'Foo', I18n.t(:foo)
20
+ end
21
+
22
+ define_method "test: looks up translations from the second chained backend" do
23
+ assert_equal 'Bar', @second.send(:translations)[:en][:bar]
24
+ assert_equal 'Bar', I18n.t(:bar)
25
+ end
26
+
27
+ define_method "test: defaults only apply to lookups on the last backend in the chain" do
28
+ assert_equal 'Foo', I18n.t(:foo, :default => 'Bah')
29
+ assert_equal 'Bar', I18n.t(:bar, :default => 'Bah')
30
+ assert_equal 'Bah', I18n.t(:bah, :default => 'Bah') # default kicks in only here
31
+ end
32
+
33
+ define_method "test: default" do
34
+ assert_equal 'Fuh', I18n.t(:default => 'Fuh')
35
+ assert_equal 'Zero', I18n.t(:default => { :zero => 'Zero' }, :count => 0)
36
+ assert_equal({ :zero => 'Zero' }, I18n.t(:default => { :zero => 'Zero' }))
37
+ assert_equal 'Foo', I18n.t(:default => :foo)
38
+ end
39
+
40
+ define_method "test: namespace lookup collects results from all backends" do
41
+ assert_equal({ :short => 'short', :long => 'long' }, I18n.t(:formats))
42
+ end
43
+
44
+ define_method "test: namespace lookup with only the first backend returning a result" do
45
+ assert_equal({ :one => '{{count}}' }, I18n.t(:plural_1))
46
+ end
47
+
48
+ define_method "test: pluralization still works" do
49
+ assert_equal '1', I18n.t(:plural_1, :count => 1)
50
+ assert_equal 'one', I18n.t(:plural_2, :count => 1)
51
+ end
52
+
53
+ define_method "test: bulk lookup collects results from all backends" do
54
+ assert_equal ['Foo', 'Bar'], I18n.t([:foo, :bar])
55
+ end
56
+
57
+ protected
58
+
59
+ def backend(translations)
60
+ backend = I18n::Backend::Simple.new
61
+ translations.each { |locale, translations| backend.store_translations(locale, translations) }
62
+ backend
63
+ end
64
+ end
@@ -0,0 +1,79 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
4
+ require 'i18n/backend/fallbacks'
5
+
6
+ module FallbacksSetup
7
+ def setup
8
+ super
9
+ I18n.backend.meta_class.send(:include, I18n::Backend::Fallbacks)
10
+ end
11
+
12
+ def test_uses_fallbacks
13
+ assert I18n.backend.meta_class.included_modules.include?(I18n::Backend::Fallbacks)
14
+ end
15
+ end
16
+
17
+ class I18nFallbacksBackendApiBasicsTest < Test::Unit::TestCase
18
+ include FallbacksSetup
19
+ include Tests::Backend::Api::Basics
20
+ end
21
+
22
+ class I18nFallbacksBackendApiTranslateTest < Test::Unit::TestCase
23
+ include Tests::Backend::Simple::Setup::Base
24
+ include FallbacksSetup
25
+ include Tests::Backend::Api::Translation
26
+ end
27
+
28
+ class I18nFallbacksBackendApiInterpolateTest < Test::Unit::TestCase
29
+ include Tests::Backend::Simple::Setup::Base
30
+ include FallbacksSetup
31
+ include Tests::Backend::Api::Interpolation
32
+ end
33
+
34
+ class I18nFallbacksBackendApiLambdaTest < Test::Unit::TestCase
35
+ include Tests::Backend::Simple::Setup::Base
36
+ include FallbacksSetup
37
+ include Tests::Backend::Api::Lambda
38
+ end
39
+
40
+ class I18nFallbacksBackendApiTranslateLinkedTest < Test::Unit::TestCase
41
+ include Tests::Backend::Simple::Setup::Base
42
+ include FallbacksSetup
43
+ include Tests::Backend::Api::Link
44
+ end
45
+
46
+ class I18nFallbacksBackendApiPluralizationTest < Test::Unit::TestCase
47
+ include Tests::Backend::Simple::Setup::Base
48
+ include FallbacksSetup
49
+ include Tests::Backend::Api::Pluralization
50
+ end
51
+
52
+ class I18nFallbacksBackendApiLocalizeDateTest < Test::Unit::TestCase
53
+ include Tests::Backend::Simple::Setup::Base
54
+ include Tests::Backend::Simple::Setup::Localization
55
+ include FallbacksSetup
56
+ include Tests::Backend::Api::Localization::Date
57
+ end
58
+
59
+ class I18nFallbacksBackendApiLocalizeDateTimeTest < Test::Unit::TestCase
60
+ include Tests::Backend::Simple::Setup::Base
61
+ include Tests::Backend::Simple::Setup::Localization
62
+ include FallbacksSetup
63
+ include Tests::Backend::Api::Localization::DateTime
64
+ end
65
+
66
+ class I18nFallbacksBackendApiLocalizeTimeTest < Test::Unit::TestCase
67
+ include Tests::Backend::Simple::Setup::Base
68
+ include Tests::Backend::Simple::Setup::Localization
69
+ include FallbacksSetup
70
+ include Tests::Backend::Api::Localization::Time
71
+ end
72
+
73
+ class I18nFallbacksBackendApiLocalizeLambdaTest < Test::Unit::TestCase
74
+ include Tests::Backend::Simple::Setup::Base
75
+ include Tests::Backend::Simple::Setup::Localization
76
+ include FallbacksSetup
77
+ include Tests::Backend::Api::Localization::Lambda
78
+ end
79
+
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
4
+ require 'i18n/backend/fallbacks'
5
+
6
+ class I18nFallbacksBackendTest < Test::Unit::TestCase
7
+ def setup
8
+ I18n.backend = I18n::Backend::Simple.new
9
+ I18n.backend.meta_class.send(:include, I18n::Backend::Fallbacks)
10
+ backend_store_translations(:en, :foo => 'Foo')
11
+ end
12
+
13
+ define_method "test: fallbacks for :de are [:de, :en]" do
14
+ assert_equal [:de, :en], I18n.fallbacks[:de]
15
+ end
16
+
17
+ define_method "test: still returns the English translation as usual" do
18
+ assert_equal 'Foo', I18n.t(:foo, :locale => :en)
19
+ end
20
+
21
+ define_method "test: returns the English translation for a missing German translation" do
22
+ assert_equal 'Foo', I18n.t(:foo, :locale => :de)
23
+ end
24
+
25
+ define_method "test: raises I18n::MissingTranslationData exception when no translation was found" do
26
+ assert_raises(I18n::MissingTranslationData) { I18n.t(:bar, :locale => :en, :raise => true) }
27
+ assert_raises(I18n::MissingTranslationData) { I18n.t(:bar, :locale => :de, :raise => true) }
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+
3
+ Dir[File.dirname(__FILE__) + '/*_test.rb'].each do |file|
4
+ require file
5
+ end
@@ -0,0 +1,91 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
4
+
5
+ class I18nFastBackendApiBasicsTest < Test::Unit::TestCase
6
+ include Tests::Backend::Fast::Setup::Base
7
+ include Tests::Backend::Api::Basics
8
+
9
+ def test_uses_fast_backend
10
+ assert_equal I18n::Backend::Fast, I18n.backend.class
11
+ end
12
+ end
13
+
14
+ class I18nFastBackendApiTranslateTest < Test::Unit::TestCase
15
+ include Tests::Backend::Fast::Setup::Base
16
+ include Tests::Backend::Api::Translation
17
+
18
+ # implementation specific tests
19
+
20
+ def test_translate_calls_lookup_with_locale_given
21
+ I18n.backend.expects(:lookup).with('de', :bar, [:foo], nil).returns 'bar'
22
+ I18n.backend.translate 'de', :bar, :scope => [:foo]
23
+ end
24
+
25
+ def test_translate_calls_pluralize
26
+ I18n.backend.expects(:pluralize).with('en', 'bar', 1).returns('bar')
27
+ I18n.backend.translate 'en', :bar, :scope => [:foo], :count => 1
28
+ end
29
+ end
30
+
31
+ class I18nFastBackendApiInterpolateTest < Test::Unit::TestCase
32
+ include Tests::Backend::Fast::Setup::Base
33
+ include Tests::Backend::Api::Interpolation
34
+
35
+ # pre-compile default strings to make sure we are testing I18n::Fast::InterpolationCompiler
36
+ def interpolate(options)
37
+ if default_str = options[:default]
38
+ I18n::Backend::Fast::InterpolationCompiler.compile_if_an_interpolation(default_str)
39
+ end
40
+ super
41
+ end
42
+
43
+ # I kinda don't think this really is a correct behavior
44
+ undef :test_interpolation_given_no_interpolation_values_it_does_not_alter_the_string
45
+
46
+ # implementation specific tests
47
+
48
+ def test_interpolate_given_nil_as_a_string_returns_nil
49
+ assert_nil I18n.backend.send(:interpolate, nil, nil, :name => 'David')
50
+ end
51
+
52
+ def test_interpolate_given_an_non_string_as_a_string_returns_nil
53
+ assert_equal [], I18n.backend.send(:interpolate, nil, [], :name => 'David')
54
+ end
55
+ end
56
+
57
+ class I18nFastBackendApiLambdaTest < Test::Unit::TestCase
58
+ include Tests::Backend::Fast::Setup::Base
59
+ include Tests::Backend::Api::Lambda
60
+ end
61
+
62
+ class I18nFastBackendApiTranslateLinkedTest < Test::Unit::TestCase
63
+ include Tests::Backend::Fast::Setup::Base
64
+ include Tests::Backend::Api::Link
65
+ end
66
+
67
+ class I18nFastBackendApiPluralizationTest < Test::Unit::TestCase
68
+ include Tests::Backend::Fast::Setup::Base
69
+ include Tests::Backend::Api::Pluralization
70
+ end
71
+
72
+ class I18nFastBackendApiLocalizeDateTest < Test::Unit::TestCase
73
+ include Tests::Backend::Fast::Setup::Localization
74
+ include Tests::Backend::Api::Localization::Date
75
+ end
76
+
77
+ class I18nFastBackendApiLocalizeDateTimeTest < Test::Unit::TestCase
78
+ include Tests::Backend::Fast::Setup::Localization
79
+ include Tests::Backend::Api::Localization::DateTime
80
+ end
81
+
82
+ class I18nFastBackendApiLocalizeTimeTest < Test::Unit::TestCase
83
+ include Tests::Backend::Fast::Setup::Localization
84
+ include Tests::Backend::Api::Localization::Time
85
+ end
86
+
87
+ class I18nFastBackendApiLocalizeLambdaTest < Test::Unit::TestCase
88
+ include Tests::Backend::Fast::Setup::Localization
89
+ include Tests::Backend::Api::Localization::Lambda
90
+ end
91
+
@@ -0,0 +1,84 @@
1
+ # encoding: utf-8
2
+ $:.unshift "lib"
3
+
4
+ require 'rubygems'
5
+ require 'test/unit'
6
+ require 'i18n'
7
+
8
+ InterpolationCompiler = I18n::Backend::Fast::InterpolationCompiler
9
+
10
+ class InterpolationCompilerTest < Test::Unit::TestCase
11
+ def compile_and_interpolate(str, values = {})
12
+ InterpolationCompiler.compile_if_an_interpolation(str).i18n_interpolate(values)
13
+ end
14
+
15
+ def assert_escapes_interpolation_key(expected, malicious_str)
16
+ assert_equal(expected, InterpolationCompiler.send(:escape_key_sym, malicious_str))
17
+ end
18
+
19
+ def test_escape_key_properly_escapes
20
+ assert_escapes_interpolation_key ':"\""', '"'
21
+ assert_escapes_interpolation_key ':"\\\\"', '\\'
22
+ assert_escapes_interpolation_key ':"\\\\\""', '\\"'
23
+ assert_escapes_interpolation_key ':"\#{}"', '#{}'
24
+ assert_escapes_interpolation_key ':"\\\\\#{}"', '\#{}'
25
+ end
26
+
27
+ def assert_escapes_plain_string(expected, plain_str)
28
+ assert_equal expected, InterpolationCompiler.send(:escape_plain_str, plain_str)
29
+ end
30
+
31
+ def test_escape_plain_string_properly_escapes
32
+ assert_escapes_plain_string '\\"', '"'
33
+ assert_escapes_plain_string '\'', '\''
34
+ assert_escapes_plain_string '\\#', '#'
35
+ assert_escapes_plain_string '\\#{}', '#{}'
36
+ assert_escapes_plain_string '\\\\\\"','\\"'
37
+ end
38
+
39
+ def test_non_interpolated_strings_or_arrays_dont_get_compiled
40
+ ['abc', '\\{a}}', '{a}}', []].each do |obj|
41
+ InterpolationCompiler.compile_if_an_interpolation(obj)
42
+ assert_equal false, obj.respond_to?(:i18n_interpolate)
43
+ end
44
+ end
45
+
46
+ def test_interpolated_string_gets_compiled
47
+ assert_equal '-A-', compile_and_interpolate('-{{a}}-', :a => 'A')
48
+ end
49
+
50
+ def assert_handles_key(str, key)
51
+ assert_equal 'A', compile_and_interpolate(str, key => 'A')
52
+ end
53
+
54
+ def test_compiles_fancy_keys
55
+ assert_handles_key('{{\}}', :'\\' )
56
+ assert_handles_key('{{#}}', :'#' )
57
+ assert_handles_key('{{#{}}', :'#{' )
58
+ assert_handles_key('{{#$SAFE}}', :'#$SAFE')
59
+ assert_handles_key('{{\000}}', :'\000' )
60
+ assert_handles_key('{{\'}}', :'\'' )
61
+ assert_handles_key('{{\'\'}}', :'\'\'' )
62
+ assert_handles_key('{{a.b}}', :'a.b' )
63
+ assert_handles_key('{{ }}', :' ' )
64
+ assert_handles_key('{{:}}', :':' )
65
+ assert_handles_key("{{:''}}", :":''" )
66
+ assert_handles_key('{{:"}}', :':"' )
67
+ end
68
+
69
+ def test_str_containing_only_escaped_interpolation_is_handled_correctly
70
+ assert_equal 'abc {{x}}', compile_and_interpolate('abc \\{{x}}')
71
+ end
72
+
73
+ def test_handles_weired_strings
74
+ assert_equal '#{} a', compile_and_interpolate('#{} {{a}}', :a => 'a')
75
+ assert_equal '"#{abc}"', compile_and_interpolate('"#{ab{{a}}c}"', :a => '' )
76
+ assert_equal 'a}', compile_and_interpolate('{{{a}}}', :'{a' => 'a')
77
+ assert_equal '"', compile_and_interpolate('"{{a}}', :a => '' )
78
+ assert_equal 'a{{a}}', compile_and_interpolate('{{a}}\\{{a}}', :a => 'a')
79
+ assert_equal '\\{{a}}', compile_and_interpolate('\\\\{{a}}')
80
+ assert_equal '\";eval("a")', compile_and_interpolate('\";eval("{{a}}")', :a => 'a')
81
+ assert_equal '\";eval("a")', compile_and_interpolate('\";eval("a"){{a}}',:a => '' )
82
+ end
83
+
84
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
4
+
5
+ class I18nFastBackendLookupTest < Test::Unit::TestCase
6
+ include Tests::Backend::Fast::Setup::Base
7
+
8
+ # useful because this way we can use the backend with no key for interpolation/pluralization
9
+ def test_lookup_given_nil_as_a_key_returns_nil
10
+ assert_nil I18n.backend.send(:lookup, :en, nil)
11
+ end
12
+
13
+ def test_lookup_given_nested_keys_looks_up_a_nested_hash_value
14
+ assert_equal 'bar', I18n.backend.send(:lookup, :en, :bar, [:foo])
15
+ end
16
+
17
+ def test_lookup_using_a_custom_separator
18
+ assert_equal 'bar', I18n.backend.send(:lookup, :en, 'foo|bar', [], '|')
19
+ end
20
+
21
+ def test_default_using_a_custom_separator
22
+ assert_equal 'bar', I18n.backend.send(:default, :en, :'does_not_exist', :'foo|bar', :separator => '|')
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ module Tests
4
+ module Backend
5
+ module Fast
6
+ module Setup
7
+ module Base
8
+ include Tests::Backend::Simple::Setup::Base
9
+
10
+ def new_backend
11
+ I18n::Backend::Fast.new
12
+ end
13
+ end
14
+
15
+ module Localization
16
+ include Base
17
+ include Tests::Backend::Simple::Setup::Localization
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,89 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
4
+
5
+ class I18nFastBackendLoadTranslationsTest < Test::Unit::TestCase
6
+ include Tests::Backend::Fast::Setup::Base
7
+
8
+ def test_load_translations_with_unknown_file_type_raises_exception
9
+ assert_raises(I18n::UnknownFileType) { I18n.backend.load_translations "#{locales_dir}/en.xml" }
10
+ end
11
+
12
+ def test_load_translations_with_ruby_file_type_does_not_raise_exception
13
+ assert_nothing_raised { I18n.backend.load_translations "#{locales_dir}/en.rb" }
14
+ end
15
+
16
+ def test_load_rb_loads_data_from_ruby_file
17
+ data = I18n.backend.send :load_rb, "#{locales_dir}/en.rb"
18
+ assert_equal({ :en => { :fuh => { :bah => 'bas' } } }, data)
19
+ end
20
+
21
+ def test_load_rb_loads_data_from_yaml_file
22
+ data = I18n.backend.send :load_yml, "#{locales_dir}/en.yml"
23
+ assert_equal({ 'en' => { 'foo' => { 'bar' => 'baz' } } }, data)
24
+ end
25
+
26
+ def test_load_translations_loads_from_different_file_formats
27
+ I18n.backend = I18n::Backend::Fast.new
28
+ I18n.backend.load_translations "#{locales_dir}/en.rb", "#{locales_dir}/en.yml"
29
+ expected = { :en => { :fuh => { :bah => "bas" }, :foo => { :bar => "baz" } } }
30
+ assert_equal expected, backend_get_translations
31
+ end
32
+ end
33
+
34
+ class I18nFastBackendStoreTranslationsTest < Test::Unit::TestCase
35
+ include Tests::Backend::Fast::Setup::Base
36
+
37
+ def test_store_translations_adds_translations # no, really :-)
38
+ I18n.backend.store_translations :'en', :foo => 'bar'
39
+ assert_equal Hash[:'en', {:foo => 'bar'}], backend_get_translations
40
+ end
41
+
42
+ def test_store_translations_deep_merges_translations
43
+ I18n.backend.store_translations :'en', :foo => {:bar => 'bar'}
44
+ I18n.backend.store_translations :'en', :foo => {:baz => 'baz'}
45
+ assert_equal Hash[:'en', {:foo => {:bar => 'bar', :baz => 'baz'}}], backend_get_translations
46
+ end
47
+
48
+ def test_store_translations_forces_locale_to_sym
49
+ I18n.backend.store_translations 'en', :foo => 'bar'
50
+ assert_equal Hash[:'en', {:foo => 'bar'}], backend_get_translations
51
+ end
52
+
53
+ def test_store_translations_converts_keys_to_symbols
54
+ # backend_reset_translations!
55
+ I18n.backend.store_translations 'en', 'foo' => {'bar' => 'bar', 'baz' => 'baz'}
56
+ assert_equal Hash[:'en', {:foo => {:bar => 'bar', :baz => 'baz'}}], backend_get_translations
57
+ end
58
+
59
+ def test_deep_symbolize_keys_works
60
+ result = I18n.backend.send :deep_symbolize_keys, 'foo' => {'bar' => {'baz' => 'bar'}}
61
+ expected = {:foo => {:bar => {:baz => 'bar'}}}
62
+ assert_equal expected, result
63
+ end
64
+ end
65
+
66
+ class I18nFastBackendReloadTranslationsTest < Test::Unit::TestCase
67
+ include Tests::Backend::Fast::Setup::Base
68
+
69
+ def setup
70
+ I18n.backend = I18n::Backend::Fast.new
71
+ I18n.load_path = [locales_dir + '/en.yml']
72
+ assert_nil backend_get_translations
73
+ I18n.backend.send :init_translations
74
+ end
75
+
76
+ def test_setup
77
+ assert_not_nil backend_get_translations
78
+ end
79
+
80
+ def test_reload_translations_unloads_translations
81
+ I18n.backend.reload!
82
+ assert_nil backend_get_translations
83
+ end
84
+
85
+ def test_reload_translations_uninitializes_translations
86
+ I18n.backend.reload!
87
+ assert_equal I18n.backend.initialized?, false
88
+ end
89
+ end