i18n 0.3.6 → 0.3.7
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/lib/i18n.rb +29 -4
- data/lib/i18n/backend/active_record/translation.rb +6 -4
- data/lib/i18n/backend/base.rb +1 -1
- data/lib/i18n/locale/fallbacks.rb +4 -4
- data/lib/i18n/version.rb +1 -1
- metadata +16 -116
- data/CHANGELOG.textile +0 -76
- data/MIT-LICENSE +0 -20
- data/README.textile +0 -104
- data/Rakefile +0 -29
- data/test/all.rb +0 -8
- data/test/api.rb +0 -18
- data/test/api/active_record_test.rb +0 -30
- data/test/api/all_features_test.rb +0 -59
- data/test/api/cascade_test.rb +0 -32
- data/test/api/chain_test.rb +0 -27
- data/test/api/fallbacks_test.rb +0 -34
- data/test/api/fast_test.rb +0 -32
- data/test/api/pluralization_test.rb +0 -34
- data/test/api/simple_test.rb +0 -23
- data/test/api/tests/basics.rb +0 -15
- data/test/api/tests/defaults.rb +0 -40
- data/test/api/tests/interpolation.rb +0 -92
- data/test/api/tests/link.rb +0 -56
- data/test/api/tests/localization/date.rb +0 -96
- data/test/api/tests/localization/date_time.rb +0 -93
- data/test/api/tests/localization/procs.rb +0 -60
- data/test/api/tests/localization/time.rb +0 -88
- data/test/api/tests/lookup.rb +0 -62
- data/test/api/tests/pluralization.rb +0 -35
- data/test/api/tests/procs.rb +0 -55
- data/test/backend/active_record/missing_test.rb +0 -51
- data/test/backend/active_record_test.rb +0 -57
- data/test/backend/cache_test.rb +0 -71
- data/test/backend/cascade_test.rb +0 -73
- data/test/backend/chain_test.rb +0 -63
- data/test/backend/cldr_test.rb +0 -151
- data/test/backend/exceptions_test.rb +0 -25
- data/test/backend/fallbacks_test.rb +0 -107
- data/test/backend/fast_test.rb +0 -50
- data/test/backend/helpers_test.rb +0 -27
- data/test/backend/interpolation_compiler_test.rb +0 -108
- data/test/backend/metadata_test.rb +0 -66
- data/test/backend/pluralization_test.rb +0 -47
- data/test/backend/simple_test.rb +0 -77
- data/test/core_ext/string/interpolate_test.rb +0 -99
- data/test/gettext/api_test.rb +0 -207
- data/test/gettext/backend_test.rb +0 -91
- data/test/i18n_exceptions_test.rb +0 -97
- data/test/i18n_load_path_test.rb +0 -23
- data/test/i18n_test.rb +0 -207
- data/test/locale/fallbacks_test.rb +0 -126
- data/test/locale/tag/rfc4646_test.rb +0 -143
- data/test/locale/tag/simple_test.rb +0 -33
- data/test/test_data/locales/cldr/de/calendars.yml +0 -152
- data/test/test_data/locales/cldr/de/currencies.yml +0 -8
- data/test/test_data/locales/cldr/de/numbers.yml +0 -31
- data/test/test_data/locales/de.po +0 -72
- data/test/test_data/locales/en.rb +0 -3
- data/test/test_data/locales/en.yml +0 -3
- data/test/test_data/locales/plurals.rb +0 -113
- data/test/test_helper.rb +0 -116
@@ -1,99 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../../')); $:.uniq!
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
# thanks to Masao's String extensions these should work the same in
|
6
|
-
# Ruby 1.8 (patched) and Ruby 1.9 (native)
|
7
|
-
# some tests taken from Masao's tests
|
8
|
-
# http://github.com/mutoh/gettext/blob/edbbe1fa8238fa12c7f26f2418403015f0270e47/test/test_string.rb
|
9
|
-
|
10
|
-
class I18nCoreExtStringInterpolationTest < Test::Unit::TestCase
|
11
|
-
test "String interpolates a single argument" do
|
12
|
-
assert_equal "Masao", "%s" % "Masao"
|
13
|
-
end
|
14
|
-
|
15
|
-
test "String interpolates an array argument" do
|
16
|
-
assert_equal "1 message", "%d %s" % [1, 'message']
|
17
|
-
end
|
18
|
-
|
19
|
-
test "String interpolates a hash argument w/ named placeholders" do
|
20
|
-
assert_equal "Masao Mutoh", "%{first} %{last}" % { :first => 'Masao', :last => 'Mutoh' }
|
21
|
-
end
|
22
|
-
|
23
|
-
test "String interpolates a hash argument w/ named placeholders (reverse order)" do
|
24
|
-
assert_equal "Mutoh, Masao", "%{last}, %{first}" % { :first => 'Masao', :last => 'Mutoh' }
|
25
|
-
end
|
26
|
-
|
27
|
-
test "String interpolates named placeholders with sprintf syntax" do
|
28
|
-
assert_equal "10, 43.4", "%<integer>d, %<float>.1f" % {:integer => 10, :float => 43.4}
|
29
|
-
end
|
30
|
-
|
31
|
-
test "String interpolates named placeholders with sprintf syntax, does not recurse" do
|
32
|
-
assert_equal "%<not_translated>s", "%{msg}" % { :msg => '%<not_translated>s', :not_translated => 'should not happen' }
|
33
|
-
end
|
34
|
-
|
35
|
-
test "String interpolation does not replace anything when no placeholders are given" do
|
36
|
-
assert_equal("aaa", "aaa" % {:num => 1})
|
37
|
-
assert_equal("bbb", "bbb" % [1])
|
38
|
-
end
|
39
|
-
|
40
|
-
test "String interpolation sprintf behaviour equals Ruby 1.9 behaviour" do
|
41
|
-
assert_equal("1", "%<num>d" % {:num => 1})
|
42
|
-
assert_equal("0b1", "%<num>#b" % {:num => 1})
|
43
|
-
assert_equal("foo", "%<msg>s" % {:msg => "foo"})
|
44
|
-
assert_equal("1.000000", "%<num>f" % {:num => 1.0})
|
45
|
-
assert_equal(" 1", "%<num>3.0f" % {:num => 1.0})
|
46
|
-
assert_equal("100.00", "%<num>2.2f" % {:num => 100.0})
|
47
|
-
assert_equal("0x64", "%<num>#x" % {:num => 100.0})
|
48
|
-
assert_raise(ArgumentError) { "%<num>,d" % {:num => 100} }
|
49
|
-
assert_raise(ArgumentError) { "%<num>/d" % {:num => 100} }
|
50
|
-
end
|
51
|
-
|
52
|
-
test "String interpolation old-style sprintf still works" do
|
53
|
-
assert_equal("foo 1.000000", "%s %f" % ["foo", 1.0])
|
54
|
-
end
|
55
|
-
|
56
|
-
test "String interpolation raises an ArgumentError when the string has extra placeholders (Array)" do
|
57
|
-
assert_raise(ArgumentError) do # Ruby 1.9 msg: "too few arguments"
|
58
|
-
"%s %s" % %w(Masao)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
test "String interpolation raises a KeyError when the string has extra placeholders (Hash)" do
|
63
|
-
assert_raise(KeyError) do # Ruby 1.9 msg: "key not found"
|
64
|
-
"%{first} %{last}" % { :first => 'Masao' }
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
test "String interpolation does not raise when passed extra values (Array)" do
|
69
|
-
assert_nothing_raised do
|
70
|
-
assert_equal "Masao", "%s" % %w(Masao Mutoh)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
test "String interpolation does not raise when passed extra values (Hash)" do
|
75
|
-
assert_nothing_raised do
|
76
|
-
assert_equal "Masao Mutoh", "%{first} %{last}" % { :first => 'Masao', :last => 'Mutoh', :salutation => 'Mr.' }
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
test "% acts as escape character in String interpolation" do
|
81
|
-
assert_equal "%{first}", "%%{first}" % { :first => 'Masao' }
|
82
|
-
assert_equal("% 1", "%% %<num>d" % {:num => 1.0})
|
83
|
-
assert_equal("%{num} %<num>d", "%%{num} %%<num>d" % {:num => 1})
|
84
|
-
end
|
85
|
-
|
86
|
-
test "% can be used in Ruby's own sprintf behavior" do
|
87
|
-
assert_equal "70%", "%d%%" % 70
|
88
|
-
assert_equal "70-100%", "%d-%d%%" % [70, 100]
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_sprintf_mix_unformatted_and_formatted_named_placeholders
|
92
|
-
assert_equal("foo 1.000000", "%{name} %<num>f" % {:name => "foo", :num => 1.0})
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_string_interpolation_raises_an_argument_error_when_mixing_named_and_unnamed_placeholders
|
96
|
-
assert_raise(ArgumentError) { "%{name} %f" % [1.0] }
|
97
|
-
assert_raise(ArgumentError) { "%{name} %f" % [1.0, 2.0] }
|
98
|
-
end
|
99
|
-
end
|
data/test/gettext/api_test.rb
DELETED
@@ -1,207 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
|
3
|
-
require 'test_helper'
|
4
|
-
require 'i18n/helpers/gettext'
|
5
|
-
|
6
|
-
include I18n::Helpers::Gettext
|
7
|
-
|
8
|
-
class I18nGettextApiTest < Test::Unit::TestCase
|
9
|
-
def setup
|
10
|
-
I18n.locale = :en
|
11
|
-
I18n.backend.store_translations :de, {
|
12
|
-
'Hi Gettext!' => 'Hallo Gettext!',
|
13
|
-
'Sentence 1. Sentence 2.' => 'Satz 1. Satz 2.',
|
14
|
-
"An apple" => { :one => 'Ein Apfel', :other => '{{count}} Äpfel' },
|
15
|
-
:special => { "A special apple" => { :one => 'Ein spezieller Apfel', :other => '{{count}} spezielle Äpfel' } },
|
16
|
-
:foo => { :bar => 'bar-de' },
|
17
|
-
'foo.bar' => 'Foo Bar'
|
18
|
-
}, :separator => '|'
|
19
|
-
end
|
20
|
-
|
21
|
-
# gettext
|
22
|
-
def test_gettext_uses_msg_as_default
|
23
|
-
assert_equal 'Hi Gettext!', _('Hi Gettext!')
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_gettext_uses_msg_as_key
|
27
|
-
I18n.locale = :de
|
28
|
-
assert_equal 'Hallo Gettext!', gettext('Hi Gettext!')
|
29
|
-
assert_equal 'Hallo Gettext!', _('Hi Gettext!')
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_gettext_uses_msg_containing_dots_as_default
|
33
|
-
assert_equal 'Sentence 1. Sentence 2.', gettext('Sentence 1. Sentence 2.')
|
34
|
-
assert_equal 'Sentence 1. Sentence 2.', _('Sentence 1. Sentence 2.')
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_gettext_uses_msg_containing_dots_as_key
|
38
|
-
I18n.locale = :de
|
39
|
-
assert_equal 'Satz 1. Satz 2.', gettext('Sentence 1. Sentence 2.')
|
40
|
-
assert_equal 'Satz 1. Satz 2.', _('Sentence 1. Sentence 2.')
|
41
|
-
end
|
42
|
-
|
43
|
-
# sgettext
|
44
|
-
def test_sgettext_defaults_to_the_last_token_of_a_scoped_msgid
|
45
|
-
assert_equal 'bar', sgettext('foo|bar')
|
46
|
-
assert_equal 'bar', s_('foo|bar')
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_sgettext_looks_up_a_scoped_translation
|
50
|
-
I18n.locale = :de
|
51
|
-
assert_equal 'bar-de', sgettext('foo|bar')
|
52
|
-
assert_equal 'bar-de', s_('foo|bar')
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_sgettext_ignores_dots
|
56
|
-
I18n.locale = :de
|
57
|
-
assert_equal 'Foo Bar', sgettext('foo.bar')
|
58
|
-
assert_equal 'Foo Bar', s_('foo.bar')
|
59
|
-
end
|
60
|
-
|
61
|
-
# pgettext
|
62
|
-
def test_pgettext_defaults_to_msgid
|
63
|
-
assert_equal 'bar', pgettext('foo', 'bar')
|
64
|
-
assert_equal 'bar', p_('foo', 'bar')
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_pgettext_looks_up_a_scoped_translation
|
68
|
-
I18n.locale = :de
|
69
|
-
assert_equal 'bar-de', pgettext('foo', 'bar')
|
70
|
-
assert_equal 'bar-de', p_('foo', 'bar')
|
71
|
-
end
|
72
|
-
|
73
|
-
# ngettext
|
74
|
-
def test_ngettext_looks_up_msg_id_as_default_singular
|
75
|
-
assert_equal 'An apple', ngettext('An apple', '{{count}} apples', 1)
|
76
|
-
assert_equal 'An apple', n_('An apple', '{{count}} apples', 1)
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_ngettext_looks_up_msg_id_plural_as_default_plural
|
80
|
-
assert_equal '2 apples', ngettext('An apple', '{{count}} apples', 2)
|
81
|
-
assert_equal '2 apples', n_('An apple', '{{count}} apples', 2)
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_ngettext_looks_up_a_singular
|
85
|
-
I18n.locale = :de
|
86
|
-
assert_equal 'Ein Apfel', ngettext('An apple', '{{count}} apples', 1)
|
87
|
-
assert_equal 'Ein Apfel', n_('An apple', '{{count}} apples', 1)
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_ngettext_looks_up_a_plural
|
91
|
-
I18n.locale = :de
|
92
|
-
assert_equal '2 Äpfel', ngettext('An apple', '{{count}} apples', 2)
|
93
|
-
assert_equal '2 Äpfel', n_('An apple', '{{count}} apples', 2)
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_ngettext_looks_up_msg_id_as_default_singular_with_alternative_syntax
|
97
|
-
assert_equal 'An apple', ngettext(['An apple', '{{count}} apples'], 1)
|
98
|
-
assert_equal 'An apple', n_(['An apple', '{{count}} apples'], 1)
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_ngettext_looks_up_msg_id_plural_as_default_plural_with_alternative_syntax
|
102
|
-
assert_equal '2 apples', ngettext(['An apple', '{{count}} apples'], 2)
|
103
|
-
assert_equal '2 apples', n_(['An apple', '{{count}} apples'], 2)
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_ngettext_looks_up_a_singular_with_alternative_syntax
|
107
|
-
I18n.locale = :de
|
108
|
-
assert_equal 'Ein Apfel', ngettext(['An apple', '{{count}} apples'], 1)
|
109
|
-
assert_equal 'Ein Apfel', n_(['An apple', '{{count}} apples'], 1)
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_ngettext_looks_up_a_plural_with_alternative_syntax
|
113
|
-
I18n.locale = :de
|
114
|
-
assert_equal '2 Äpfel', ngettext(['An apple', '{{count}} apples'], 2)
|
115
|
-
assert_equal '2 Äpfel', n_(['An apple', '{{count}} apples'], 2)
|
116
|
-
end
|
117
|
-
|
118
|
-
# nsgettext
|
119
|
-
def test_nsgettext_looks_up_msg_id_as_default_singular
|
120
|
-
assert_equal 'A special apple', nsgettext('special|A special apple', '{{count}} special apples', 1)
|
121
|
-
assert_equal 'A special apple', ns_('special|A special apple', '{{count}} special apples', 1)
|
122
|
-
end
|
123
|
-
|
124
|
-
def test_nsgettext_looks_up_msg_id_plural_as_default_plural
|
125
|
-
assert_equal '2 special apples', nsgettext('special|A special apple', '{{count}} special apples', 2)
|
126
|
-
assert_equal '2 special apples', ns_('special|A special apple', '{{count}} special apples', 2)
|
127
|
-
end
|
128
|
-
|
129
|
-
def test_nsgettext_looks_up_a_singular
|
130
|
-
I18n.locale = :de
|
131
|
-
assert_equal 'Ein spezieller Apfel', nsgettext('special|A special apple', '{{count}} special apples', 1)
|
132
|
-
assert_equal 'Ein spezieller Apfel', ns_('special|A special apple', '{{count}} special apples', 1)
|
133
|
-
end
|
134
|
-
|
135
|
-
def test_nsgettext_looks_up_a_plural
|
136
|
-
I18n.locale = :de
|
137
|
-
assert_equal '2 spezielle Äpfel', nsgettext('special|A special apple', '{{count}} special apples', 2)
|
138
|
-
assert_equal '2 spezielle Äpfel', ns_('special|A special apple', '{{count}} special apples', 2)
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_nsgettext_looks_up_msg_id_as_default_singular_with_alternative_syntax
|
142
|
-
assert_equal 'A special apple', nsgettext(['special|A special apple', '{{count}} special apples'], 1)
|
143
|
-
assert_equal 'A special apple', ns_(['special|A special apple', '{{count}} special apples'], 1)
|
144
|
-
end
|
145
|
-
|
146
|
-
def test_nsgettext_looks_up_msg_id_plural_as_default_plural_with_alternative_syntax
|
147
|
-
assert_equal '2 special apples', nsgettext(['special|A special apple', '{{count}} special apples'], 2)
|
148
|
-
assert_equal '2 special apples', ns_(['special|A special apple', '{{count}} special apples'], 2)
|
149
|
-
end
|
150
|
-
|
151
|
-
def test_nsgettext_looks_up_a_singular_with_alternative_syntax
|
152
|
-
I18n.locale = :de
|
153
|
-
assert_equal 'Ein spezieller Apfel', nsgettext(['special|A special apple', '{{count}} special apples'], 1)
|
154
|
-
assert_equal 'Ein spezieller Apfel', ns_(['special|A special apple', '{{count}} special apples'], 1)
|
155
|
-
end
|
156
|
-
|
157
|
-
def test_nsgettext_looks_up_a_plural_with_alternative_syntax
|
158
|
-
I18n.locale = :de
|
159
|
-
assert_equal '2 spezielle Äpfel', nsgettext(['special|A special apple', '{{count}} special apples'], 2)
|
160
|
-
assert_equal '2 spezielle Äpfel', ns_(['special|A special apple', '{{count}} special apples'], 2)
|
161
|
-
end
|
162
|
-
|
163
|
-
# npgettext
|
164
|
-
def test_npgettext_looks_up_msg_id_as_default_singular
|
165
|
-
assert_equal 'A special apple', npgettext('special', 'A special apple', '{{count}} special apples', 1)
|
166
|
-
assert_equal 'A special apple', np_('special', 'A special apple', '{{count}} special apples', 1)
|
167
|
-
end
|
168
|
-
|
169
|
-
def test_npgettext_looks_up_msg_id_plural_as_default_plural
|
170
|
-
assert_equal '2 special apples', npgettext('special', 'A special apple', '{{count}} special apples', 2)
|
171
|
-
assert_equal '2 special apples', np_('special', 'A special apple', '{{count}} special apples', 2)
|
172
|
-
end
|
173
|
-
|
174
|
-
def test_npgettext_looks_up_a_singular
|
175
|
-
I18n.locale = :de
|
176
|
-
assert_equal 'Ein spezieller Apfel', npgettext('special', 'A special apple', '{{count}} special apples', 1)
|
177
|
-
assert_equal 'Ein spezieller Apfel', np_('special', 'A special apple', '{{count}} special apples', 1)
|
178
|
-
end
|
179
|
-
|
180
|
-
def test_npgettext_looks_up_a_plural
|
181
|
-
I18n.locale = :de
|
182
|
-
assert_equal '2 spezielle Äpfel', npgettext('special', 'A special apple', '{{count}} special apples', 2)
|
183
|
-
assert_equal '2 spezielle Äpfel', np_('special', 'A special apple', '{{count}} special apples', 2)
|
184
|
-
end
|
185
|
-
|
186
|
-
def test_npgettext_looks_up_msg_id_as_default_singular_with_alternative_syntax
|
187
|
-
assert_equal 'A special apple', npgettext('special', ['A special apple', '{{count}} special apples'], 1)
|
188
|
-
assert_equal 'A special apple', np_('special', ['A special apple', '{{count}} special apples'], 1)
|
189
|
-
end
|
190
|
-
|
191
|
-
def test_npgettext_looks_up_msg_id_plural_as_default_plural_with_alternative_syntax
|
192
|
-
assert_equal '2 special apples', npgettext('special', ['A special apple', '{{count}} special apples'], 2)
|
193
|
-
assert_equal '2 special apples', np_('special', ['A special apple', '{{count}} special apples'], 2)
|
194
|
-
end
|
195
|
-
|
196
|
-
def test_npgettext_looks_up_a_singular_with_alternative_syntax
|
197
|
-
I18n.locale = :de
|
198
|
-
assert_equal 'Ein spezieller Apfel', npgettext('special', ['A special apple', '{{count}} special apples'], 1)
|
199
|
-
assert_equal 'Ein spezieller Apfel', np_('special', ['A special apple', '{{count}} special apples'], 1)
|
200
|
-
end
|
201
|
-
|
202
|
-
def test_npgettext_looks_up_a_plural_with_alternative_syntax
|
203
|
-
I18n.locale = :de
|
204
|
-
assert_equal '2 spezielle Äpfel', npgettext('special', ['A special apple', '{{count}} special apples'], 2)
|
205
|
-
assert_equal '2 spezielle Äpfel', np_('special', ['A special apple', '{{count}} special apples'], 2)
|
206
|
-
end
|
207
|
-
end
|
@@ -1,91 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class I18nGettextBackendTest < Test::Unit::TestCase
|
6
|
-
include I18n::Helpers::Gettext
|
7
|
-
|
8
|
-
class Backend
|
9
|
-
include I18n::Backend::Base
|
10
|
-
include I18n::Backend::Gettext
|
11
|
-
end
|
12
|
-
|
13
|
-
def setup
|
14
|
-
I18n.backend = Backend.new
|
15
|
-
I18n.locale = :en
|
16
|
-
I18n.load_path = ["#{locales_dir}/de.po"]
|
17
|
-
@old_separator, I18n.default_separator = I18n.default_separator, '|'
|
18
|
-
end
|
19
|
-
|
20
|
-
def teardown
|
21
|
-
I18n.load_path = nil
|
22
|
-
I18n.backend = nil
|
23
|
-
I18n.default_separator = @old_separator
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_backend_loads_po_file
|
27
|
-
I18n.backend.send(:init_translations)
|
28
|
-
assert I18n.backend.send(:translations)[:de][:"Axis"]
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_looks_up_a_translation
|
32
|
-
I18n.locale = :de
|
33
|
-
assert_equal 'Auto', gettext('car')
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_uses_default_translation
|
37
|
-
assert_equal 'car', gettext('car')
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_looks_up_a_namespaced_translation
|
41
|
-
I18n.locale = :de
|
42
|
-
assert_equal 'Räderzahl', sgettext('Car|Wheels count')
|
43
|
-
assert_equal 'Räderzahl', pgettext('Car', 'Wheels count')
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_uses_namespaced_default_translation
|
47
|
-
assert_equal 'Wheels count', sgettext('Car|Wheels count')
|
48
|
-
assert_equal 'Wheels count', pgettext('Car', 'Wheels count')
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_pluralizes_entry
|
52
|
-
I18n.locale = :de
|
53
|
-
assert_equal 'Achse', ngettext('Axis', 'Axis', 1)
|
54
|
-
assert_equal 'Achsen', ngettext('Axis', 'Axis', 2)
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_pluralizes_default_entry
|
58
|
-
assert_equal 'Axis', ngettext('Axis', 'Axis', 1)
|
59
|
-
assert_equal 'Axis', ngettext('Axis', 'Axis', 2)
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_pluralizes_namespaced_entry
|
63
|
-
I18n.locale = :de
|
64
|
-
assert_equal 'Rad', nsgettext('Car|wheel', 'wheels', 1)
|
65
|
-
assert_equal 'Räder', nsgettext('Car|wheel', 'wheels', 2)
|
66
|
-
assert_equal 'Rad', npgettext('Car', 'wheel', 'wheels', 1)
|
67
|
-
assert_equal 'Räder', npgettext('Car', 'wheel', 'wheels', 2)
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_pluralizes_namespaced_default_entry
|
71
|
-
assert_equal 'wheel', nsgettext('Car|wheel', 'wheels', 1)
|
72
|
-
assert_equal 'wheels', nsgettext('Car|wheel', 'wheels', 2)
|
73
|
-
assert_equal 'wheel', npgettext('Car', 'wheel', 'wheels', 1)
|
74
|
-
assert_equal 'wheels', npgettext('Car', 'wheel', 'wheels', 2)
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_pluralizes_namespaced_entry_with_alternative_syntax
|
78
|
-
I18n.locale = :de
|
79
|
-
assert_equal 'Rad', nsgettext(['Car|wheel', 'wheels'], 1)
|
80
|
-
assert_equal 'Räder', nsgettext(['Car|wheel', 'wheels'], 2)
|
81
|
-
assert_equal 'Rad', npgettext('Car', ['wheel', 'wheels'], 1)
|
82
|
-
assert_equal 'Räder', npgettext('Car', ['wheel', 'wheels'], 2)
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_ngettextpluralizes_entry_with_dots
|
86
|
-
I18n.locale = :de
|
87
|
-
assert_equal 'Auf 1 Achse.', n_("On %{count} wheel.", "On %{count} wheels.", 1)
|
88
|
-
assert_equal 'Auf 2 Achsen.', n_("On %{count} wheel.", "On %{count} wheels.", 2)
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
@@ -1,97 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$:.unshift File.expand_path(File.dirname(__FILE__) + '/')
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class I18nExceptionsTest < Test::Unit::TestCase
|
6
|
-
def test_invalid_locale_stores_locale
|
7
|
-
force_invalid_locale
|
8
|
-
rescue I18n::ArgumentError => e
|
9
|
-
assert_nil e.locale
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_invalid_locale_message
|
13
|
-
force_invalid_locale
|
14
|
-
rescue I18n::ArgumentError => e
|
15
|
-
assert_equal 'nil is not a valid locale', e.message
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_missing_translation_data_stores_locale_key_and_options
|
19
|
-
force_missing_translation_data
|
20
|
-
rescue I18n::ArgumentError => e
|
21
|
-
options = {:scope => :bar}
|
22
|
-
assert_equal 'de', e.locale
|
23
|
-
assert_equal :foo, e.key
|
24
|
-
assert_equal options, e.options
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_missing_translation_data_message
|
28
|
-
force_missing_translation_data
|
29
|
-
rescue I18n::ArgumentError => e
|
30
|
-
assert_equal 'translation missing: de, bar, foo', e.message
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_invalid_pluralization_data_stores_entry_and_count
|
34
|
-
force_invalid_pluralization_data
|
35
|
-
rescue I18n::ArgumentError => e
|
36
|
-
assert_equal [:bar], e.entry
|
37
|
-
assert_equal 1, e.count
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_invalid_pluralization_data_message
|
41
|
-
force_invalid_pluralization_data
|
42
|
-
rescue I18n::ArgumentError => e
|
43
|
-
assert_equal 'translation data [:bar] can not be used with :count => 1', e.message
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_missing_interpolation_argument_stores_key_and_string
|
47
|
-
assert_raise(I18n::MissingInterpolationArgument) { force_missing_interpolation_argument }
|
48
|
-
force_missing_interpolation_argument
|
49
|
-
rescue I18n::ArgumentError => e
|
50
|
-
# assert_equal :bar, e.key
|
51
|
-
assert_equal "{{bar}}", e.string
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_missing_interpolation_argument_message
|
55
|
-
force_missing_interpolation_argument
|
56
|
-
rescue I18n::ArgumentError => e
|
57
|
-
assert_equal 'missing interpolation argument in "{{bar}}" ({:baz=>"baz"} given)', e.message
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_reserved_interpolation_key_stores_key_and_string
|
61
|
-
force_reserved_interpolation_key
|
62
|
-
rescue I18n::ArgumentError => e
|
63
|
-
assert_equal :scope, e.key
|
64
|
-
assert_equal "{{scope}}", e.string
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_reserved_interpolation_key_message
|
68
|
-
force_reserved_interpolation_key
|
69
|
-
rescue I18n::ArgumentError => e
|
70
|
-
assert_equal 'reserved key :scope used in "{{scope}}"', e.message
|
71
|
-
end
|
72
|
-
|
73
|
-
private
|
74
|
-
def force_invalid_locale
|
75
|
-
I18n.backend.translate nil, :foo
|
76
|
-
end
|
77
|
-
|
78
|
-
def force_missing_translation_data
|
79
|
-
I18n.backend.store_translations 'de', :bar => nil
|
80
|
-
I18n.backend.translate 'de', :foo, :scope => :bar
|
81
|
-
end
|
82
|
-
|
83
|
-
def force_invalid_pluralization_data
|
84
|
-
I18n.backend.store_translations 'de', :foo => [:bar]
|
85
|
-
I18n.backend.translate 'de', :foo, :count => 1
|
86
|
-
end
|
87
|
-
|
88
|
-
def force_missing_interpolation_argument
|
89
|
-
I18n.backend.store_translations 'de', :foo => "{{bar}}"
|
90
|
-
I18n.backend.translate 'de', :foo, :baz => 'baz'
|
91
|
-
end
|
92
|
-
|
93
|
-
def force_reserved_interpolation_key
|
94
|
-
I18n.backend.store_translations 'de', :foo => "{{scope}}"
|
95
|
-
I18n.backend.translate 'de', :foo, :baz => 'baz'
|
96
|
-
end
|
97
|
-
end
|