i18n 0.3.6 → 0.3.7

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.

Files changed (62) hide show
  1. data/lib/i18n.rb +29 -4
  2. data/lib/i18n/backend/active_record/translation.rb +6 -4
  3. data/lib/i18n/backend/base.rb +1 -1
  4. data/lib/i18n/locale/fallbacks.rb +4 -4
  5. data/lib/i18n/version.rb +1 -1
  6. metadata +16 -116
  7. data/CHANGELOG.textile +0 -76
  8. data/MIT-LICENSE +0 -20
  9. data/README.textile +0 -104
  10. data/Rakefile +0 -29
  11. data/test/all.rb +0 -8
  12. data/test/api.rb +0 -18
  13. data/test/api/active_record_test.rb +0 -30
  14. data/test/api/all_features_test.rb +0 -59
  15. data/test/api/cascade_test.rb +0 -32
  16. data/test/api/chain_test.rb +0 -27
  17. data/test/api/fallbacks_test.rb +0 -34
  18. data/test/api/fast_test.rb +0 -32
  19. data/test/api/pluralization_test.rb +0 -34
  20. data/test/api/simple_test.rb +0 -23
  21. data/test/api/tests/basics.rb +0 -15
  22. data/test/api/tests/defaults.rb +0 -40
  23. data/test/api/tests/interpolation.rb +0 -92
  24. data/test/api/tests/link.rb +0 -56
  25. data/test/api/tests/localization/date.rb +0 -96
  26. data/test/api/tests/localization/date_time.rb +0 -93
  27. data/test/api/tests/localization/procs.rb +0 -60
  28. data/test/api/tests/localization/time.rb +0 -88
  29. data/test/api/tests/lookup.rb +0 -62
  30. data/test/api/tests/pluralization.rb +0 -35
  31. data/test/api/tests/procs.rb +0 -55
  32. data/test/backend/active_record/missing_test.rb +0 -51
  33. data/test/backend/active_record_test.rb +0 -57
  34. data/test/backend/cache_test.rb +0 -71
  35. data/test/backend/cascade_test.rb +0 -73
  36. data/test/backend/chain_test.rb +0 -63
  37. data/test/backend/cldr_test.rb +0 -151
  38. data/test/backend/exceptions_test.rb +0 -25
  39. data/test/backend/fallbacks_test.rb +0 -107
  40. data/test/backend/fast_test.rb +0 -50
  41. data/test/backend/helpers_test.rb +0 -27
  42. data/test/backend/interpolation_compiler_test.rb +0 -108
  43. data/test/backend/metadata_test.rb +0 -66
  44. data/test/backend/pluralization_test.rb +0 -47
  45. data/test/backend/simple_test.rb +0 -77
  46. data/test/core_ext/string/interpolate_test.rb +0 -99
  47. data/test/gettext/api_test.rb +0 -207
  48. data/test/gettext/backend_test.rb +0 -91
  49. data/test/i18n_exceptions_test.rb +0 -97
  50. data/test/i18n_load_path_test.rb +0 -23
  51. data/test/i18n_test.rb +0 -207
  52. data/test/locale/fallbacks_test.rb +0 -126
  53. data/test/locale/tag/rfc4646_test.rb +0 -143
  54. data/test/locale/tag/simple_test.rb +0 -33
  55. data/test/test_data/locales/cldr/de/calendars.yml +0 -152
  56. data/test/test_data/locales/cldr/de/currencies.yml +0 -8
  57. data/test/test_data/locales/cldr/de/numbers.yml +0 -31
  58. data/test/test_data/locales/de.po +0 -72
  59. data/test/test_data/locales/en.rb +0 -3
  60. data/test/test_data/locales/en.yml +0 -3
  61. data/test/test_data/locales/plurals.rb +0 -113
  62. data/test/test_helper.rb +0 -116
@@ -1,25 +0,0 @@
1
- # encoding: utf-8
2
- $:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
3
- require 'test_helper'
4
-
5
- class I18nBackendExceptionsTest < Test::Unit::TestCase
6
- def setup
7
- I18n.backend = I18n::Backend::Simple.new
8
- end
9
-
10
- test "exceptions: MissingTranslationData message from #translate includes the given scope and full key" do
11
- begin
12
- I18n.t(:'baz.missing', :scope => :'foo.bar', :raise => true)
13
- rescue I18n::MissingTranslationData => exception
14
- end
15
- assert_equal "translation missing: en, foo, bar, baz, missing", exception.message
16
- end
17
-
18
- test "exceptions: MissingTranslationData message from #localize includes the given scope and full key" do
19
- begin
20
- I18n.l(Time.now, :format => :foo)
21
- rescue I18n::MissingTranslationData => exception
22
- end
23
- assert_equal "translation missing: en, time, formats, foo", exception.message
24
- end
25
- end
@@ -1,107 +0,0 @@
1
- # encoding: utf-8
2
- $:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
3
- require 'test_helper'
4
-
5
- class I18nBackendFallbacksTranslateTest < Test::Unit::TestCase
6
- class Backend
7
- include I18n::Backend::Base
8
- include I18n::Backend::Fallbacks
9
- end
10
-
11
- def setup
12
- I18n.backend = Backend.new
13
- store_translations(:en, :foo => 'Foo in :en', :bar => 'Bar in :en', :buz => 'Buz in :en')
14
- store_translations(:de, :bar => 'Bar in :de', :baz => 'Baz in :de')
15
- store_translations(:'de-DE', :baz => 'Baz in :de-DE')
16
- end
17
-
18
- test "still returns an existing translation as usual" do
19
- assert_equal 'Foo in :en', I18n.t(:foo, :locale => :en)
20
- assert_equal 'Bar in :de', I18n.t(:bar, :locale => :de)
21
- assert_equal 'Baz in :de-DE', I18n.t(:baz, :locale => :'de-DE')
22
- end
23
-
24
- test "returns the :en translation for a missing :de translation" do
25
- assert_equal 'Foo in :en', I18n.t(:foo, :locale => :de)
26
- end
27
-
28
- test "returns the :de translation for a missing :'de-DE' translation" do
29
- assert_equal 'Bar in :de', I18n.t(:bar, :locale => :'de-DE')
30
- end
31
-
32
- test "returns the :en translation for translation missing in both :de and :'de-De'" do
33
- assert_equal 'Buz in :en', I18n.t(:buz, :locale => :'de-DE')
34
- end
35
-
36
- test "returns the :de translation for a missing :'de-DE' when :default is a String" do
37
- assert_equal 'Bar in :de', I18n.t(:bar, :locale => :'de-DE', :default => "Default Bar")
38
- assert_equal "Default Bar", I18n.t(:missing_bar, :locale => :'de-DE', :default => "Default Bar")
39
- end
40
-
41
- test "returns the :'de-DE' default :baz translation for a missing :'de-DE' when defaults contains Symbol" do
42
- assert_equal 'Baz in :de-DE', I18n.t(:missing_foo, :locale => :'de-DE', :default => [:baz, "Default Bar"])
43
- end
44
-
45
- test "returns the defaults translation for a missing :'de-DE' when defaults a contains String before Symbol" do
46
- assert_equal "Default Bar", I18n.t(:missing_foo, :locale => :'de-DE', :default => [:missing_bar, "Default Bar", :baz])
47
- end
48
-
49
- test "returns the default translation for a missing :'de-DE' and existing :de when default is a Hash" do
50
- assert_equal 'Default 6 Bars', I18n.t(:missing_foo, :locale => :'de-DE', :default => [:missing_bar, {:other => "Default {{count}} Bars"}, "Default Bar"], :count => 6)
51
- end
52
-
53
- test "raises I18n::MissingTranslationData exception when no translation was found" do
54
- assert_raise(I18n::MissingTranslationData) { I18n.t(:faa, :locale => :en, :raise => true) }
55
- assert_raise(I18n::MissingTranslationData) { I18n.t(:faa, :locale => :de, :raise => true) }
56
- end
57
- end
58
-
59
- class I18nBackendFallbacksLocalizeTest < Test::Unit::TestCase
60
- class Backend
61
- include I18n::Backend::Base
62
- include I18n::Backend::Fallbacks
63
- end
64
-
65
- def setup
66
- I18n.backend = Backend.new
67
- store_translations(:en, :date => { :formats => { :en => 'en' }, :day_names => %w(Sunday) })
68
- store_translations(:de, :date => { :formats => { :de => 'de' } })
69
- end
70
-
71
- test "still uses an existing format as usual" do
72
- assert_equal 'en', I18n.l(Date.today, :format => :en, :locale => :en)
73
- end
74
-
75
- test "looks up and uses a fallback locale's format for a key missing in the given locale (1)" do
76
- assert_equal 'en', I18n.l(Date.today, :format => :en, :locale => :de)
77
- end
78
-
79
- test "looks up and uses a fallback locale's format for a key missing in the given locale (2)" do
80
- assert_equal 'de', I18n.l(Date.today, :format => :de, :locale => :'de-DE')
81
- end
82
-
83
- test "still uses an existing day name translation as usual" do
84
- assert_equal 'Sunday', I18n.l(Date.new(2010, 1, 3), :format => '%A', :locale => :en)
85
- end
86
-
87
- test "uses a fallback locale's translation for a key missing in the given locale" do
88
- assert_equal 'Sunday', I18n.l(Date.new(2010, 1, 3), :format => '%A', :locale => :de)
89
- end
90
- end
91
-
92
- class I18nBackendFallbacksWithChainTest < Test::Unit::TestCase
93
- class Backend
94
- include I18n::Backend::Base
95
- include I18n::Backend::Fallbacks
96
- end
97
-
98
- def setup
99
- backend = Backend.new
100
- backend.store_translations(:de, :foo => 'FOO')
101
- I18n.backend = I18n::Backend::Chain.new(I18n::Backend::Simple.new, backend)
102
- end
103
-
104
- test "falls back from de-DE to de when there is no translation for de-DE available" do
105
- assert_equal 'FOO', I18n.t(:foo, :locale => :'de-DE')
106
- end
107
- end
@@ -1,50 +0,0 @@
1
- # encoding: utf-8
2
- $:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
3
- require 'test_helper'
4
- require 'backend/simple_test'
5
-
6
- class I18nBackendFastTest < I18nBackendSimpleTest
7
- class FastBackend
8
- include I18n::Backend::Base
9
- include I18n::Backend::Fast
10
- end
11
-
12
- def setup
13
- super
14
- I18n.backend = FastBackend.new
15
- end
16
- end
17
-
18
- class I18nBackendFastSpecificTest < Test::Unit::TestCase
19
- class FastBackend
20
- include I18n::Backend::Base
21
- include I18n::Backend::Fast
22
- end
23
-
24
- def setup
25
- @backend = FastBackend.new
26
- end
27
-
28
- def assert_flattens(expected, nested)
29
- assert_equal expected, @backend.send(:wind_keys, nested, nil, true)
30
- end
31
-
32
- test "hash flattening works" do
33
- assert_flattens(
34
- {:a=>'a', :b=>{:c=>'c', :d=>'d', :f=>{:x=>'x'}}, :"b.f" => {:x=>"x"}, :"b.c"=>"c", :"b.f.x"=>"x", :"b.d"=>"d"},
35
- {:a=>'a', :b=>{:c=>'c', :d=>'d', :f=>{:x=>'x'}}}
36
- )
37
- assert_flattens({:a=>{:b =>['a', 'b']}, :"a.b"=>['a', 'b']}, {:a=>{:b =>['a', 'b']}})
38
- end
39
-
40
- test "pluralization logic and lookup works" do
41
- counts_hash = {:zero => 'zero', :one => 'one', :other => 'other'}
42
- @backend.store_translations :en, {:a => counts_hash}
43
- assert_equal 'one', @backend.translate(:en, :a, :count => 1)
44
- end
45
-
46
- test "translation subtree retrieval" do
47
- @backend.store_translations :en, :a => {:foo => 'bar'}
48
- assert_equal({:foo => 'bar'}, @backend.translate(:en, :a))
49
- end
50
- end
@@ -1,27 +0,0 @@
1
- # encoding: utf-8
2
- $:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
3
- require 'test_helper'
4
-
5
- class I18nBackendHelpersTest < Test::Unit::TestCase
6
- def setup
7
- @backend = I18n::Backend::Simple.new
8
- end
9
-
10
- test "wind_keys" do
11
- hash = { "a" => { "b" => { "c" => "d", "e" => "f" }, "g" => "h" }, :"i.a" => "j", "g.a" => "h"}
12
- expected = { :"a.b.c" => "d", :"a.b.e" => "f", :"a.g" => "h", :"i.a" => "j", :"g.a" => "h" }
13
- assert_equal expected, @backend.wind_keys(hash)
14
- end
15
-
16
- test "unwind_keys" do
17
- hash = { "a.b.c" => "d", :"a.b.e" => "f", :"a.g" => "h", "i" => "j" }
18
- expected = { "a" => { "b" => { "c" => "d", "e" => "f" }, "g" => "h" }, "i" => "j"}
19
- assert_equal expected, @backend.unwind_keys(hash)
20
- end
21
-
22
- test "deep_symbolize_keys" do
23
- result = @backend.deep_symbolize_keys('foo' => { 'bar' => { 'baz' => 'bar' } })
24
- expected = {:foo => {:bar => {:baz => 'bar'}}}
25
- assert_equal expected, result
26
- end
27
- end
@@ -1,108 +0,0 @@
1
- # encoding: utf-8
2
- $:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
3
- require 'test_helper'
4
- require 'api'
5
-
6
- class InterpolationCompilerTest < Test::Unit::TestCase
7
- Compiler = I18n::Backend::InterpolationCompiler::Compiler
8
-
9
- def compile_and_interpolate(str, values = {})
10
- Compiler.compile_if_an_interpolation(str).i18n_interpolate(values)
11
- end
12
-
13
- def assert_escapes_interpolation_key(expected, malicious_str)
14
- assert_equal(expected, Compiler.send(:escape_key_sym, malicious_str))
15
- end
16
-
17
- def test_escape_key_properly_escapes
18
- assert_escapes_interpolation_key ':"\""', '"'
19
- assert_escapes_interpolation_key ':"\\\\"', '\\'
20
- assert_escapes_interpolation_key ':"\\\\\""', '\\"'
21
- assert_escapes_interpolation_key ':"\#{}"', '#{}'
22
- assert_escapes_interpolation_key ':"\\\\\#{}"', '\#{}'
23
- end
24
-
25
- def assert_escapes_plain_string(expected, plain_str)
26
- assert_equal expected, Compiler.send(:escape_plain_str, plain_str)
27
- end
28
-
29
- def test_escape_plain_string_properly_escapes
30
- assert_escapes_plain_string '\\"', '"'
31
- assert_escapes_plain_string '\'', '\''
32
- assert_escapes_plain_string '\\#', '#'
33
- assert_escapes_plain_string '\\#{}', '#{}'
34
- assert_escapes_plain_string '\\\\\\"','\\"'
35
- end
36
-
37
- def test_non_interpolated_strings_or_arrays_dont_get_compiled
38
- ['abc', '\\{a}}', '{a}}', []].each do |obj|
39
- Compiler.compile_if_an_interpolation(obj)
40
- assert_equal false, obj.respond_to?(:i18n_interpolate)
41
- end
42
- end
43
-
44
- def test_interpolated_string_gets_compiled
45
- assert_equal '-A-', compile_and_interpolate('-{{a}}-', :a => 'A')
46
- end
47
-
48
- def assert_handles_key(str, key)
49
- assert_equal 'A', compile_and_interpolate(str, key => 'A')
50
- end
51
-
52
- def test_compiles_fancy_keys
53
- assert_handles_key('{{\}}', :'\\' )
54
- assert_handles_key('{{#}}', :'#' )
55
- assert_handles_key('{{#{}}', :'#{' )
56
- assert_handles_key('{{#$SAFE}}', :'#$SAFE')
57
- assert_handles_key('{{\000}}', :'\000' )
58
- assert_handles_key('{{\'}}', :'\'' )
59
- assert_handles_key('{{\'\'}}', :'\'\'' )
60
- assert_handles_key('{{a.b}}', :'a.b' )
61
- assert_handles_key('{{ }}', :' ' )
62
- assert_handles_key('{{:}}', :':' )
63
- assert_handles_key("{{:''}}", :":''" )
64
- assert_handles_key('{{:"}}', :':"' )
65
- end
66
-
67
- def test_str_containing_only_escaped_interpolation_is_handled_correctly
68
- assert_equal 'abc {{x}}', compile_and_interpolate('abc \\{{x}}')
69
- end
70
-
71
- def test_handles_weired_strings
72
- assert_equal '#{} a', compile_and_interpolate('#{} {{a}}', :a => 'a')
73
- assert_equal '"#{abc}"', compile_and_interpolate('"#{ab{{a}}c}"', :a => '' )
74
- assert_equal 'a}', compile_and_interpolate('{{{a}}}', :'{a' => 'a')
75
- assert_equal '"', compile_and_interpolate('"{{a}}', :a => '' )
76
- assert_equal 'a{{a}}', compile_and_interpolate('{{a}}\\{{a}}', :a => 'a')
77
- assert_equal '\\{{a}}', compile_and_interpolate('\\\\{{a}}')
78
- assert_equal '\";eval("a")', compile_and_interpolate('\";eval("{{a}}")', :a => 'a')
79
- assert_equal '\";eval("a")', compile_and_interpolate('\";eval("a"){{a}}',:a => '' )
80
- assert_equal "\na", compile_and_interpolate("\n{{a}}", :a => 'a')
81
- end
82
- end
83
-
84
- class I18nBackendInterpolationCompilerTest < Test::Unit::TestCase
85
- class Backend
86
- include I18n::Backend::Base
87
- include I18n::Backend::InterpolationCompiler
88
- end
89
-
90
- include Tests::Api::Interpolation
91
-
92
- def setup
93
- I18n.backend = Backend.new
94
- super
95
- end
96
-
97
- # pre-compile default strings to make sure we are testing I18n::Backend::InterpolationCompiler
98
- def interpolate(*args)
99
- options = args.last.kind_of?(Hash) ? args.last : {}
100
- if default_str = options[:default]
101
- I18n::Backend::InterpolationCompiler::Compiler.compile_if_an_interpolation(default_str)
102
- end
103
- super
104
- end
105
-
106
- # I kinda don't think this really is a correct behavior
107
- undef :'test interpolation: given no values it does not alter the string'
108
- end
@@ -1,66 +0,0 @@
1
- # encoding: utf-8
2
- $:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
3
- require 'test_helper'
4
-
5
- class I18nBackendMetadataTest < Test::Unit::TestCase
6
- class Backend
7
- include I18n::Backend::Base
8
- include I18n::Backend::Metadata
9
- end
10
-
11
- def setup
12
- I18n.backend = Backend.new
13
- store_translations(:en, :foo => 'Hi {{name}}')
14
- end
15
-
16
- test "translation strings carry metadata" do
17
- translation = I18n.t(:foo)
18
- assert translation.respond_to?(:translation_metadata)
19
- assert translation.translation_metadata.is_a?(Hash)
20
- end
21
-
22
- test "translate preserves metadata stored on original Strings" do
23
- store_metadata(:foo, :bar, 'bar')
24
- assert_equal 'bar', I18n.t(:foo).translation_metadata[:bar]
25
- end
26
-
27
- test "translate preserves metadata stored on original Strings (when interpolated)" do
28
- store_metadata(:foo, :bar, 'bar')
29
- assert_equal 'bar', I18n.t(:foo, :name => 'David').translation_metadata[:bar]
30
- end
31
-
32
- test "translate adds the locale to metadata on Strings" do
33
- assert_equal :en, I18n.t(:foo, :locale => :en).translation_metadata[:locale]
34
- end
35
-
36
- test "translate adds the key to metadata on Strings" do
37
- assert_equal :foo, I18n.t(:foo).translation_metadata[:key]
38
- end
39
-
40
- test "translate adds the default to metadata on Strings" do
41
- assert_equal 'bar', I18n.t(:foo, :default => 'bar', :name => '').translation_metadata[:default]
42
- end
43
-
44
- test "translation adds the interpolation values to metadata on Strings" do
45
- assert_equal({:name => 'David'}, I18n.t(:foo, :name => 'David').translation_metadata[:values])
46
- end
47
-
48
- test "interpolation adds the original string to metadata on Strings" do
49
- assert_equal('Hi {{name}}', I18n.t(:foo, :name => 'David').translation_metadata[:original])
50
- end
51
-
52
- test "pluralizatoin adds the count to metadata on Strings" do
53
- assert_equal(1, I18n.t(:missing, :count => 1, :default => { :one => 'foo' }).translation_metadata[:count])
54
- end
55
-
56
- protected
57
-
58
- def translations
59
- I18n.backend.instance_variable_get(:@translations)
60
- end
61
-
62
- def store_metadata(key, name, value)
63
- translations[:en][key].translation_metadata[name] = value
64
- end
65
- end
66
-
@@ -1,47 +0,0 @@
1
- # encoding: utf-8
2
- $:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
3
- require 'test_helper'
4
-
5
- class I18nBackendPluralizationTest < Test::Unit::TestCase
6
- class Backend
7
- include I18n::Backend::Base
8
- include I18n::Backend::Pluralization
9
- include I18n::Backend::Fallbacks
10
- end
11
-
12
- def setup
13
- I18n.backend = Backend.new
14
- @rule = lambda { |n| n == 1 ? :one : n == 0 || (2..10).include?(n % 100) ? :few : (11..19).include?(n % 100) ? :many : :other }
15
- store_translations(:xx, :i18n => { :plural => { :rule => @rule } })
16
- @entry = { :zero => 'zero', :one => 'one', :few => 'few', :many => 'many', :other => 'other' }
17
- end
18
-
19
- test "pluralization picks a pluralizer from :'i18n.pluralize'" do
20
- assert_equal @rule, I18n.backend.send(:pluralizer, :xx)
21
- end
22
-
23
- test "pluralization picks :one for 1" do
24
- assert_equal 'one', I18n.t(:count => 1, :default => @entry, :locale => :xx)
25
- end
26
-
27
- test "pluralization picks :few for 2" do
28
- assert_equal 'few', I18n.t(:count => 2, :default => @entry, :locale => :xx)
29
- end
30
-
31
- test "pluralization picks :many for 11" do
32
- assert_equal 'many', I18n.t(:count => 11, :default => @entry, :locale => :xx)
33
- end
34
-
35
- test "pluralization picks zero for 0 if the key is contained in the data" do
36
- assert_equal 'zero', I18n.t(:count => 0, :default => @entry, :locale => :xx)
37
- end
38
-
39
- test "pluralization picks few for 0 if the key is not contained in the data" do
40
- @entry.delete(:zero)
41
- assert_equal 'few', I18n.t(:count => 0, :default => @entry, :locale => :xx)
42
- end
43
-
44
- test "Fallbacks can pick up rules from fallback locales, too" do
45
- assert_equal @rule, I18n.backend.send(:pluralizer, :'xx-XX')
46
- end
47
- end
@@ -1,77 +0,0 @@
1
- # encoding: utf-8
2
- $:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
3
- require 'test_helper'
4
-
5
- class I18nBackendSimpleTest < Test::Unit::TestCase
6
- def setup
7
- I18n.backend = I18n::Backend::Simple.new
8
- I18n.load_path = [locales_dir + '/en.yml']
9
- end
10
-
11
- # useful because this way we can use the backend with no key for interpolation/pluralization
12
- test "simple backend lookup: given nil as a key it returns nil" do
13
- assert_nil I18n.backend.send(:lookup, :en, nil)
14
- end
15
-
16
- # loading translations
17
-
18
- test "simple load_translations: given an unknown file type it raises I18n::UnknownFileType" do
19
- assert_raise(I18n::UnknownFileType) { I18n.backend.load_translations("#{locales_dir}/en.xml") }
20
- end
21
-
22
- test "simple load_translations: given a Ruby file name it does not raise anything" do
23
- assert_nothing_raised { I18n.backend.load_translations("#{locales_dir}/en.rb") }
24
- end
25
-
26
- test "simple load_rb: loads data from a Ruby file" do
27
- data = I18n.backend.send(:load_rb, "#{locales_dir}/en.rb")
28
- assert_equal({ :en => { :fuh => { :bah => 'bas' } } }, data)
29
- end
30
-
31
- test "simple load_yml: loads data from a YAML file" do
32
- data = I18n.backend.send(:load_yml, "#{locales_dir}/en.yml")
33
- assert_equal({ 'en' => { 'foo' => { 'bar' => 'baz' } } }, data)
34
- end
35
-
36
- test "simple load_translations: loads data from known file formats" do
37
- I18n.backend = I18n::Backend::Simple.new
38
- I18n.backend.load_translations("#{locales_dir}/en.rb", "#{locales_dir}/en.yml")
39
- expected = { :en => { :fuh => { :bah => "bas" }, :foo => { :bar => "baz" } } }
40
- assert_equal expected, translations
41
- end
42
-
43
- # storing translations
44
-
45
- test "simple store_translations: stores translations, ... no, really :-)" do
46
- I18n.backend.store_translations :'en', :foo => 'bar'
47
- assert_equal Hash[:'en', {:foo => 'bar'}], translations
48
- end
49
-
50
- test "simple store_translations: deep_merges with existing translations" do
51
- I18n.backend.store_translations :'en', :foo => {:bar => 'bar'}
52
- I18n.backend.store_translations :'en', :foo => {:baz => 'baz'}
53
- assert_equal Hash[:'en', {:foo => {:bar => 'bar', :baz => 'baz'}}], translations
54
- end
55
-
56
- test "simple store_translations: converts the given locale to a Symbol" do
57
- I18n.backend.store_translations 'en', :foo => 'bar'
58
- assert_equal Hash[:'en', {:foo => 'bar'}], translations
59
- end
60
-
61
- test "simple store_translations: converts keys to Symbols" do
62
- I18n.backend.store_translations 'en', 'foo' => {'bar' => 'bar', 'baz' => 'baz'}
63
- assert_equal Hash[:'en', {:foo => {:bar => 'bar', :baz => 'baz'}}], translations
64
- end
65
-
66
- # reloading translations
67
-
68
- test "simple reload_translations: unloads translations" do
69
- I18n.backend.reload!
70
- assert_nil translations
71
- end
72
-
73
- test "simple reload_translations: uninitializes the backend" do
74
- I18n.backend.reload!
75
- assert_equal I18n.backend.initialized?, false
76
- end
77
- end