i18n 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of i18n might be problematic. Click here for more details.

data/test/string_test.rb CHANGED
@@ -1,92 +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
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
data/test/test_helper.rb CHANGED
@@ -1,59 +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
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
59
  end
data/test/with_options.rb CHANGED
@@ -1,32 +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
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
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Fuchs
@@ -13,7 +13,7 @@ autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
15
 
16
- date: 2009-07-16 00:00:00 +02:00
16
+ date: 2009-07-12 00:00:00 +02:00
17
17
  default_executable:
18
18
  dependencies: []
19
19
 
@@ -83,33 +83,33 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  version:
84
84
  requirements: []
85
85
 
86
- rubyforge_project: i18n
87
- rubygems_version: 1.3.2
86
+ rubyforge_project:
87
+ rubygems_version: 1.3.5
88
88
  signing_key:
89
- specification_version: 3
89
+ specification_version: 2
90
90
  summary: New wave Internationalization support for Ruby
91
91
  test_files:
92
- - test/string_test.rb
93
- - test/fixtures/locales/en.rb
92
+ - test/all.rb
93
+ - test/api/basics.rb
94
+ - test/api/interpolation.rb
95
+ - test/api/lambda.rb
96
+ - test/api/link.rb
97
+ - test/api/localization/date.rb
94
98
  - test/api/localization/date_time.rb
95
99
  - test/api/localization/lambda.rb
96
100
  - test/api/localization/time.rb
97
- - test/api/localization/date.rb
98
- - test/api/link.rb
99
101
  - test/api/pluralization.rb
100
- - test/api/lambda.rb
101
- - test/api/interpolation.rb
102
- - test/api/basics.rb
103
102
  - 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
103
+ - test/backend/simple/all.rb
108
104
  - test/backend/simple/api_test.rb
109
105
  - test/backend/simple/lookup_test.rb
110
- - test/backend/simple/all.rb
111
- - test/test_helper.rb
106
+ - test/backend/simple/setup/base.rb
107
+ - test/backend/simple/setup/localization.rb
108
+ - test/backend/simple/translations_test.rb
109
+ - test/fixtures/locales/en.rb
112
110
  - test/i18n_exceptions_test.rb
113
- - test/all.rb
114
111
  - test/i18n_load_path_test.rb
115
112
  - test/i18n_test.rb
113
+ - test/string_test.rb
114
+ - test/test_helper.rb
115
+ - test/with_options.rb