i18n 0.1.0 → 0.2.0

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.

@@ -0,0 +1,92 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
+
3
+ # thanks to Masao's String extensions these should work the same in
4
+ # Ruby 1.8 (patched) and Ruby 1.9 (native)
5
+ # some tests taken from Masao's tests
6
+ # http://github.com/mutoh/gettext/blob/edbbe1fa8238fa12c7f26f2418403015f0270e47/test/test_string.rb
7
+
8
+ class I18nStringTest < Test::Unit::TestCase
9
+ define_method :"test: String interpolates a single argument" do
10
+ assert_equal "Masao", "%s" % "Masao"
11
+ end
12
+
13
+ define_method :"test: String interpolates an array argument" do
14
+ assert_equal "1 message", "%d %s" % [1, 'message']
15
+ end
16
+
17
+ define_method :"test: String interpolates a hash argument w/ named placeholders" do
18
+ assert_equal "Masao Mutoh", "%{first} %{last}" % { :first => 'Masao', :last => 'Mutoh' }
19
+ end
20
+
21
+ define_method :"test: String interpolates a hash argument w/ named placeholders (reverse order)" do
22
+ assert_equal "Mutoh, Masao", "%{last}, %{first}" % { :first => 'Masao', :last => 'Mutoh' }
23
+ end
24
+
25
+ define_method :"test: String interpolates named placeholders with sprintf syntax" do
26
+ assert_equal "10, 43.4", "%<integer>d, %<float>.1f" % {:integer => 10, :float => 43.4}
27
+ end
28
+
29
+ define_method :"test: String interpolates named placeholders with sprintf syntax, does not recurse" do
30
+ assert_equal "%<not_translated>s", "%{msg}" % { :msg => '%<not_translated>s', :not_translated => 'should not happen' }
31
+ end
32
+
33
+ define_method :"test: String interpolation does not replace anything when no placeholders are given" do
34
+ assert_equal("aaa", "aaa" % {:num => 1})
35
+ assert_equal("bbb", "bbb" % [1])
36
+ end
37
+
38
+ define_method :"test: String interpolation sprintf behaviour equals Ruby 1.9 behaviour" do
39
+ assert_equal("1", "%<num>d" % {:num => 1})
40
+ assert_equal("0b1", "%<num>#b" % {:num => 1})
41
+ assert_equal("foo", "%<msg>s" % {:msg => "foo"})
42
+ assert_equal("1.000000", "%<num>f" % {:num => 1.0})
43
+ assert_equal(" 1", "%<num>3.0f" % {:num => 1.0})
44
+ assert_equal("100.00", "%<num>2.2f" % {:num => 100.0})
45
+ assert_equal("0x64", "%<num>#x" % {:num => 100.0})
46
+ assert_raise(ArgumentError) { "%<num>,d" % {:num => 100} }
47
+ assert_raise(ArgumentError) { "%<num>/d" % {:num => 100} }
48
+ end
49
+
50
+ define_method :"test: String interpolation old-style sprintf still works" do
51
+ assert_equal("foo 1.000000", "%s %f" % ["foo", 1.0])
52
+ end
53
+
54
+ define_method :"test: String interpolation raises an ArgumentError when the string has extra placeholders (Array)" do
55
+ assert_raises(ArgumentError) do # Ruby 1.9 msg: "too few arguments"
56
+ "%s %s" % %w(Masao)
57
+ end
58
+ end
59
+
60
+ define_method :"test: String interpolation raises a KeyError when the string has extra placeholders (Hash)" do
61
+ assert_raises(KeyError) do # Ruby 1.9 msg: "key not found"
62
+ "%{first} %{last}" % { :first => 'Masao' }
63
+ end
64
+ end
65
+
66
+ define_method :"test: String interpolation does not raise when passed extra values (Array)" do
67
+ assert_nothing_raised do
68
+ assert_equal "Masao", "%s" % %w(Masao Mutoh)
69
+ end
70
+ end
71
+
72
+ define_method :"test: String interpolation does not raise when passed extra values (Hash)" do
73
+ assert_nothing_raised do
74
+ assert_equal "Masao Mutoh", "%{first} %{last}" % { :first => 'Masao', :last => 'Mutoh', :salutation => 'Mr.' }
75
+ end
76
+ end
77
+
78
+ define_method :"test: % acts as escape character in String interpolation" do
79
+ assert_equal "%{first}", "%%{first}" % { :first => 'Masao' }
80
+ assert_equal("% 1", "%% %<num>d" % {:num => 1.0})
81
+ assert_equal("%{num} %<num>d", "%%{num} %%<num>d" % {:num => 1})
82
+ end
83
+
84
+ def test_sprintf_mix_unformatted_and_formatted_named_placeholders
85
+ assert_equal("foo 1.000000", "%{name} %<num>f" % {:name => "foo", :num => 1.0})
86
+ end
87
+
88
+ def test_string_interpolation_raises_an_argument_error_when_mixing_named_and_unnamed_placeholders
89
+ assert_raises(ArgumentError) { "%{name} %f" % [1.0] }
90
+ assert_raises(ArgumentError) { "%{name} %f" % [1.0, 2.0] }
91
+ end
92
+ end
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+ $:.unshift "lib"
3
+
4
+ require 'rubygems'
5
+ require 'test/unit'
6
+ require 'mocha'
7
+ require 'i18n'
8
+ require 'time'
9
+ require 'yaml'
10
+
11
+ require File.dirname(__FILE__) + '/with_options'
12
+ require File.dirname(__FILE__) + '/backend/simple/setup/base'
13
+ require File.dirname(__FILE__) + '/backend/simple/setup/localization'
14
+
15
+ Dir[File.dirname(__FILE__) + '/api/**/*.rb'].each do |filename|
16
+ require filename
17
+ end
18
+
19
+ $KCODE = 'u' unless RUBY_VERSION >= '1.9'
20
+
21
+ class Test::Unit::TestCase
22
+ def euc_jp(string)
23
+ string.encode!(Encoding::EUC_JP)
24
+ end
25
+
26
+ def locales_dir
27
+ File.dirname(__FILE__) + '/fixtures/locales'
28
+ end
29
+
30
+ def backend_store_translations(*args)
31
+ I18n.backend.store_translations(*args)
32
+ end
33
+
34
+ def backend_get_translations
35
+ I18n.backend.instance_variable_get :@translations
36
+ end
37
+
38
+ def date
39
+ Date.new(2008, 3, 1)
40
+ end
41
+
42
+ def morning_datetime
43
+ DateTime.new(2008, 3, 1, 6)
44
+ end
45
+ alias :datetime :morning_datetime
46
+
47
+ def evening_datetime
48
+ DateTime.new(2008, 3, 1, 18)
49
+ end
50
+
51
+ def morning_time
52
+ Time.parse('2008-03-01 6:00 UTC')
53
+ end
54
+ alias :time :morning_time
55
+
56
+ def evening_time
57
+ Time.parse('2008-03-01 18:00 UTC')
58
+ end
59
+ end
@@ -0,0 +1,32 @@
1
+ # this is only here so we can test I18n works nicely with ActiveSupports
2
+ # with_options. Maybe we can just remove it?
3
+
4
+ class Object
5
+ def with_options(options)
6
+ yield ActiveSupport::OptionMerger.new(self, options)
7
+ end
8
+ end
9
+
10
+ module ActiveSupport
11
+ class OptionMerger #:nodoc:
12
+ instance_methods.each do |method|
13
+ undef_method(method) if method !~ /^(__|instance_eval|class|object_id)/
14
+ end
15
+
16
+ def initialize(context, options)
17
+ @context, @options = context, options
18
+ end
19
+
20
+ private
21
+ def method_missing(method, *arguments, &block)
22
+ if arguments.last.is_a?(Proc)
23
+ proc = arguments.pop
24
+ arguments << lambda { |*args| @options.deep_merge(proc.call(*args)) }
25
+ else
26
+ arguments << (arguments.last.respond_to?(:to_hash) ? @options.deep_merge(arguments.pop) : @options.dup)
27
+ end
28
+
29
+ @context.__send__(method, *arguments, &block)
30
+ end
31
+ end
32
+ end
metadata CHANGED
@@ -1,10 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Fuchs
8
+ - Joshua Harvey
8
9
  - Matt Aimonetti
9
10
  - Stephan Soller
10
11
  - Saimon Moore
@@ -12,35 +13,60 @@ autorequire:
12
13
  bindir: bin
13
14
  cert_chain: []
14
15
 
15
- date: 2008-06-13 00:00:00 +02:00
16
+ date: 2009-07-16 00:00:00 +02:00
16
17
  default_executable:
17
18
  dependencies: []
18
19
 
19
- description: Add Internationalization to your Ruby application.
20
- email: rails-patch-i18n@googlegroups.com
20
+ description: Add Internationalization support to your Ruby application.
21
+ email: rails-i18n@googlegroups.com
21
22
  executables: []
22
23
 
23
24
  extensions: []
24
25
 
25
- extra_rdoc_files: []
26
-
26
+ extra_rdoc_files:
27
+ - README.textile
27
28
  files:
28
- - lib/i18n/backend/simple.rb
29
- - lib/i18n/exceptions.rb
30
- - lib/i18n.rb
29
+ - CHANGELOG.textile
31
30
  - MIT-LICENSE
32
31
  - README.textile
32
+ - Rakefile
33
+ - VERSION
34
+ - lib/i18n.rb
35
+ - lib/i18n/backend/simple.rb
36
+ - lib/i18n/exceptions.rb
37
+ - lib/i18n/string.rb
33
38
  - test/all.rb
39
+ - test/api/basics.rb
40
+ - test/api/interpolation.rb
41
+ - test/api/lambda.rb
42
+ - test/api/link.rb
43
+ - test/api/localization/date.rb
44
+ - test/api/localization/date_time.rb
45
+ - test/api/localization/lambda.rb
46
+ - test/api/localization/time.rb
47
+ - test/api/pluralization.rb
48
+ - test/api/translation.rb
49
+ - test/backend/simple/all.rb
50
+ - test/backend/simple/api_test.rb
51
+ - test/backend/simple/lookup_test.rb
52
+ - test/backend/simple/setup/base.rb
53
+ - test/backend/simple/setup/localization.rb
54
+ - test/backend/simple/translations_test.rb
55
+ - test/fixtures/locales/en.rb
56
+ - test/fixtures/locales/en.yml
34
57
  - test/i18n_exceptions_test.rb
58
+ - test/i18n_load_path_test.rb
35
59
  - test/i18n_test.rb
36
- - test/locale/en-US.rb
37
- - test/locale/en-US.yml
38
- - test/simple_backend_test.rb
39
- has_rdoc: false
40
- homepage: http://groups.google.com/group/rails-patch-i18n
41
- post_install_message:
42
- rdoc_options: []
60
+ - test/string_test.rb
61
+ - test/test_helper.rb
62
+ - test/with_options.rb
63
+ has_rdoc: true
64
+ homepage: http://rails-i18n.org
65
+ licenses: []
43
66
 
67
+ post_install_message:
68
+ rdoc_options:
69
+ - --charset=UTF-8
44
70
  require_paths:
45
71
  - lib
46
72
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -57,10 +83,33 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
83
  version:
58
84
  requirements: []
59
85
 
60
- rubyforge_project:
61
- rubygems_version: 1.2.0
86
+ rubyforge_project: i18n
87
+ rubygems_version: 1.3.2
62
88
  signing_key:
63
- specification_version: 2
64
- summary: Internationalization for Ruby
65
- test_files: []
66
-
89
+ specification_version: 3
90
+ summary: New wave Internationalization support for Ruby
91
+ test_files:
92
+ - test/string_test.rb
93
+ - test/fixtures/locales/en.rb
94
+ - test/api/localization/date_time.rb
95
+ - test/api/localization/lambda.rb
96
+ - test/api/localization/time.rb
97
+ - test/api/localization/date.rb
98
+ - test/api/link.rb
99
+ - test/api/pluralization.rb
100
+ - test/api/lambda.rb
101
+ - test/api/interpolation.rb
102
+ - test/api/basics.rb
103
+ - test/api/translation.rb
104
+ - test/with_options.rb
105
+ - test/backend/simple/translations_test.rb
106
+ - test/backend/simple/setup/base.rb
107
+ - test/backend/simple/setup/localization.rb
108
+ - test/backend/simple/api_test.rb
109
+ - test/backend/simple/lookup_test.rb
110
+ - test/backend/simple/all.rb
111
+ - test/test_helper.rb
112
+ - test/i18n_exceptions_test.rb
113
+ - test/all.rb
114
+ - test/i18n_load_path_test.rb
115
+ - test/i18n_test.rb
@@ -1 +0,0 @@
1
- {:'en-US-Ruby' => {:foo => {:bar => "baz"}}}
@@ -1,3 +0,0 @@
1
- en-US-Yaml:
2
- foo:
3
- bar: baz
@@ -1,473 +0,0 @@
1
- # encoding: utf-8
2
- $:.unshift "lib"
3
-
4
- require 'rubygems'
5
- require 'test/unit'
6
- require 'mocha'
7
- require 'i18n'
8
- require 'time'
9
- require 'yaml'
10
-
11
- module I18nSimpleBackendTestSetup
12
- def setup_backend
13
- # backend_reset_translations!
14
- @backend = I18n::Backend::Simple.new
15
- @backend.store_translations 'en-US', :foo => {:bar => 'bar', :baz => 'baz'}
16
- @locale_dir = File.dirname(__FILE__) + '/locale'
17
- end
18
- alias :setup :setup_backend
19
-
20
- # def backend_reset_translations!
21
- # I18n::Backend::Simple::ClassMethods.send :class_variable_set, :@@translations, {}
22
- # end
23
-
24
- def backend_get_translations
25
- # I18n::Backend::Simple::ClassMethods.send :class_variable_get, :@@translations
26
- @backend.instance_variable_get :@translations
27
- end
28
-
29
- def add_datetime_translations
30
- @backend.store_translations :'de-DE', {
31
- :date => {
32
- :formats => {
33
- :default => "%d.%m.%Y",
34
- :short => "%d. %b",
35
- :long => "%d. %B %Y",
36
- },
37
- :day_names => %w(Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag),
38
- :abbr_day_names => %w(So Mo Di Mi Do Fr Sa),
39
- :month_names => %w(Januar Februar März April Mai Juni Juli August September Oktober November Dezember).unshift(nil),
40
- :abbr_month_names => %w(Jan Feb Mar Apr Mai Jun Jul Aug Sep Okt Nov Dez).unshift(nil),
41
- :order => [:day, :month, :year]
42
- },
43
- :time => {
44
- :formats => {
45
- :default => "%a, %d. %b %Y %H:%M:%S %z",
46
- :short => "%d. %b %H:%M",
47
- :long => "%d. %B %Y %H:%M",
48
- },
49
- :am => 'am',
50
- :pm => 'pm'
51
- },
52
- :datetime => {
53
- :distance_in_words => {
54
- :half_a_minute => 'half a minute',
55
- :less_than_x_seconds => {
56
- :one => 'less than 1 second',
57
- :other => 'less than {{count}} seconds'
58
- },
59
- :x_seconds => {
60
- :one => '1 second',
61
- :other => '{{count}} seconds'
62
- },
63
- :less_than_x_minutes => {
64
- :one => 'less than a minute',
65
- :other => 'less than {{count}} minutes'
66
- },
67
- :x_minutes => {
68
- :one => '1 minute',
69
- :other => '{{count}} minutes'
70
- },
71
- :about_x_hours => {
72
- :one => 'about 1 hour',
73
- :other => 'about {{count}} hours'
74
- },
75
- :x_days => {
76
- :one => '1 day',
77
- :other => '{{count}} days'
78
- },
79
- :about_x_months => {
80
- :one => 'about 1 month',
81
- :other => 'about {{count}} months'
82
- },
83
- :x_months => {
84
- :one => '1 month',
85
- :other => '{{count}} months'
86
- },
87
- :about_x_years => {
88
- :one => 'about 1 year',
89
- :other => 'about {{count}} year'
90
- },
91
- :over_x_years => {
92
- :one => 'over 1 year',
93
- :other => 'over {{count}} years'
94
- }
95
- }
96
- }
97
- }
98
- end
99
- end
100
-
101
- class I18nSimpleBackendTranslationsTest < Test::Unit::TestCase
102
- include I18nSimpleBackendTestSetup
103
-
104
- def test_store_translations_adds_translations # no, really :-)
105
- @backend.store_translations :'en-US', :foo => 'bar'
106
- assert_equal Hash[:'en-US', {:foo => 'bar'}], backend_get_translations
107
- end
108
-
109
- def test_store_translations_deep_merges_translations
110
- @backend.store_translations :'en-US', :foo => {:bar => 'bar'}
111
- @backend.store_translations :'en-US', :foo => {:baz => 'baz'}
112
- assert_equal Hash[:'en-US', {:foo => {:bar => 'bar', :baz => 'baz'}}], backend_get_translations
113
- end
114
-
115
- def test_store_translations_forces_locale_to_sym
116
- @backend.store_translations 'en-US', :foo => 'bar'
117
- assert_equal Hash[:'en-US', {:foo => 'bar'}], backend_get_translations
118
- end
119
-
120
- def test_store_translations_converts_keys_to_symbols
121
- # backend_reset_translations!
122
- @backend.store_translations 'en-US', 'foo' => {'bar' => 'bar', 'baz' => 'baz'}
123
- assert_equal Hash[:'en-US', {:foo => {:bar => 'bar', :baz => 'baz'}}], backend_get_translations
124
- end
125
- end
126
-
127
- class I18nSimpleBackendTranslateTest < Test::Unit::TestCase
128
- include I18nSimpleBackendTestSetup
129
-
130
- def test_translate_calls_lookup_with_locale_given
131
- @backend.expects(:lookup).with('de-DE', :bar, [:foo]).returns 'bar'
132
- @backend.translate 'de-DE', :bar, :scope => [:foo]
133
- end
134
-
135
- def test_given_no_keys_it_returns_the_default
136
- assert_equal 'default', @backend.translate('en-US', nil, :default => 'default')
137
- end
138
-
139
- def test_translate_given_a_symbol_as_a_default_translates_the_symbol
140
- assert_equal 'bar', @backend.translate('en-US', nil, :scope => [:foo], :default => :bar)
141
- end
142
-
143
- def test_translate_given_an_array_as_default_uses_the_first_match
144
- assert_equal 'bar', @backend.translate('en-US', :does_not_exist, :scope => [:foo], :default => [:does_not_exist_2, :bar])
145
- end
146
-
147
- def test_translate_given_an_array_of_inexistent_keys_it_raises_missing_translation_data
148
- assert_raises I18n::MissingTranslationData do
149
- @backend.translate('en-US', :does_not_exist, :scope => [:foo], :default => [:does_not_exist_2, :does_not_exist_3])
150
- end
151
- end
152
-
153
- def test_translate_an_array_of_keys_translates_all_of_them
154
- assert_equal %w(bar baz), @backend.translate('en-US', [:bar, :baz], :scope => [:foo])
155
- end
156
-
157
- def test_translate_calls_pluralize
158
- @backend.expects(:pluralize).with 'en-US', 'bar', 1
159
- @backend.translate 'en-US', :bar, :scope => [:foo], :count => 1
160
- end
161
-
162
- def test_translate_calls_interpolate
163
- @backend.expects(:interpolate).with 'en-US', 'bar', {}
164
- @backend.translate 'en-US', :bar, :scope => [:foo]
165
- end
166
-
167
- def test_translate_calls_interpolate_including_count_as_a_value
168
- @backend.expects(:interpolate).with 'en-US', 'bar', {:count => 1}
169
- @backend.translate 'en-US', :bar, :scope => [:foo], :count => 1
170
- end
171
-
172
- def test_translate_given_nil_as_a_locale_raises_an_argument_error
173
- assert_raises(I18n::InvalidLocale){ @backend.translate nil, :bar }
174
- end
175
-
176
- def test_translate_with_a_bogus_key_and_no_default_raises_missing_translation_data
177
- assert_raises(I18n::MissingTranslationData){ @backend.translate 'de-DE', :bogus }
178
- end
179
- end
180
-
181
- class I18nSimpleBackendLookupTest < Test::Unit::TestCase
182
- include I18nSimpleBackendTestSetup
183
-
184
- # useful because this way we can use the backend with no key for interpolation/pluralization
185
- def test_lookup_given_nil_as_a_key_returns_nil
186
- assert_nil @backend.send(:lookup, 'en-US', nil)
187
- end
188
-
189
- def test_lookup_given_nested_keys_looks_up_a_nested_hash_value
190
- assert_equal 'bar', @backend.send(:lookup, 'en-US', :bar, [:foo])
191
- end
192
- end
193
-
194
- class I18nSimpleBackendPluralizeTest < Test::Unit::TestCase
195
- include I18nSimpleBackendTestSetup
196
-
197
- def test_pluralize_given_nil_returns_the_given_entry
198
- entry = {:one => 'bar', :other => 'bars'}
199
- assert_equal entry, @backend.send(:pluralize, nil, entry, nil)
200
- end
201
-
202
- def test_pluralize_given_0_returns_zero_string_if_zero_key_given
203
- assert_equal 'zero', @backend.send(:pluralize, nil, {:zero => 'zero', :one => 'bar', :other => 'bars'}, 0)
204
- end
205
-
206
- def test_pluralize_given_0_returns_plural_string_if_no_zero_key_given
207
- assert_equal 'bars', @backend.send(:pluralize, nil, {:one => 'bar', :other => 'bars'}, 0)
208
- end
209
-
210
- def test_pluralize_given_1_returns_singular_string
211
- assert_equal 'bar', @backend.send(:pluralize, nil, {:one => 'bar', :other => 'bars'}, 1)
212
- end
213
-
214
- def test_pluralize_given_2_returns_plural_string
215
- assert_equal 'bars', @backend.send(:pluralize, nil, {:one => 'bar', :other => 'bars'}, 2)
216
- end
217
-
218
- def test_pluralize_given_3_returns_plural_string
219
- assert_equal 'bars', @backend.send(:pluralize, nil, {:one => 'bar', :other => 'bars'}, 3)
220
- end
221
-
222
- def test_interpolate_given_incomplete_pluralization_data_raises_invalid_pluralization_data
223
- assert_raises(I18n::InvalidPluralizationData){ @backend.send(:pluralize, nil, {:one => 'bar'}, 2) }
224
- end
225
-
226
- # def test_interpolate_given_a_string_raises_invalid_pluralization_data
227
- # assert_raises(I18n::InvalidPluralizationData){ @backend.send(:pluralize, nil, 'bar', 2) }
228
- # end
229
- #
230
- # def test_interpolate_given_an_array_raises_invalid_pluralization_data
231
- # assert_raises(I18n::InvalidPluralizationData){ @backend.send(:pluralize, nil, ['bar'], 2) }
232
- # end
233
- end
234
-
235
- class I18nSimpleBackendInterpolateTest < Test::Unit::TestCase
236
- include I18nSimpleBackendTestSetup
237
-
238
- def test_interpolate_given_a_value_hash_interpolates_the_values_to_the_string
239
- assert_equal 'Hi David!', @backend.send(:interpolate, nil, 'Hi {{name}}!', :name => 'David')
240
- end
241
-
242
- def test_interpolate_given_a_value_hash_interpolates_into_unicode_string
243
- assert_equal 'Häi David!', @backend.send(:interpolate, nil, 'Häi {{name}}!', :name => 'David')
244
- end
245
-
246
- def test_interpolate_given_nil_as_a_string_returns_nil
247
- assert_nil @backend.send(:interpolate, nil, nil, :name => 'David')
248
- end
249
-
250
- def test_interpolate_given_an_non_string_as_a_string_returns_nil
251
- assert_equal [], @backend.send(:interpolate, nil, [], :name => 'David')
252
- end
253
-
254
- def test_interpolate_given_a_values_hash_with_nil_values_interpolates_the_string
255
- assert_equal 'Hi !', @backend.send(:interpolate, nil, 'Hi {{name}}!', {:name => nil})
256
- end
257
-
258
- def test_interpolate_given_an_empty_values_hash_raises_missing_interpolation_argument
259
- assert_raises(I18n::MissingInterpolationArgument) { @backend.send(:interpolate, nil, 'Hi {{name}}!', {}) }
260
- end
261
-
262
- def test_interpolate_given_a_string_containing_a_reserved_key_raises_reserved_interpolation_key
263
- assert_raises(I18n::ReservedInterpolationKey) { @backend.send(:interpolate, nil, '{{default}}', {:default => nil}) }
264
- end
265
- end
266
-
267
- class I18nSimpleBackendLocalizeDateTest < Test::Unit::TestCase
268
- include I18nSimpleBackendTestSetup
269
-
270
- def setup
271
- @backend = I18n::Backend::Simple.new
272
- add_datetime_translations
273
- @date = Date.new 2008, 1, 1
274
- end
275
-
276
- def test_translate_given_the_short_format_it_uses_it
277
- assert_equal '01. Jan', @backend.localize('de-DE', @date, :short)
278
- end
279
-
280
- def test_translate_given_the_long_format_it_uses_it
281
- assert_equal '01. Januar 2008', @backend.localize('de-DE', @date, :long)
282
- end
283
-
284
- def test_translate_given_the_default_format_it_uses_it
285
- assert_equal '01.01.2008', @backend.localize('de-DE', @date, :default)
286
- end
287
-
288
- def test_translate_given_a_day_name_format_it_returns_a_day_name
289
- assert_equal 'Dienstag', @backend.localize('de-DE', @date, '%A')
290
- end
291
-
292
- def test_translate_given_an_abbr_day_name_format_it_returns_an_abbrevated_day_name
293
- assert_equal 'Di', @backend.localize('de-DE', @date, '%a')
294
- end
295
-
296
- def test_translate_given_a_month_name_format_it_returns_a_month_name
297
- assert_equal 'Januar', @backend.localize('de-DE', @date, '%B')
298
- end
299
-
300
- def test_translate_given_an_abbr_month_name_format_it_returns_an_abbrevated_month_name
301
- assert_equal 'Jan', @backend.localize('de-DE', @date, '%b')
302
- end
303
-
304
- def test_translate_given_no_format_it_does_not_fail
305
- assert_nothing_raised{ @backend.localize 'de-DE', @date }
306
- end
307
-
308
- def test_translate_given_an_unknown_format_it_does_not_fail
309
- assert_nothing_raised{ @backend.localize 'de-DE', @date, '%x' }
310
- end
311
-
312
- def test_localize_nil_raises_argument_error
313
- assert_raises(I18n::ArgumentError) { @backend.localize 'de-DE', nil }
314
- end
315
-
316
- def test_localize_object_raises_argument_error
317
- assert_raises(I18n::ArgumentError) { @backend.localize 'de-DE', Object.new }
318
- end
319
- end
320
-
321
- class I18nSimpleBackendLocalizeDateTimeTest < Test::Unit::TestCase
322
- include I18nSimpleBackendTestSetup
323
-
324
- def setup
325
- @backend = I18n::Backend::Simple.new
326
- add_datetime_translations
327
- @morning = DateTime.new 2008, 1, 1, 6
328
- @evening = DateTime.new 2008, 1, 1, 18
329
- end
330
-
331
- def test_translate_given_the_short_format_it_uses_it
332
- assert_equal '01. Jan 06:00', @backend.localize('de-DE', @morning, :short)
333
- end
334
-
335
- def test_translate_given_the_long_format_it_uses_it
336
- assert_equal '01. Januar 2008 06:00', @backend.localize('de-DE', @morning, :long)
337
- end
338
-
339
- def test_translate_given_the_default_format_it_uses_it
340
- assert_equal 'Di, 01. Jan 2008 06:00:00 +0000', @backend.localize('de-DE', @morning, :default)
341
- end
342
-
343
- def test_translate_given_a_day_name_format_it_returns_the_correct_day_name
344
- assert_equal 'Dienstag', @backend.localize('de-DE', @morning, '%A')
345
- end
346
-
347
- def test_translate_given_an_abbr_day_name_format_it_returns_the_correct_abbrevated_day_name
348
- assert_equal 'Di', @backend.localize('de-DE', @morning, '%a')
349
- end
350
-
351
- def test_translate_given_a_month_name_format_it_returns_the_correct_month_name
352
- assert_equal 'Januar', @backend.localize('de-DE', @morning, '%B')
353
- end
354
-
355
- def test_translate_given_an_abbr_month_name_format_it_returns_the_correct_abbrevated_month_name
356
- assert_equal 'Jan', @backend.localize('de-DE', @morning, '%b')
357
- end
358
-
359
- def test_translate_given_a_meridian_indicator_format_it_returns_the_correct_meridian_indicator
360
- assert_equal 'am', @backend.localize('de-DE', @morning, '%p')
361
- assert_equal 'pm', @backend.localize('de-DE', @evening, '%p')
362
- end
363
-
364
- def test_translate_given_no_format_it_does_not_fail
365
- assert_nothing_raised{ @backend.localize 'de-DE', @morning }
366
- end
367
-
368
- def test_translate_given_an_unknown_format_it_does_not_fail
369
- assert_nothing_raised{ @backend.localize 'de-DE', @morning, '%x' }
370
- end
371
- end
372
-
373
- class I18nSimpleBackendLocalizeTimeTest < Test::Unit::TestCase
374
- include I18nSimpleBackendTestSetup
375
-
376
- def setup
377
- @old_timezone, ENV['TZ'] = ENV['TZ'], 'UTC'
378
- @backend = I18n::Backend::Simple.new
379
- add_datetime_translations
380
- @morning = Time.parse '2008-01-01 6:00 UTC'
381
- @evening = Time.parse '2008-01-01 18:00 UTC'
382
- end
383
-
384
- def teardown
385
- @old_timezone ? ENV['TZ'] = @old_timezone : ENV.delete('TZ')
386
- end
387
-
388
- def test_translate_given_the_short_format_it_uses_it
389
- assert_equal '01. Jan 06:00', @backend.localize('de-DE', @morning, :short)
390
- end
391
-
392
- def test_translate_given_the_long_format_it_uses_it
393
- assert_equal '01. Januar 2008 06:00', @backend.localize('de-DE', @morning, :long)
394
- end
395
-
396
- # TODO Seems to break on Windows because ENV['TZ'] is ignored. What's a better way to do this?
397
- # def test_translate_given_the_default_format_it_uses_it
398
- # assert_equal 'Di, 01. Jan 2008 06:00:00 +0000', @backend.localize('de-DE', @morning, :default)
399
- # end
400
-
401
- def test_translate_given_a_day_name_format_it_returns_the_correct_day_name
402
- assert_equal 'Dienstag', @backend.localize('de-DE', @morning, '%A')
403
- end
404
-
405
- def test_translate_given_an_abbr_day_name_format_it_returns_the_correct_abbrevated_day_name
406
- assert_equal 'Di', @backend.localize('de-DE', @morning, '%a')
407
- end
408
-
409
- def test_translate_given_a_month_name_format_it_returns_the_correct_month_name
410
- assert_equal 'Januar', @backend.localize('de-DE', @morning, '%B')
411
- end
412
-
413
- def test_translate_given_an_abbr_month_name_format_it_returns_the_correct_abbrevated_month_name
414
- assert_equal 'Jan', @backend.localize('de-DE', @morning, '%b')
415
- end
416
-
417
- def test_translate_given_a_meridian_indicator_format_it_returns_the_correct_meridian_indicator
418
- assert_equal 'am', @backend.localize('de-DE', @morning, '%p')
419
- assert_equal 'pm', @backend.localize('de-DE', @evening, '%p')
420
- end
421
-
422
- def test_translate_given_no_format_it_does_not_fail
423
- assert_nothing_raised{ @backend.localize 'de-DE', @morning }
424
- end
425
-
426
- def test_translate_given_an_unknown_format_it_does_not_fail
427
- assert_nothing_raised{ @backend.localize 'de-DE', @morning, '%x' }
428
- end
429
- end
430
-
431
- class I18nSimpleBackendHelperMethodsTest < Test::Unit::TestCase
432
- def setup
433
- @backend = I18n::Backend::Simple.new
434
- end
435
-
436
- def test_deep_symbolize_keys_works
437
- result = @backend.send :deep_symbolize_keys, 'foo' => {'bar' => {'baz' => 'bar'}}
438
- expected = {:foo => {:bar => {:baz => 'bar'}}}
439
- assert_equal expected, result
440
- end
441
- end
442
-
443
- class I18nSimpleBackendLoadTranslationsTest < Test::Unit::TestCase
444
- include I18nSimpleBackendTestSetup
445
-
446
- def test_load_translations_with_unknown_file_type_raises_exception
447
- assert_raises(I18n::UnknownFileType) { @backend.load_translations "#{@locale_dir}/en-US.xml" }
448
- end
449
-
450
- def test_load_translations_with_ruby_file_type_does_not_raise_exception
451
- assert_nothing_raised { @backend.load_translations "#{@locale_dir}/en-US.rb" }
452
- end
453
-
454
- def test_load_rb_loads_data_from_ruby_file
455
- data = @backend.send :load_rb, "#{@locale_dir}/en-US.rb"
456
- assert_equal({:'en-US-Ruby' => {:foo => {:bar => "baz"}}}, data)
457
- end
458
-
459
- def test_load_rb_loads_data_from_yaml_file
460
- data = @backend.send :load_yml, "#{@locale_dir}/en-US.yml"
461
- assert_equal({'en-US-Yaml' => {'foo' => {'bar' => 'baz'}}}, data)
462
- end
463
-
464
- def test_load_translations_loads_from_different_file_formats
465
- @backend = I18n::Backend::Simple.new
466
- @backend.load_translations "#{@locale_dir}/en-US.rb", "#{@locale_dir}/en-US.yml"
467
- expected = {
468
- :'en-US-Ruby' => {:foo => {:bar => "baz"}},
469
- :'en-US-Yaml' => {:foo => {:bar => "baz"}}
470
- }
471
- assert_equal expected, backend_get_translations
472
- end
473
- end