theoooo-i18n 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/test/i18n_test.rb ADDED
@@ -0,0 +1,161 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
+
3
+ class I18nTest < Test::Unit::TestCase
4
+ def setup
5
+ I18n.backend.store_translations :'en', {
6
+ :currency => {
7
+ :format => {
8
+ :separator => '.',
9
+ :delimiter => ',',
10
+ }
11
+ }
12
+ }
13
+ end
14
+
15
+ def test_uses_simple_backend_set_by_default
16
+ assert I18n.backend.is_a?(I18n::Backend::Simple)
17
+ end
18
+
19
+ def test_can_set_backend
20
+ assert_nothing_raised { I18n.backend = self }
21
+ assert_equal self, I18n.backend
22
+ I18n.backend = I18n::Backend::Simple.new
23
+ end
24
+
25
+ def test_uses_en_us_as_default_locale_by_default
26
+ assert_equal :en, I18n.default_locale
27
+ end
28
+
29
+ def test_can_set_default_locale
30
+ assert_nothing_raised { I18n.default_locale = 'de' }
31
+ assert_equal :de, I18n.default_locale
32
+ I18n.default_locale = :en
33
+ end
34
+
35
+ def test_uses_default_locale_as_locale_by_default
36
+ assert_equal I18n.default_locale, I18n.locale
37
+ end
38
+
39
+ def test_can_set_locale_to_thread_current
40
+ assert_nothing_raised { I18n.locale = 'de' }
41
+ assert_equal :de, I18n.locale
42
+ assert_equal :de, Thread.current[:locale]
43
+ I18n.locale = :en
44
+ end
45
+
46
+ def test_defaults_to_dot_as_separator
47
+ assert_equal '.', I18n.default_separator
48
+ end
49
+
50
+ def test_can_set_default_separator
51
+ assert_nothing_raised { I18n.default_separator = "\001" }
52
+ I18n.default_separator = '.' # revert it
53
+ end
54
+
55
+ def test_normalize_keys
56
+ assert_equal [:en, :foo, :bar], I18n.send(:normalize_translation_keys, :en, :bar, :foo)
57
+ assert_equal [:en, :foo, :bar, :baz, :buz], I18n.send(:normalize_translation_keys, :en, :'baz.buz', :'foo.bar')
58
+ assert_equal [:en, :foo, :bar, :baz, :buz], I18n.send(:normalize_translation_keys, :en, 'baz.buz', 'foo.bar')
59
+ assert_equal [:en, :foo, :bar, :baz, :buz], I18n.send(:normalize_translation_keys, :en, %w(baz buz), %w(foo bar))
60
+ assert_equal [:en, :foo, :bar, :baz, :buz], I18n.send(:normalize_translation_keys, :en, [:baz, :buz], [:foo, :bar])
61
+ end
62
+
63
+ def test_uses_passed_separator_to_normalize_keys
64
+ assert_equal [:en, :foo, :bar, :baz, :buz], I18n.send(:normalize_translation_keys, :en, :'baz|buz', :'foo|bar', '|')
65
+ end
66
+
67
+ def test_can_set_exception_handler
68
+ assert_nothing_raised { I18n.exception_handler = :custom_exception_handler }
69
+ I18n.exception_handler = :default_exception_handler # revert it
70
+ end
71
+
72
+ def test_uses_custom_exception_handler
73
+ I18n.exception_handler = :custom_exception_handler
74
+ I18n.expects(:custom_exception_handler)
75
+ I18n.translate :bogus
76
+ I18n.exception_handler = :default_exception_handler # revert it
77
+ end
78
+
79
+ def test_delegates_translate_to_backend
80
+ I18n.backend.expects(:translate).with 'de', :foo, {}
81
+ I18n.translate :foo, :locale => 'de'
82
+ end
83
+
84
+ def test_delegates_localize_to_backend
85
+ I18n.backend.expects(:localize).with 'de', :whatever, :default
86
+ I18n.localize :whatever, :locale => 'de'
87
+ end
88
+
89
+ def test_translate_given_no_locale_uses_i18n_locale
90
+ I18n.backend.expects(:translate).with :en, :foo, {}
91
+ I18n.translate :foo
92
+ end
93
+
94
+ def test_translate_on_nested_symbol_keys_works
95
+ assert_equal ".", I18n.t(:'currency.format.separator')
96
+ end
97
+
98
+ def test_translate_with_nested_string_keys_works
99
+ assert_equal ".", I18n.t('currency.format.separator')
100
+ end
101
+
102
+ def test_translate_with_array_as_scope_works
103
+ assert_equal ".", I18n.t(:separator, :scope => %w(currency format))
104
+ end
105
+
106
+ def test_translate_with_array_containing_dot_separated_strings_as_scope_works
107
+ assert_equal ".", I18n.t(:separator, :scope => ['currency.format'])
108
+ end
109
+
110
+ def test_translate_with_key_array_and_dot_separated_scope_works
111
+ assert_equal [".", ","], I18n.t(%w(separator delimiter), :scope => 'currency.format')
112
+ end
113
+
114
+ def test_translate_with_dot_separated_key_array_and_scope_works
115
+ assert_equal [".", ","], I18n.t(%w(format.separator format.delimiter), :scope => 'currency')
116
+ end
117
+
118
+ def test_translate_with_options_using_scope_works
119
+ I18n.backend.expects(:translate).with('de', :precision, :scope => :"currency.format")
120
+ I18n.with_options :locale => 'de', :scope => :'currency.format' do |locale|
121
+ locale.t :precision
122
+ end
123
+ end
124
+
125
+ # def test_translate_given_no_args_raises_missing_translation_data
126
+ # assert_equal "translation missing: en, no key", I18n.t
127
+ # end
128
+
129
+ def test_translate_given_a_bogus_key_raises_missing_translation_data
130
+ assert_equal "translation missing: en, bogus", I18n.t(:bogus)
131
+ end
132
+
133
+ def test_localize_nil_raises_argument_error
134
+ assert_raises(I18n::ArgumentError) { I18n.l nil }
135
+ end
136
+
137
+ def test_localize_object_raises_argument_error
138
+ assert_raises(I18n::ArgumentError) { I18n.l Object.new }
139
+ end
140
+
141
+ def test_proc_exception_handler
142
+ I18n.exception_handler = Proc.new { |exception, locale, key, options|
143
+ "No exception here! [Proc handler]"
144
+ }
145
+ assert_equal "No exception here! [Proc handler]", I18n.translate(:test_proc_handler)
146
+ ensure
147
+ I18n.exception_handler = :default_exception_handler
148
+ end
149
+
150
+ def test_class_exception_handler
151
+ I18n.exception_handler = Class.new do
152
+ def call(exception, locale, key, options)
153
+ "No exception here! [Class handler]"
154
+ end
155
+ end.new
156
+ assert_equal "No exception here! [Class handler]", I18n.translate(:test_class_handler)
157
+ ensure
158
+ I18n.exception_handler = :default_exception_handler
159
+ end
160
+
161
+ end
@@ -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,71 @@
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'
13
+ require File.dirname(__FILE__) + '/backend/active_record/setup'
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 self.test(name, &block)
23
+ define_method("test: " + name, &block)
24
+ end
25
+
26
+ def euc_jp(string)
27
+ string.encode!(Encoding::EUC_JP)
28
+ end
29
+
30
+ def locales_dir
31
+ File.dirname(__FILE__) + '/fixtures/locales'
32
+ end
33
+
34
+ def backend_store_translations(*args)
35
+ I18n.backend.store_translations(*args)
36
+ end
37
+
38
+ def backend_get_translations
39
+ I18n.backend.instance_variable_get :@translations
40
+ end
41
+
42
+ def date
43
+ Date.new(2008, 3, 1)
44
+ end
45
+
46
+ def morning_datetime
47
+ DateTime.new(2008, 3, 1, 6)
48
+ end
49
+ alias :datetime :morning_datetime
50
+
51
+ def evening_datetime
52
+ DateTime.new(2008, 3, 1, 18)
53
+ end
54
+
55
+ def morning_time
56
+ Time.parse('2008-03-01 6:00 UTC')
57
+ end
58
+ alias :time :morning_time
59
+
60
+ def evening_time
61
+ Time.parse('2008-03-01 18:00 UTC')
62
+ end
63
+ end
64
+
65
+ class Object
66
+ def meta_class
67
+ class << self; self; end
68
+ end
69
+ end
70
+
71
+
@@ -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 ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: theoooo-i18n
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Sven Fuchs
8
+ - Joshua Harvey
9
+ - Matt Aimonetti
10
+ - Stephan Soller
11
+ - Saimon Moore
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2009-07-12 00:00:00 -07:00
17
+ default_executable:
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: ruby2ruby
21
+ type: :runtime
22
+ version_requirement:
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "="
26
+ - !ruby/object:Gem::Version
27
+ version: 1.2.2
28
+ version:
29
+ description: Add Internationalization support to your Ruby application.
30
+ email: rails-i18n@googlegroups.com
31
+ executables: []
32
+
33
+ extensions: []
34
+
35
+ extra_rdoc_files:
36
+ - README.textile
37
+ files:
38
+ - CHANGELOG.textile
39
+ - MIT-LICENSE
40
+ - README.textile
41
+ - Rakefile
42
+ - VERSION
43
+ - lib/i18n.rb
44
+ - lib/i18n/backend/simple.rb
45
+ - lib/i18n/backend/active_record.rb
46
+ - lib/i18n/backend/active_record/translation.rb
47
+ - lib/i18n/exceptions.rb
48
+ - lib/i18n/string.rb
49
+ - test/all.rb
50
+ - test/api/basics.rb
51
+ - test/api/interpolation.rb
52
+ - test/api/lambda.rb
53
+ - test/api/link.rb
54
+ - test/api/localization/date.rb
55
+ - test/api/localization/date_time.rb
56
+ - test/api/localization/lambda.rb
57
+ - test/api/localization/time.rb
58
+ - test/api/pluralization.rb
59
+ - test/api/translation.rb
60
+ - test/backend/simple/all.rb
61
+ - test/backend/simple/api_test.rb
62
+ - test/backend/simple/lookup_test.rb
63
+ - test/backend/simple/setup.rb
64
+ - test/backend/simple/translations_test.rb
65
+ - test/backend/active_record/api_test.rb
66
+ - test/backend/active_record/setup.rb
67
+ - test/fixtures/locales/en.rb
68
+ - test/fixtures/locales/en.yml
69
+ - test/i18n_exceptions_test.rb
70
+ - test/i18n_load_path_test.rb
71
+ - test/i18n_test.rb
72
+ - test/string_test.rb
73
+ - test/test_helper.rb
74
+ - test/with_options.rb
75
+ has_rdoc: true
76
+ homepage: http://rails-i18n.org
77
+ licenses:
78
+ post_install_message:
79
+ rdoc_options:
80
+ - --charset=UTF-8
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ version:
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: "0"
94
+ version:
95
+ requirements: []
96
+
97
+ rubyforge_project:
98
+ rubygems_version: 1.3.5
99
+ signing_key:
100
+ specification_version: 2
101
+ summary: New wave Internationalization support for Ruby
102
+ test_files:
103
+ - test/all.rb
104
+ - test/api/basics.rb
105
+ - test/api/interpolation.rb
106
+ - test/api/lambda.rb
107
+ - test/api/link.rb
108
+ - test/api/localization/date.rb
109
+ - test/api/localization/date_time.rb
110
+ - test/api/localization/lambda.rb
111
+ - test/api/localization/time.rb
112
+ - test/api/pluralization.rb
113
+ - test/api/translation.rb
114
+ - test/backend/simple/all.rb
115
+ - test/backend/simple/api_test.rb
116
+ - test/backend/simple/lookup_test.rb
117
+ - test/backend/simple/setup.rb
118
+ - test/backend/simple/translations_test.rb
119
+ - test/backend/active_record/api_test.rb
120
+ - test/backend/active_record/setup.rb
121
+ - test/fixtures/locales/en.rb
122
+ - test/i18n_exceptions_test.rb
123
+ - test/i18n_load_path_test.rb
124
+ - test/i18n_test.rb
125
+ - test/string_test.rb
126
+ - test/test_helper.rb
127
+ - test/with_options.rb