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.
- data/CHANGELOG.textile +57 -0
- data/MIT-LICENSE +19 -19
- data/README.textile +20 -18
- data/Rakefile +21 -0
- data/VERSION +1 -0
- data/lib/i18n.rb +229 -192
- data/lib/i18n/backend/simple.rb +233 -193
- data/lib/i18n/exceptions.rb +59 -53
- data/lib/i18n/string.rb +93 -0
- data/test/all.rb +3 -5
- data/test/api/basics.rb +13 -0
- data/test/api/interpolation.rb +63 -0
- data/test/api/lambda.rb +50 -0
- data/test/api/link.rb +45 -0
- data/test/api/localization/date.rb +63 -0
- data/test/api/localization/date_time.rb +61 -0
- data/test/api/localization/lambda.rb +24 -0
- data/test/api/localization/time.rb +61 -0
- data/test/api/pluralization.rb +40 -0
- data/test/api/translation.rb +49 -0
- data/test/backend/simple/all.rb +3 -0
- data/test/backend/simple/api_test.rb +85 -0
- data/test/backend/simple/lookup_test.rb +23 -0
- data/test/backend/simple/setup/base.rb +21 -0
- data/test/backend/simple/setup/localization.rb +129 -0
- data/test/backend/simple/translations_test.rb +88 -0
- data/test/fixtures/locales/en.rb +1 -0
- data/test/fixtures/locales/en.yml +3 -0
- data/test/i18n_exceptions_test.rb +94 -99
- data/test/i18n_load_path_test.rb +16 -0
- data/test/i18n_test.rb +140 -141
- data/test/string_test.rb +92 -0
- data/test/test_helper.rb +59 -0
- data/test/with_options.rb +32 -0
- metadata +71 -22
- data/test/locale/en-US.rb +0 -1
- data/test/locale/en-US.yml +0 -3
- data/test/simple_backend_test.rb +0 -473
@@ -0,0 +1 @@
|
|
1
|
+
{ :en => { :fuh => { :bah => "bas" } } }
|
@@ -1,100 +1,95 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
def
|
11
|
-
force_invalid_locale
|
12
|
-
rescue I18n::ArgumentError => e
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
def
|
17
|
-
|
18
|
-
rescue I18n::ArgumentError => e
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
assert_equal
|
29
|
-
end
|
30
|
-
|
31
|
-
def
|
32
|
-
|
33
|
-
rescue I18n::ArgumentError => e
|
34
|
-
assert_equal
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
assert_equal 1, e.
|
42
|
-
end
|
43
|
-
|
44
|
-
def
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
I18n.backend.translate
|
79
|
-
end
|
80
|
-
|
81
|
-
def
|
82
|
-
I18n.store_translations 'de
|
83
|
-
I18n.backend.translate 'de
|
84
|
-
end
|
85
|
-
|
86
|
-
def
|
87
|
-
I18n.store_translations 'de
|
88
|
-
I18n.backend.translate 'de
|
89
|
-
end
|
90
|
-
|
91
|
-
def
|
92
|
-
I18n.store_translations 'de
|
93
|
-
I18n.backend.translate 'de
|
94
|
-
end
|
95
|
-
|
96
|
-
def force_reserved_interpolation_key
|
97
|
-
I18n.store_translations 'de-DE', :foo => "{{scope}}"
|
98
|
-
I18n.backend.translate 'de-DE', :foo, :baz => 'baz'
|
99
|
-
end
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
2
|
+
|
3
|
+
class I18nExceptionsTest < Test::Unit::TestCase
|
4
|
+
def test_invalid_locale_stores_locale
|
5
|
+
force_invalid_locale
|
6
|
+
rescue I18n::ArgumentError => e
|
7
|
+
assert_nil e.locale
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_invalid_locale_message
|
11
|
+
force_invalid_locale
|
12
|
+
rescue I18n::ArgumentError => e
|
13
|
+
assert_equal 'nil is not a valid locale', e.message
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_missing_translation_data_stores_locale_key_and_options
|
17
|
+
force_missing_translation_data
|
18
|
+
rescue I18n::ArgumentError => e
|
19
|
+
options = {:scope => :bar}
|
20
|
+
assert_equal 'de', e.locale
|
21
|
+
assert_equal :foo, e.key
|
22
|
+
assert_equal options, e.options
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_missing_translation_data_message
|
26
|
+
force_missing_translation_data
|
27
|
+
rescue I18n::ArgumentError => e
|
28
|
+
assert_equal 'translation missing: de, bar, foo', e.message
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_invalid_pluralization_data_stores_entry_and_count
|
32
|
+
force_invalid_pluralization_data
|
33
|
+
rescue I18n::ArgumentError => e
|
34
|
+
assert_equal [:bar], e.entry
|
35
|
+
assert_equal 1, e.count
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_invalid_pluralization_data_message
|
39
|
+
force_invalid_pluralization_data
|
40
|
+
rescue I18n::ArgumentError => e
|
41
|
+
assert_equal 'translation data [:bar] can not be used with :count => 1', e.message
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_missing_interpolation_argument_stores_key_and_string
|
45
|
+
assert_raises(I18n::MissingInterpolationArgument) { force_missing_interpolation_argument }
|
46
|
+
force_missing_interpolation_argument
|
47
|
+
rescue I18n::ArgumentError => e
|
48
|
+
# assert_equal :bar, e.key
|
49
|
+
assert_equal "{{bar}}", e.string
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_missing_interpolation_argument_message
|
53
|
+
force_missing_interpolation_argument
|
54
|
+
rescue I18n::ArgumentError => e
|
55
|
+
assert_equal 'missing interpolation argument in "{{bar}}" ({:baz=>"baz"} given)', e.message
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_reserved_interpolation_key_stores_key_and_string
|
59
|
+
force_reserved_interpolation_key
|
60
|
+
rescue I18n::ArgumentError => e
|
61
|
+
assert_equal :scope, e.key
|
62
|
+
assert_equal "{{scope}}", e.string
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_reserved_interpolation_key_message
|
66
|
+
force_reserved_interpolation_key
|
67
|
+
rescue I18n::ArgumentError => e
|
68
|
+
assert_equal 'reserved key :scope used in "{{scope}}"', e.message
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
def force_invalid_locale
|
73
|
+
I18n.backend.translate nil, :foo
|
74
|
+
end
|
75
|
+
|
76
|
+
def force_missing_translation_data
|
77
|
+
I18n.backend.store_translations 'de', :bar => nil
|
78
|
+
I18n.backend.translate 'de', :foo, :scope => :bar
|
79
|
+
end
|
80
|
+
|
81
|
+
def force_invalid_pluralization_data
|
82
|
+
I18n.backend.store_translations 'de', :foo => [:bar]
|
83
|
+
I18n.backend.translate 'de', :foo, :count => 1
|
84
|
+
end
|
85
|
+
|
86
|
+
def force_missing_interpolation_argument
|
87
|
+
I18n.backend.store_translations 'de', :foo => "{{bar}}"
|
88
|
+
I18n.backend.translate 'de', :foo, :baz => 'baz'
|
89
|
+
end
|
90
|
+
|
91
|
+
def force_reserved_interpolation_key
|
92
|
+
I18n.backend.store_translations 'de', :foo => "{{scope}}"
|
93
|
+
I18n.backend.translate 'de', :foo, :baz => 'baz'
|
94
|
+
end
|
100
95
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
3
|
+
|
4
|
+
class I18nLoadPathTest < Test::Unit::TestCase
|
5
|
+
include Tests::Backend::Simple::Setup::Base
|
6
|
+
|
7
|
+
def test_nested_load_paths_do_not_break_locale_loading
|
8
|
+
I18n.load_path = [[locales_dir + '/en.yml']]
|
9
|
+
assert_equal "baz", I18n.t(:'foo.bar')
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_adding_arrays_of_filenames_to_load_path_do_not_break_locale_loading
|
13
|
+
I18n.load_path << Dir[locales_dir + '/*.{rb,yml}']
|
14
|
+
assert_equal "baz", I18n.t(:'foo.bar')
|
15
|
+
end
|
16
|
+
end
|
data/test/i18n_test.rb
CHANGED
@@ -1,141 +1,140 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
def
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
def
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
assert_equal
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
assert_equal '
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
I18n.
|
59
|
-
I18n.
|
60
|
-
I18n.
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
I18n.
|
76
|
-
I18n.
|
77
|
-
end
|
78
|
-
|
79
|
-
def
|
80
|
-
I18n.backend.expects(:
|
81
|
-
I18n.
|
82
|
-
end
|
83
|
-
|
84
|
-
def
|
85
|
-
|
86
|
-
I18n.
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
I18n.
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
I18n.
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
#
|
127
|
-
#
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
end
|
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
|
+
end
|