polish 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/LICENSE +20 -0
  2. data/README.md +25 -0
  3. data/Rakefile +56 -0
  4. data/TODO +5 -0
  5. data/init.rb +1 -0
  6. data/lib/polish.rb +104 -0
  7. data/lib/polish/action_view_ext/helpers/date_helper.rb +94 -0
  8. data/lib/polish/backend/advanced.rb +105 -0
  9. data/lib/polish/locale/actionview.yml +81 -0
  10. data/lib/polish/locale/activerecord.yml +27 -0
  11. data/lib/polish/locale/activesupport.yml +11 -0
  12. data/lib/polish/locale/datetime.yml +25 -0
  13. data/lib/polish/locale/pluralize.rb +16 -0
  14. data/lib/vendor/i18n/CHANGELOG.textile +57 -0
  15. data/lib/vendor/i18n/MIT-LICENSE +20 -0
  16. data/lib/vendor/i18n/README.textile +42 -0
  17. data/lib/vendor/i18n/Rakefile +21 -0
  18. data/lib/vendor/i18n/VERSION +1 -0
  19. data/lib/vendor/i18n/i18n.gemspec +141 -0
  20. data/lib/vendor/i18n/lib/i18n.rb +270 -0
  21. data/lib/vendor/i18n/lib/i18n/backend/base.rb +251 -0
  22. data/lib/vendor/i18n/lib/i18n/backend/cache.rb +71 -0
  23. data/lib/vendor/i18n/lib/i18n/backend/chain.rb +64 -0
  24. data/lib/vendor/i18n/lib/i18n/backend/fallbacks.rb +53 -0
  25. data/lib/vendor/i18n/lib/i18n/backend/gettext.rb +65 -0
  26. data/lib/vendor/i18n/lib/i18n/backend/pluralization.rb +56 -0
  27. data/lib/vendor/i18n/lib/i18n/backend/simple.rb +23 -0
  28. data/lib/vendor/i18n/lib/i18n/exceptions.rb +61 -0
  29. data/lib/vendor/i18n/lib/i18n/gettext.rb +25 -0
  30. data/lib/vendor/i18n/lib/i18n/helpers/gettext.rb +35 -0
  31. data/lib/vendor/i18n/lib/i18n/locale/fallbacks.rb +100 -0
  32. data/lib/vendor/i18n/lib/i18n/locale/tag.rb +27 -0
  33. data/lib/vendor/i18n/lib/i18n/locale/tag/parents.rb +24 -0
  34. data/lib/vendor/i18n/lib/i18n/locale/tag/rfc4646.rb +78 -0
  35. data/lib/vendor/i18n/lib/i18n/locale/tag/simple.rb +44 -0
  36. data/lib/vendor/i18n/lib/i18n/string.rb +95 -0
  37. data/lib/vendor/i18n/test/all.rb +5 -0
  38. data/lib/vendor/i18n/test/api/basics.rb +15 -0
  39. data/lib/vendor/i18n/test/api/interpolation.rb +85 -0
  40. data/lib/vendor/i18n/test/api/lambda.rb +52 -0
  41. data/lib/vendor/i18n/test/api/link.rb +47 -0
  42. data/lib/vendor/i18n/test/api/localization/date.rb +65 -0
  43. data/lib/vendor/i18n/test/api/localization/date_time.rb +63 -0
  44. data/lib/vendor/i18n/test/api/localization/lambda.rb +26 -0
  45. data/lib/vendor/i18n/test/api/localization/time.rb +63 -0
  46. data/lib/vendor/i18n/test/api/pluralization.rb +37 -0
  47. data/lib/vendor/i18n/test/api/translation.rb +51 -0
  48. data/lib/vendor/i18n/test/backend/cache/cache_test.rb +57 -0
  49. data/lib/vendor/i18n/test/backend/chain/api_test.rb +80 -0
  50. data/lib/vendor/i18n/test/backend/chain/chain_test.rb +64 -0
  51. data/lib/vendor/i18n/test/backend/fallbacks/api_test.rb +79 -0
  52. data/lib/vendor/i18n/test/backend/fallbacks/fallbacks_test.rb +29 -0
  53. data/lib/vendor/i18n/test/backend/pluralization/api_test.rb +81 -0
  54. data/lib/vendor/i18n/test/backend/pluralization/pluralization_test.rb +39 -0
  55. data/lib/vendor/i18n/test/backend/simple/all.rb +5 -0
  56. data/lib/vendor/i18n/test/backend/simple/api_test.rb +90 -0
  57. data/lib/vendor/i18n/test/backend/simple/lookup_test.rb +24 -0
  58. data/lib/vendor/i18n/test/backend/simple/setup.rb +147 -0
  59. data/lib/vendor/i18n/test/backend/simple/translations_test.rb +89 -0
  60. data/lib/vendor/i18n/test/fixtures/locales/de.po +61 -0
  61. data/lib/vendor/i18n/test/fixtures/locales/en.rb +3 -0
  62. data/lib/vendor/i18n/test/fixtures/locales/en.yml +3 -0
  63. data/lib/vendor/i18n/test/fixtures/locales/plurals.rb +112 -0
  64. data/lib/vendor/i18n/test/gettext/api_test.rb +78 -0
  65. data/lib/vendor/i18n/test/gettext/backend_test.rb +35 -0
  66. data/lib/vendor/i18n/test/i18n_exceptions_test.rb +97 -0
  67. data/lib/vendor/i18n/test/i18n_load_path_test.rb +23 -0
  68. data/lib/vendor/i18n/test/i18n_test.rb +163 -0
  69. data/lib/vendor/i18n/test/locale/fallbacks_test.rb +128 -0
  70. data/lib/vendor/i18n/test/locale/tag/rfc4646_test.rb +147 -0
  71. data/lib/vendor/i18n/test/locale/tag/simple_test.rb +35 -0
  72. data/lib/vendor/i18n/test/string_test.rb +94 -0
  73. data/lib/vendor/i18n/test/test_helper.rb +71 -0
  74. data/lib/vendor/i18n/test/with_options.rb +34 -0
  75. data/lib/vendor/i18n/vendor/po_parser.rb +329 -0
  76. data/spec/fixtures/en.yml +4 -0
  77. data/spec/fixtures/pl.yml +4 -0
  78. data/spec/i18n/locale/datetime_spec.rb +91 -0
  79. data/spec/i18n/locale/pluralization_spec.rb +41 -0
  80. data/spec/locale_spec.rb +124 -0
  81. data/spec/polish_spec.rb +141 -0
  82. data/spec/spec_helper.rb +4 -0
  83. metadata +138 -0
@@ -0,0 +1,81 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
4
+ require 'i18n/backend/pluralization'
5
+
6
+ module PluralizationSetup
7
+ def setup
8
+ super
9
+ I18n.backend.meta_class.send(:include, I18n::Backend::Pluralization)
10
+ I18n.load_path << locales_dir + '/plurals.rb'
11
+ end
12
+
13
+ def test_uses_pluralization
14
+ assert I18n.backend.meta_class.included_modules.include?(I18n::Backend::Pluralization)
15
+ end
16
+ end
17
+
18
+ class I18nPluralizationBackendApiBasicsTest < Test::Unit::TestCase
19
+ include PluralizationSetup
20
+ include Tests::Backend::Api::Basics
21
+ end
22
+
23
+ class I18nPluralizationBackendApiTranslateTest < Test::Unit::TestCase
24
+ include Tests::Backend::Simple::Setup::Base
25
+ include PluralizationSetup
26
+ include Tests::Backend::Api::Translation
27
+ end
28
+
29
+ class I18nPluralizationBackendApiInterpolateTest < Test::Unit::TestCase
30
+ include Tests::Backend::Simple::Setup::Base
31
+ include PluralizationSetup
32
+ include Tests::Backend::Api::Interpolation
33
+ end
34
+
35
+ class I18nPluralizationBackendApiLambdaTest < Test::Unit::TestCase
36
+ include Tests::Backend::Simple::Setup::Base
37
+ include PluralizationSetup
38
+ include Tests::Backend::Api::Lambda
39
+ end
40
+
41
+ class I18nPluralizationBackendApiTranslateLinkedTest < Test::Unit::TestCase
42
+ include Tests::Backend::Simple::Setup::Base
43
+ include PluralizationSetup
44
+ include Tests::Backend::Api::Link
45
+ end
46
+
47
+ class I18nPluralizationBackendApiPluralizeTest < Test::Unit::TestCase
48
+ include Tests::Backend::Simple::Setup::Base
49
+ include Tests::Backend::Simple::Setup::Localization
50
+ include PluralizationSetup
51
+ include Tests::Backend::Api::Pluralization
52
+ end
53
+
54
+ class I18nPluralizationBackendApiLocalizeDateTest < Test::Unit::TestCase
55
+ include Tests::Backend::Simple::Setup::Base
56
+ include Tests::Backend::Simple::Setup::Localization
57
+ include PluralizationSetup
58
+ include Tests::Backend::Api::Localization::Date
59
+ end
60
+
61
+ class I18nPluralizationBackendApiLocalizeDateTimeTest < Test::Unit::TestCase
62
+ include Tests::Backend::Simple::Setup::Base
63
+ include Tests::Backend::Simple::Setup::Localization
64
+ include PluralizationSetup
65
+ include Tests::Backend::Api::Localization::DateTime
66
+ end
67
+
68
+ class I18nPluralizationBackendApiLocalizeTimeTest < Test::Unit::TestCase
69
+ include Tests::Backend::Simple::Setup::Base
70
+ include Tests::Backend::Simple::Setup::Localization
71
+ include PluralizationSetup
72
+ include Tests::Backend::Api::Localization::Time
73
+ end
74
+
75
+ class I18nPluralizationBackendApiLocalizeLambdaTest < Test::Unit::TestCase
76
+ include Tests::Backend::Simple::Setup::Base
77
+ include Tests::Backend::Simple::Setup::Localization
78
+ include PluralizationSetup
79
+ include Tests::Backend::Api::Localization::Lambda
80
+ end
81
+
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
4
+ require 'i18n/backend/pluralization'
5
+
6
+ class I18nPluralizationBackendTest < Test::Unit::TestCase
7
+ def setup
8
+ I18n.backend = I18n::Backend::Simple.new
9
+ I18n.backend.meta_class.send(:include, I18n::Backend::Pluralization)
10
+ @pluralizer = lambda { |n| n == 1 ? :one : n == 0 || (2..10).include?(n % 100) ? :few : (11..19).include?(n % 100) ? :many : :other }
11
+ backend_store_translations(:foo, :i18n => { :pluralize => @pluralizer })
12
+ @entry = { :zero => 'zero', :one => 'one', :few => 'few', :many => 'many', :other => 'other' }
13
+ end
14
+
15
+ define_method :"test: pluralization picks a pluralizer from :'i18n.pluralize'" do
16
+ assert_equal @pluralizer, I18n.backend.send(:pluralizer, :foo)
17
+ end
18
+
19
+ define_method :"test: pluralization picks :one for 1" do
20
+ assert_equal 'one', I18n.t(:count => 1, :default => @entry, :locale => :foo)
21
+ end
22
+
23
+ define_method :"test: pluralization picks :few for 2" do
24
+ assert_equal 'few', I18n.t(:count => 2, :default => @entry, :locale => :foo)
25
+ end
26
+
27
+ define_method :"test: pluralization picks :many for 11" do
28
+ assert_equal 'many', I18n.t(:count => 11, :default => @entry, :locale => :foo)
29
+ end
30
+
31
+ define_method :"test: pluralization picks zero for 0 if the key is contained in the data" do
32
+ assert_equal 'zero', I18n.t(:count => 0, :default => @entry, :locale => :foo)
33
+ end
34
+
35
+ define_method :"test: pluralization picks few for 0 if the key is not contained in the data" do
36
+ @entry.delete(:zero)
37
+ assert_equal 'few', I18n.t(:count => 0, :default => @entry, :locale => :foo)
38
+ end
39
+ 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,90 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
4
+
5
+ class I18nSimpleBackendApiBasicsTest < Test::Unit::TestCase
6
+ include Tests::Backend::Simple::Setup::Base
7
+ include Tests::Backend::Api::Basics
8
+
9
+ def test_uses_simple_backend
10
+ assert_equal I18n::Backend::Simple, I18n.backend.class
11
+ end
12
+ end
13
+
14
+ class I18nSimpleBackendApiTranslateTest < Test::Unit::TestCase
15
+ include Tests::Backend::Simple::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
27
+ I18n.backend.translate 'en', :bar, :scope => [:foo], :count => 1
28
+ end
29
+
30
+ def test_translate_calls_interpolate
31
+ I18n.backend.expects(:interpolate).with 'en', 'bar', {}
32
+ I18n.backend.translate 'en', :bar, :scope => [:foo]
33
+ end
34
+
35
+ def test_translate_calls_interpolate_including_count_as_a_value
36
+ I18n.backend.expects(:interpolate).with 'en', 'bar', {:count => 1}
37
+ I18n.backend.translate 'en', :bar, :scope => [:foo], :count => 1
38
+ end
39
+ end
40
+
41
+ class I18nSimpleBackendApiInterpolateTest < Test::Unit::TestCase
42
+ include Tests::Backend::Simple::Setup::Base
43
+ include Tests::Backend::Api::Interpolation
44
+
45
+ # implementation specific tests
46
+
47
+ def test_interpolate_given_nil_as_a_string_returns_nil
48
+ assert_nil I18n.backend.send(:interpolate, nil, nil, :name => 'David')
49
+ end
50
+
51
+ def test_interpolate_given_an_non_string_as_a_string_returns_nil
52
+ assert_equal [], I18n.backend.send(:interpolate, nil, [], :name => 'David')
53
+ end
54
+ end
55
+
56
+ class I18nSimpleBackendApiLambdaTest < Test::Unit::TestCase
57
+ include Tests::Backend::Simple::Setup::Base
58
+ include Tests::Backend::Api::Lambda
59
+ end
60
+
61
+ class I18nSimpleBackendApiTranslateLinkedTest < Test::Unit::TestCase
62
+ include Tests::Backend::Simple::Setup::Base
63
+ include Tests::Backend::Api::Link
64
+ end
65
+
66
+ class I18nSimpleBackendApiPluralizationTest < Test::Unit::TestCase
67
+ include Tests::Backend::Simple::Setup::Base
68
+ include Tests::Backend::Api::Pluralization
69
+ end
70
+
71
+ class I18nSimpleBackendApiLocalizeDateTest < Test::Unit::TestCase
72
+ include Tests::Backend::Simple::Setup::Localization
73
+ include Tests::Backend::Api::Localization::Date
74
+ end
75
+
76
+ class I18nSimpleBackendApiLocalizeDateTimeTest < Test::Unit::TestCase
77
+ include Tests::Backend::Simple::Setup::Localization
78
+ include Tests::Backend::Api::Localization::DateTime
79
+ end
80
+
81
+ class I18nSimpleBackendApiLocalizeTimeTest < Test::Unit::TestCase
82
+ include Tests::Backend::Simple::Setup::Localization
83
+ include Tests::Backend::Api::Localization::Time
84
+ end
85
+
86
+ class I18nSimpleBackendApiLocalizeLambdaTest < Test::Unit::TestCase
87
+ include Tests::Backend::Simple::Setup::Localization
88
+ include Tests::Backend::Api::Localization::Lambda
89
+ end
90
+
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
4
+
5
+ class I18nSimpleBackendLookupTest < Test::Unit::TestCase
6
+ include Tests::Backend::Simple::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,147 @@
1
+ # encoding: utf-8
2
+
3
+ module Tests
4
+ module Backend
5
+ module Simple
6
+ module Setup
7
+ module Base
8
+ def setup
9
+ super
10
+ I18n.locale = nil
11
+ I18n.default_locale = :en
12
+ I18n.backend = I18n::Backend::Simple.new
13
+ backend_store_translations :en, :foo => {:bar => 'bar', :baz => 'baz'}
14
+ end
15
+
16
+ def teardown
17
+ super
18
+ I18n.load_path = []
19
+ I18n.backend = nil
20
+ end
21
+ end
22
+
23
+ module Localization
24
+ include Base
25
+
26
+ def setup
27
+ super
28
+ setup_datetime_translations
29
+ setup_datetime_lambda_translations
30
+ @old_timezone, ENV['TZ'] = ENV['TZ'], 'UTC'
31
+ end
32
+
33
+ def teardown
34
+ super
35
+ @old_timezone ? ENV['TZ'] = @old_timezone : ENV.delete('TZ')
36
+ end
37
+
38
+ def setup_datetime_translations
39
+ backend_store_translations :de, {
40
+ :date => {
41
+ :formats => {
42
+ :default => "%d.%m.%Y",
43
+ :short => "%d. %b",
44
+ :long => "%d. %B %Y",
45
+ :long_ordinalized => lambda { |date, options|
46
+ tz = " (#{options[:timezone]})" if options[:timezone]
47
+ "#{date.day}ter %B %Y#{tz}"
48
+ }
49
+ },
50
+ :day_names => %w(Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag),
51
+ :abbr_day_names => %w(So Mo Di Mi Do Fr Sa),
52
+ :month_names => %w(Januar Februar März April Mai Juni Juli August September Oktober November Dezember).unshift(nil),
53
+ :abbr_month_names => %w(Jan Feb Mar Apr Mai Jun Jul Aug Sep Okt Nov Dez).unshift(nil),
54
+ :order => [:day, :month, :year]
55
+ },
56
+ :time => {
57
+ :formats => {
58
+ :default => "%a, %d. %b %Y %H:%M:%S %z",
59
+ :short => "%d. %b %H:%M",
60
+ :long => "%d. %B %Y %H:%M",
61
+ :long_ordinalized => lambda { |date, options|
62
+ tz = " (#{options[:timezone]})" if options[:timezone]
63
+ "#{date.day}ter %B %Y, %H:%M Uhr#{tz}"
64
+ }
65
+ },
66
+ :am => 'am',
67
+ :pm => 'pm'
68
+ },
69
+ :datetime => {
70
+ :distance_in_words => {
71
+ :half_a_minute => 'half a minute',
72
+ :less_than_x_seconds => {
73
+ :one => 'less than 1 second',
74
+ :other => 'less than {{count}} seconds'
75
+ },
76
+ :x_seconds => {
77
+ :one => '1 second',
78
+ :other => '{{count}} seconds'
79
+ },
80
+ :less_than_x_minutes => {
81
+ :one => 'less than a minute',
82
+ :other => 'less than {{count}} minutes'
83
+ },
84
+ :x_minutes => {
85
+ :one => '1 minute',
86
+ :other => '{{count}} minutes'
87
+ },
88
+ :about_x_hours => {
89
+ :one => 'about 1 hour',
90
+ :other => 'about {{count}} hours'
91
+ },
92
+ :x_days => {
93
+ :one => '1 day',
94
+ :other => '{{count}} days'
95
+ },
96
+ :about_x_months => {
97
+ :one => 'about 1 month',
98
+ :other => 'about {{count}} months'
99
+ },
100
+ :x_months => {
101
+ :one => '1 month',
102
+ :other => '{{count}} months'
103
+ },
104
+ :about_x_years => {
105
+ :one => 'about 1 year',
106
+ :other => 'about {{count}} year'
107
+ },
108
+ :over_x_years => {
109
+ :one => 'over 1 year',
110
+ :other => 'over {{count}} years'
111
+ }
112
+ }
113
+ }
114
+ }
115
+ end
116
+
117
+ def setup_datetime_lambda_translations
118
+ backend_store_translations 'ru', {
119
+ :date => {
120
+ :'day_names' => lambda { |key, options|
121
+ (options[:format] =~ /^%A/) ?
122
+ %w(Воскресенье Понедельник Вторник Среда Четверг Пятница Суббота) :
123
+ %w(воскресенье понедельник вторник среда четверг пятница суббота)
124
+ },
125
+ :'abbr_day_names' => %w(Вс Пн Вт Ср Чт Пт Сб),
126
+ :'month_names' => lambda { |key, options|
127
+ (options[:format] =~ /(%d|%e)(\s*)?(%B)/) ?
128
+ %w(января февраля марта апреля мая июня июля августа сентября октября ноября декабря).unshift(nil) :
129
+ %w(Январь Февраль Март Апрель Май Июнь Июль Август Сентябрь Октябрь Ноябрь Декабрь).unshift(nil)
130
+ },
131
+ :'abbr_month_names' => lambda { |key, options|
132
+ (options[:format] =~ /(%d|%e)(\s*)(%b)/) ?
133
+ %w(янв. февр. марта апр. мая июня июля авг. сент. окт. нояб. дек.).unshift(nil) :
134
+ %w(янв. февр. март апр. май июнь июль авг. сент. окт. нояб. дек.).unshift(nil)
135
+ },
136
+ },
137
+ :time => {
138
+ :am => "утра",
139
+ :pm => "вечера"
140
+ }
141
+ }
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,89 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
4
+
5
+ class I18nSimpleBackendLoadTranslationsTest < Test::Unit::TestCase
6
+ include Tests::Backend::Simple::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::Simple.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 I18nSimpleBackendStoreTranslationsTest < Test::Unit::TestCase
35
+ include Tests::Backend::Simple::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 I18nSimpleBackendReloadTranslationsTest < Test::Unit::TestCase
67
+ include Tests::Backend::Simple::Setup::Base
68
+
69
+ def setup
70
+ I18n.backend = I18n::Backend::Simple.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