thedarkone-i18n 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,116 @@
1
+ $:.unshift "lib"
2
+
3
+ require 'rubygems'
4
+ require 'test/unit'
5
+ require 'mocha'
6
+ require 'i18n'
7
+ require 'active_support'
8
+
9
+ module I18nExceptionsTest
10
+ def test_invalid_locale_stores_locale
11
+ force_invalid_locale
12
+ rescue I18n::ArgumentError => e
13
+ assert_nil e.locale
14
+ end
15
+
16
+ def test_invalid_locale_message
17
+ force_invalid_locale
18
+ rescue I18n::ArgumentError => e
19
+ assert_equal 'nil is not a valid locale', e.message
20
+ end
21
+
22
+ def test_missing_translation_data_stores_locale_key_and_options
23
+ force_missing_translation_data
24
+ rescue I18n::ArgumentError => e
25
+ options = {:scope => :bar}
26
+ assert_equal 'de', e.locale
27
+ assert_equal :foo, e.key
28
+ assert_equal options, e.options
29
+ end
30
+
31
+ def test_missing_translation_data_message
32
+ force_missing_translation_data
33
+ rescue I18n::ArgumentError => e
34
+ assert_equal 'translation missing: de, bar, foo', e.message
35
+ end
36
+
37
+ def test_invalid_pluralization_data_stores_entry_and_count
38
+ force_invalid_pluralization_data
39
+ rescue I18n::ArgumentError => e
40
+ assert_equal [:bar], e.entry
41
+ assert_equal 1, e.count
42
+ end
43
+
44
+ def test_invalid_pluralization_data_message
45
+ force_invalid_pluralization_data
46
+ rescue I18n::ArgumentError => e
47
+ assert_equal 'translation data [:bar] can not be used with :count => 1', e.message
48
+ end
49
+
50
+ def test_missing_interpolation_argument_stores_key_and_string
51
+ force_missing_interpolation_argument
52
+ rescue I18n::ArgumentError => e
53
+ assert_equal :bar, e.key
54
+ assert_equal "{{bar}}", e.string
55
+ end
56
+
57
+ def test_missing_interpolation_argument_message
58
+ force_missing_interpolation_argument
59
+ rescue I18n::ArgumentError => e
60
+ assert_equal 'interpolation argument :bar missing in "{{bar}}"', e.message
61
+ end
62
+
63
+ def test_reserved_interpolation_key_stores_key_and_string
64
+ force_reserved_interpolation_key
65
+ rescue I18n::ArgumentError => e
66
+ assert_equal :scope, e.key
67
+ assert_equal "{{scope}}", e.string
68
+ end
69
+
70
+ def test_reserved_interpolation_key_message
71
+ force_reserved_interpolation_key
72
+ rescue I18n::ArgumentError => e
73
+ assert_equal 'reserved key :scope used in "{{scope}}"', e.message
74
+ end
75
+
76
+ private
77
+ def force_invalid_locale
78
+ I18n.backend.translate nil, :foo
79
+ end
80
+
81
+ def force_missing_translation_data
82
+ I18n.backend.store_translations 'de', :bar => nil
83
+ I18n.backend.translate 'de', :foo, :scope => :bar
84
+ end
85
+
86
+ def force_invalid_pluralization_data
87
+ I18n.backend.store_translations 'de', :foo => [:bar]
88
+ I18n.backend.translate 'de', :foo, :count => 1
89
+ end
90
+
91
+ def force_missing_interpolation_argument
92
+ I18n.backend.store_translations 'de', :foo => "{{bar}}"
93
+ I18n.backend.translate 'de', :foo, :baz => 'baz'
94
+ end
95
+
96
+ def force_reserved_interpolation_key
97
+ I18n.backend.store_translations 'de', :foo => "{{scope}}"
98
+ I18n.backend.translate 'de', :foo, :baz => 'baz'
99
+ end
100
+ end
101
+
102
+ class I18nSimpleBackendExceptionsTest < Test::Unit::TestCase
103
+ include I18nExceptionsTest
104
+
105
+ def setup
106
+ I18n.backend = I18n::Backend::Simple.new
107
+ end
108
+ end
109
+
110
+ class I18nFastBackendExceptionsTest < Test::Unit::TestCase
111
+ include I18nExceptionsTest
112
+
113
+ def setup
114
+ I18n.backend = I18n::Backend::Fast.new
115
+ end
116
+ end
data/test/i18n_test.rb ADDED
@@ -0,0 +1,125 @@
1
+ $:.unshift "lib"
2
+
3
+ require 'rubygems'
4
+ require 'test/unit'
5
+ require 'mocha'
6
+ require 'i18n'
7
+ require 'active_support'
8
+
9
+ class I18nTest < Test::Unit::TestCase
10
+ def setup
11
+ I18n.backend.store_translations :'en', {
12
+ :currency => {
13
+ :format => {
14
+ :separator => '.',
15
+ :delimiter => ',',
16
+ }
17
+ }
18
+ }
19
+ end
20
+
21
+ def test_uses_simple_backend_set_by_default
22
+ assert I18n.backend.is_a?(I18n::Backend::Simple)
23
+ end
24
+
25
+ def test_can_set_backend
26
+ assert_nothing_raised{ I18n.backend = self }
27
+ assert_equal self, I18n.backend
28
+ I18n.backend = I18n::Backend::Simple.new
29
+ end
30
+
31
+ def test_uses_en_us_as_default_locale_by_default
32
+ assert_equal 'en', I18n.default_locale
33
+ end
34
+
35
+ def test_can_set_default_locale
36
+ assert_nothing_raised{ I18n.default_locale = 'de' }
37
+ assert_equal 'de', I18n.default_locale
38
+ I18n.default_locale = 'en'
39
+ end
40
+
41
+ def test_uses_default_locale_as_locale_by_default
42
+ assert_equal I18n.default_locale, I18n.locale
43
+ end
44
+
45
+ def test_can_set_locale_to_thread_current
46
+ assert_nothing_raised{ I18n.locale = 'de' }
47
+ assert_equal 'de', I18n.locale
48
+ assert_equal 'de', Thread.current[:locale]
49
+ I18n.locale = 'en'
50
+ end
51
+
52
+ def test_can_set_exception_handler
53
+ assert_nothing_raised{ I18n.exception_handler = :custom_exception_handler }
54
+ I18n.exception_handler = :default_exception_handler # revert it
55
+ end
56
+
57
+ def test_uses_custom_exception_handler
58
+ I18n.exception_handler = :custom_exception_handler
59
+ I18n.expects(:custom_exception_handler)
60
+ I18n.translate :bogus
61
+ I18n.exception_handler = :default_exception_handler # revert it
62
+ end
63
+
64
+ def test_delegates_translate_to_backend
65
+ I18n.backend.expects(:translate).with 'de', :foo, {}
66
+ I18n.translate :foo, :locale => 'de'
67
+ end
68
+
69
+ def test_delegates_localize_to_backend
70
+ I18n.backend.expects(:localize).with 'de', :whatever, :default
71
+ I18n.localize :whatever, :locale => 'de'
72
+ end
73
+
74
+ def test_translate_given_no_locale_uses_i18n_locale
75
+ I18n.backend.expects(:translate).with 'en', :foo, nil
76
+ I18n.translate :foo
77
+ end
78
+
79
+ def test_translate_on_nested_symbol_keys_works
80
+ assert_equal ".", I18n.t(:'currency.format.separator')
81
+ end
82
+
83
+ def test_translate_with_nested_string_keys_works
84
+ assert_equal ".", I18n.t('currency.format.separator')
85
+ end
86
+
87
+ def test_translate_with_array_as_scope_works
88
+ assert_equal ".", I18n.t(:separator, :scope => ['currency.format'])
89
+ end
90
+
91
+ def test_translate_with_array_containing_dot_separated_strings_as_scope_works
92
+ assert_equal ".", I18n.t(:separator, :scope => ['currency.format'])
93
+ end
94
+
95
+ def test_translate_with_key_array_and_dot_separated_scope_works
96
+ assert_equal [".", ","], I18n.t(%w(separator delimiter), :scope => 'currency.format')
97
+ end
98
+
99
+ def test_translate_with_dot_separated_key_array_and_scope_works
100
+ assert_equal [".", ","], I18n.t(%w(format.separator format.delimiter), :scope => 'currency')
101
+ end
102
+
103
+ def test_translate_with_options_using_scope_works
104
+ I18n.backend.expects(:translate).with('de', :precision, :scope => :"currency.format")
105
+ I18n.with_options :locale => 'de', :scope => :'currency.format' do |locale|
106
+ locale.t :precision
107
+ end
108
+ end
109
+
110
+ # def test_translate_given_no_args_raises_missing_translation_data
111
+ # assert_equal "translation missing: en, no key", I18n.t
112
+ # end
113
+
114
+ def test_translate_given_a_bogus_key_raises_missing_translation_data
115
+ assert_equal "translation missing: en, bogus", I18n.t(:bogus)
116
+ end
117
+
118
+ def test_localize_nil_raises_argument_error
119
+ assert_raises(I18n::ArgumentError) { I18n.l nil }
120
+ end
121
+
122
+ def test_localize_object_raises_argument_error
123
+ assert_raises(I18n::ArgumentError) { I18n.l Object.new }
124
+ end
125
+ end
data/test/locale/en.rb ADDED
@@ -0,0 +1 @@
1
+ {:'en-Ruby' => {:foo => {:bar => "baz"}}}
@@ -0,0 +1,3 @@
1
+ en-Yaml:
2
+ foo:
3
+ bar: baz
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+ $:.unshift "lib"
3
+
4
+ require 'rubygems'
5
+ require 'test/unit'
6
+ require 'i18n'
7
+
8
+ PluralizationCompiler = I18n::Backend::Fast::PluralizationCompiler
9
+
10
+ class PluralizationCompilerTest < Test::Unit::TestCase
11
+ def assert_escapes(expected, malicious_str)
12
+ assert_equal(expected, PluralizationCompiler.send(:escape_key_sym, malicious_str))
13
+ end
14
+
15
+ def test_escape_key_properly_escapes
16
+ assert_escapes ':"\""', '"'
17
+ assert_escapes ':"\\\\"', '\\'
18
+ assert_escapes ':"\\\\\""', '\\"'
19
+ assert_escapes ':"\#{}"', '#{}'
20
+ assert_escapes ':"\\\\\#{}"', '\#{}'
21
+ end
22
+
23
+ def test_non_interpolated_strings_or_arrays_dont_get_compiled
24
+ ['abc', '\\\\{{a}}', []].each do |obj|
25
+ PluralizationCompiler.compile_if_an_interpolation(obj)
26
+ assert_equal false, obj.respond_to?(:i18n_interpolate)
27
+ end
28
+ end
29
+
30
+ def test_interpolated_string_gets_compiled
31
+ str = '-{{a}}-'
32
+ PluralizationCompiler.compile_if_an_interpolation(str)
33
+ assert_equal '-A-', str.i18n_interpolate(:a => 'A')
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thedarkone-i18n
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Sven Fuchs
8
+ - Joshua Harvey
9
+ - Matt Aimonetti
10
+ - Stephan Soller
11
+ - Saimon Moore
12
+ - thedarkone2@gmail.com
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2009-01-09 00:00:00 -08:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Add Internationalization support to your Ruby application.
22
+ email: rails-i18n@googlegroups.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - i18n.gemspec
31
+ - lib/i18n/backend/simple.rb
32
+ - lib/i18n/backend/fast.rb
33
+ - lib/i18n/backend/fast/pluralization_compiler.rb
34
+ - lib/i18n/exceptions.rb
35
+ - lib/i18n.rb
36
+ - MIT-LICENSE
37
+ - README.textile
38
+ has_rdoc: false
39
+ homepage: http://rails-i18n.org
40
+ post_install_message:
41
+ rdoc_options: []
42
+
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.2.0
61
+ signing_key:
62
+ specification_version: 2
63
+ summary: Internationalization support for Ruby
64
+ test_files:
65
+ - test/all.rb
66
+ - test/i18n_exceptions_test.rb
67
+ - test/i18n_test.rb
68
+ - test/locale/en.rb
69
+ - test/locale/en.yml
70
+ - test/backend_test.rb
71
+ - test/fast_backend_test.rb
72
+ - test/pluralization_compiler_test.rb