i18n-inflector 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +1 -0
- data/ChangeLog +412 -0
- data/Gemfile +1 -0
- data/Manifest.txt +6 -1
- data/README.rdoc +16 -11
- data/Rakefile +15 -2
- data/ci/i18n-inflector.gemspec +1 -1
- data/ci/i18nv4-Gemfile +15 -0
- data/docs/EXAMPLES +222 -0
- data/docs/HISTORY +31 -0
- data/docs/LEGAL +0 -1
- data/docs/RELATIONS +16 -13
- data/docs/TODO +25 -3
- data/lib/i18n-inflector/api.rb +964 -0
- data/lib/i18n-inflector/api_strict.rb +519 -0
- data/lib/i18n-inflector/backend.rb +77 -40
- data/lib/i18n-inflector/errors.rb +56 -14
- data/lib/i18n-inflector/inflection_data.rb +133 -105
- data/lib/i18n-inflector/inflection_data_strict.rb +290 -0
- data/lib/i18n-inflector/inflector.rb +21 -660
- data/lib/i18n-inflector/lazy_enum.rb +120 -0
- data/lib/i18n-inflector/long_comments.rb +203 -14
- data/lib/i18n-inflector/version.rb +1 -1
- data/lib/i18n-inflector.rb +5 -3
- data/test/inflector_test.rb +334 -34
- data/test/test_helper.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +10 -6
- metadata.gz.sig +0 -0
- data/lib/i18n-inflector/util.rb +0 -67
data/test/inflector_test.rb
CHANGED
@@ -21,10 +21,22 @@ class I18nInflectorTest < Test::Unit::TestCase
|
|
21
21
|
:default => 'neutral' },
|
22
22
|
:person => {
|
23
23
|
:i => 'I',
|
24
|
-
:you => 'You'}
|
24
|
+
:you => 'You'},
|
25
|
+
:@gender => {
|
26
|
+
:m => 'male',
|
27
|
+
:f => 'female',
|
28
|
+
:n => 'neuter',
|
29
|
+
:s => 'strange',
|
30
|
+
:masculine => '@m',
|
31
|
+
:feminine => '@f',
|
32
|
+
:neuter => '@n',
|
33
|
+
:neutral => '@neuter',
|
34
|
+
:default => 'neutral' }
|
25
35
|
} })
|
26
36
|
|
27
|
-
store_translations(:xx, 'welcome'
|
37
|
+
store_translations(:xx, 'welcome' => 'Dear @{f:Lady|m:Sir|n:You|All}!')
|
38
|
+
store_translations(:xx, 'named_welcome' => 'Dear @gender{f:Lady|m:Sir|n:You|All}!')
|
39
|
+
I18n.locale = :en
|
28
40
|
end
|
29
41
|
|
30
42
|
test "backend inflector has methods to test its switches" do
|
@@ -53,6 +65,13 @@ class I18nInflectorTest < Test::Unit::TestCase
|
|
53
65
|
end
|
54
66
|
end
|
55
67
|
|
68
|
+
test "backend inflector strict store_translations: allows duplicated tokens across differend kinds" do
|
69
|
+
assert_nothing_raised I18n::DuplicatedInflectionToken do
|
70
|
+
store_translations(:xx, :i18n => { :inflections => { :@gender => { :o => 'other' }, :@person => { :o => 'o' }}})
|
71
|
+
store_translations(:xx, :i18n => { :inflections => { :gender => { :o => 'other' }, :@gender => { :o => 'o' }}})
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
56
75
|
test "backend inflector store_translations: raises I18n::BadInflectionAlias when bad alias is given" do
|
57
76
|
assert_raise I18n::BadInflectionAlias do
|
58
77
|
store_translations(:xx, :i18n => { :inflections => { :gender => { :o => '@nonexistant' }}})
|
@@ -60,18 +79,28 @@ class I18nInflectorTest < Test::Unit::TestCase
|
|
60
79
|
assert_raise I18n::BadInflectionAlias do
|
61
80
|
store_translations(:xx, :i18n => { :inflections => { :gender => { :default => '@nonexistant' }}})
|
62
81
|
end
|
63
|
-
|
82
|
+
assert_raise I18n::BadInflectionAlias do
|
83
|
+
store_translations(:xx, :i18n => { :inflections => { :@gender => { :oh => '@nonex' }}})
|
84
|
+
end
|
85
|
+
assert_raise I18n::BadInflectionAlias do
|
86
|
+
store_translations(:xx, :i18n => { :inflections => { :@gender => { :default => '@nonex' }}})
|
87
|
+
end
|
88
|
+
end
|
64
89
|
|
65
|
-
|
90
|
+
test "backend inflector store_translations: raises I18n::BadInflectionToken when bad token is given" do
|
66
91
|
assert_raise I18n::BadInflectionToken do
|
67
92
|
store_translations(:xx, :i18n => { :inflections => { :gender => { :o => '@' }}})
|
68
93
|
store_translations(:xx, :i18n => { :inflections => { :gender => { :tok => nil }}})
|
94
|
+
store_translations(:xx, :i18n => { :inflections => { :@gender => { :o => '@' }}})
|
95
|
+
store_translations(:xx, :i18n => { :inflections => { :@gender => { :tok => nil }}})
|
69
96
|
end
|
70
|
-
|
97
|
+
end
|
71
98
|
|
72
99
|
test "backend inflector translate: allows pattern-only translation data" do
|
73
100
|
store_translations(:xx, 'clear_welcome' => '@{f:Lady|m:Sir|n:You|All}')
|
74
101
|
assert_equal 'Lady', I18n.t('clear_welcome', :gender => 'f', :locale => :xx)
|
102
|
+
store_translations(:xx, 'clear_welcome' => '@gender{f:Lady|m:Sir|n:You|All}')
|
103
|
+
assert_equal 'Lady', I18n.t('clear_welcome', :gender => 'f', :locale => :xx)
|
75
104
|
end
|
76
105
|
|
77
106
|
test "backend inflector translate: allows patterns to be escaped using @@ or \\@" do
|
@@ -166,10 +195,10 @@ class I18nInflectorTest < Test::Unit::TestCase
|
|
166
195
|
tr = I18n.backend.send(:translations)
|
167
196
|
tr[:xx][:i18n][:inflections][:gender].delete(:default)
|
168
197
|
store_translations(:xx, :i18n => { :inflections => { :gender => { :o => 'other' }}})
|
169
|
-
assert_raise(I18n::
|
170
|
-
assert_raise(I18n::
|
171
|
-
assert_raise(I18n::
|
172
|
-
assert_raise I18n::
|
198
|
+
assert_raise(I18n::InflectionOptionNotFound) { I18n.t('welcome', :locale => :xx, :inflector_raises => true) }
|
199
|
+
assert_raise(I18n::InflectionOptionIncorrect) { I18n.t('welcome', :locale => :xx, :gender => "", :inflector_raises => true) }
|
200
|
+
assert_raise(I18n::InflectionOptionIncorrect) { I18n.t('welcome', :locale => :xx, :gender => nil, :inflector_raises => true) }
|
201
|
+
assert_raise I18n::InflectionOptionNotFound do
|
173
202
|
I18n.inflector.options.raises = true
|
174
203
|
I18n.t('welcome', :locale => :xx)
|
175
204
|
end
|
@@ -196,6 +225,15 @@ class I18nInflectorTest < Test::Unit::TestCase
|
|
196
225
|
test "backend inflector translate: works with %{} patterns" do
|
197
226
|
store_translations(:xx, 'hi' => 'Dear @{f:Lady|m:%{test}}!')
|
198
227
|
assert_equal 'Dear Dude!', I18n.t('hi', :gender => :m, :locale => :xx, :test => "Dude")
|
228
|
+
store_translations(:xx, 'to be' => '%{person} @{i:am|you:are}')
|
229
|
+
assert_equal 'you are', I18n.t('to be', :person => :you, :locale => :xx)
|
230
|
+
end
|
231
|
+
|
232
|
+
test "backend inflector translate: works with doubled patterns" do
|
233
|
+
store_translations(:xx, 'dd' => 'Dear @{f:Lady|m:Sir|All}! Dear @{f:Lady|m:Sir|All}!')
|
234
|
+
assert_equal 'Dear Lady! Dear Lady!', I18n.t('dd', :gender => :f, :locale => :xx)
|
235
|
+
store_translations(:xx, 'hi' => 'Dear @{f:Lady|m:%{test}}! Dear @{f:Lady|m:%{test}}!')
|
236
|
+
assert_equal 'Dear Dude! Dear Dude!', I18n.t('hi', :gender => :m, :locale => :xx, :test => "Dude")
|
199
237
|
end
|
200
238
|
|
201
239
|
test "backend inflector translate: works with tokens separated by commas" do
|
@@ -205,10 +243,10 @@ class I18nInflectorTest < Test::Unit::TestCase
|
|
205
243
|
|
206
244
|
test "backend inflector translate: works with negative tokens" do
|
207
245
|
store_translations(:xx, 'hi' => 'Dear @{!m:Lady|m:Sir|n:You|All}!')
|
208
|
-
assert_equal 'Dear Lady!',
|
209
|
-
assert_equal 'Dear Sir!',
|
210
|
-
assert_equal 'Dear Lady!',
|
211
|
-
assert_equal 'Dear Lady!',
|
246
|
+
assert_equal 'Dear Lady!', I18n.t('hi', :gender => :n, :locale => :xx)
|
247
|
+
assert_equal 'Dear Sir!', I18n.t('hi', :gender => :m, :locale => :xx)
|
248
|
+
assert_equal 'Dear Lady!', I18n.t('hi', :locale => :xx)
|
249
|
+
assert_equal 'Dear Lady!', I18n.t('hi', :gender => :unknown, :locale => :xx)
|
212
250
|
store_translations(:xx, 'hi' => 'Hello @{!m:Ladies|n:You}')
|
213
251
|
assert_equal 'Hello Ladies', I18n.t('hi', :gender => :n, :locale => :xx)
|
214
252
|
assert_equal 'Hello Ladies', I18n.t('hi', :gender => :f, :locale => :xx)
|
@@ -242,11 +280,81 @@ class I18nInflectorTest < Test::Unit::TestCase
|
|
242
280
|
assert_equal 'Dear Sir!', I18n.t('hi', :gender => :masculine, :locale => :xx)
|
243
281
|
end
|
244
282
|
|
283
|
+
test "backend inflector translate: recognizes named patterns and strict kinds" do
|
284
|
+
store_translations(:xx, :i18n => { :inflections => { :@gender => { :s => 'sir', :o => 'other', :s => 'a', :n => 'n', :default => 'n' }}})
|
285
|
+
store_translations(:xx, 'hi' => 'Dear @gender{s:Sir|o:Other|n:You|All}!')
|
286
|
+
assert_equal 'Dear Sir!', I18n.t('hi', :gender => :s, :locale => :xx)
|
287
|
+
assert_equal 'Dear Other!', I18n.t('hi', :gender => :o, :locale => :xx)
|
288
|
+
assert_equal 'Dear You!', I18n.t('hi', :locale => :xx)
|
289
|
+
assert_equal 'Dear You!', I18n.t('hi', :gender => "", :locale => :xx)
|
290
|
+
assert_equal 'Dear You!', I18n.t('hi', :gender => :unknown, :locale => :xx)
|
291
|
+
assert_equal 'Dear You!', I18n.t('hi', :@gender => :unknown, :locale => :xx)
|
292
|
+
end
|
293
|
+
|
294
|
+
test "backend inflector translate: prioritizes @-style kinds in options for named patterns" do
|
295
|
+
store_translations(:xx, :i18n => { :inflections => { :@gender => { :s => 'sir', :o => 'other', :s => 'a', :n => 'n', :default => 'n' }}})
|
296
|
+
store_translations(:xx, 'hi' => 'Dear @gender{s:Sir|o:Other|n:You|All}!')
|
297
|
+
assert_equal 'Dear Sir!', I18n.t('hi', :gender => :s, :locale => :xx)
|
298
|
+
assert_equal 'Dear You!', I18n.t('hi', :gender => :s, :@gender => :unknown, :locale => :xx)
|
299
|
+
assert_equal 'Dear You!', I18n.t('hi', :gender => :s, :@gender => nil, :locale => :xx)
|
300
|
+
assert_equal 'Dear Sir!', I18n.t('hi', :gender => :s, :@gender => :s, :locale => :xx)
|
301
|
+
|
302
|
+
end
|
303
|
+
|
245
304
|
test "inflector inflected_locales: lists languages that support inflection" do
|
246
305
|
assert_equal [:xx], I18n.inflector.inflected_locales
|
247
306
|
assert_equal [:xx], I18n.inflector.inflected_locales(:gender)
|
248
307
|
end
|
249
308
|
|
309
|
+
test "inflector.strict inflected_locales: lists languages that support inflection" do
|
310
|
+
assert_equal [:xx], I18n.inflector.strict.inflected_locales
|
311
|
+
assert_equal [:xx], I18n.inflector.strict.inflected_locales(:gender)
|
312
|
+
store_translations(:yy, :i18n => { :inflections => { :@person => { :s => 'sir'}}})
|
313
|
+
assert_equal [:xx], I18n.inflector.strict.inflected_locales(:gender)
|
314
|
+
assert_equal [:yy], I18n.inflector.strict.inflected_locales(:person)
|
315
|
+
assert_equal [:xx], I18n.inflector.inflected_locales(:gender)
|
316
|
+
assert_equal [:yy], I18n.inflector.inflected_locales(:@person)
|
317
|
+
assert_equal [:xx,:yy], I18n.inflector.inflected_locales.sort{|k,v| k.to_s<=>v.to_s}
|
318
|
+
assert_equal [:xx,:yy], I18n.inflector.strict.inflected_locales.sort{|k,v| k.to_s<=>v.to_s}
|
319
|
+
store_translations(:zz, :i18n => { :inflections => { :some => { :s => 'sir'}}})
|
320
|
+
assert_equal [:xx,:yy,:zz], I18n.inflector.inflected_locales.sort{|k,v| k.to_s<=>v.to_s}
|
321
|
+
assert_equal [:xx,:yy], I18n.inflector.strict.inflected_locales.sort{|k,v| k.to_s<=>v.to_s}
|
322
|
+
assert_equal [], I18n.inflector.inflected_locales(:@some)
|
323
|
+
assert_equal [:zz], I18n.inflector.inflected_locales(:some)
|
324
|
+
end
|
325
|
+
|
326
|
+
test "inflector inflected_locale?: tests if the given locale supports inflection" do
|
327
|
+
assert_equal true, I18n.inflector.inflected_locale?(:xx)
|
328
|
+
I18n.locale = :xx
|
329
|
+
assert_equal true, I18n.inflector.inflected_locale?
|
330
|
+
end
|
331
|
+
|
332
|
+
test "inflector.strict inflected_locale?: tests if the given locale supports inflection" do
|
333
|
+
assert_equal true, I18n.inflector.strict.inflected_locale?(:xx)
|
334
|
+
I18n.locale = :xx
|
335
|
+
assert_equal true, I18n.inflector.strict.inflected_locale?
|
336
|
+
end
|
337
|
+
|
338
|
+
test "inflector new_database creates a database with inflections" do
|
339
|
+
assert_kind_of I18n::Inflector::InflectionData, I18n.inflector.new_database(:yy)
|
340
|
+
assert_equal true, I18n.inflector.inflected_locale?(:yy)
|
341
|
+
assert_equal false, I18n.inflector.inflected_locale?(:yyyyy)
|
342
|
+
end
|
343
|
+
|
344
|
+
test "inflector add_database adds existing database with inflections" do
|
345
|
+
db = I18n::Inflector::InflectionData.new(:zz)
|
346
|
+
assert_kind_of I18n::Inflector::InflectionData, I18n.inflector.add_database(db)
|
347
|
+
assert_equal true, I18n.inflector.inflected_locale?(:zz)
|
348
|
+
assert_equal false, I18n.inflector.inflected_locale?(:zzzzzz)
|
349
|
+
end
|
350
|
+
|
351
|
+
test "inflector delete_database deletes existing inflections database" do
|
352
|
+
I18n.inflector.new_database(:vv)
|
353
|
+
assert_equal true, I18n.inflector.inflected_locale?(:vv)
|
354
|
+
assert_kind_of NilClass, I18n.inflector.delete_database(:vv)
|
355
|
+
assert_equal false, I18n.inflector.inflected_locale?(:vv)
|
356
|
+
end
|
357
|
+
|
250
358
|
test "inflector locale_supported?: checks if a language supports inflection" do
|
251
359
|
assert_equal true, I18n.inflector.locale_supported?(:xx)
|
252
360
|
assert_equal false, I18n.inflector.locale_supported?(:pl)
|
@@ -262,29 +370,97 @@ class I18nInflectorTest < Test::Unit::TestCase
|
|
262
370
|
assert_equal false, I18n.inflector.locale_supported?
|
263
371
|
end
|
264
372
|
|
373
|
+
test "inflector.strict locale_supported?: checks if a language supports inflection" do
|
374
|
+
assert_equal true, I18n.inflector.strict.locale_supported?(:xx)
|
375
|
+
assert_equal false, I18n.inflector.strict.locale_supported?(:pl)
|
376
|
+
assert_equal false, I18n.inflector.strict.locale_supported?(nil)
|
377
|
+
assert_equal false, I18n.inflector.strict.locale_supported?("")
|
378
|
+
I18n.locale = :xx
|
379
|
+
assert_equal true, I18n.inflector.strict.locale_supported?
|
380
|
+
I18n.locale = :pl
|
381
|
+
assert_equal false, I18n.inflector.strict.locale_supported?
|
382
|
+
I18n.locale = nil
|
383
|
+
assert_equal false, I18n.inflector.strict.locale_supported?
|
384
|
+
I18n.locale = ""
|
385
|
+
assert_equal false, I18n.inflector.strict.locale_supported?
|
386
|
+
end
|
387
|
+
|
265
388
|
test "inflector has_token?: checks if a token exists" do
|
266
389
|
assert_equal true, I18n.inflector.has_token?(:neuter, :gender, :xx)
|
267
390
|
assert_equal true, I18n.inflector.has_token?(:neuter, :xx)
|
268
|
-
assert_equal true, I18n.inflector.has_token?(:f,
|
269
|
-
assert_equal true, I18n.inflector.has_token?(:you,
|
391
|
+
assert_equal true, I18n.inflector.has_token?(:f, :xx)
|
392
|
+
assert_equal true, I18n.inflector.has_token?(:you, :xx)
|
270
393
|
I18n.locale = :xx
|
271
394
|
assert_equal true, I18n.inflector.has_token?(:f)
|
272
395
|
assert_equal true, I18n.inflector.has_token?(:you)
|
273
396
|
assert_equal false,I18n.inflector.has_token?(:faafaffafafa)
|
274
397
|
end
|
275
398
|
|
399
|
+
test "inflector.strict has_token?: checks if a token exists" do
|
400
|
+
assert_equal true, I18n.inflector.strict.has_token?(:neuter, :gender, :xx)
|
401
|
+
assert_equal true, I18n.inflector.strict.has_token?(:f, :gender, :xx)
|
402
|
+
assert_equal false, I18n.inflector.strict.has_token?(:you, :gender)
|
403
|
+
I18n.locale = :xx
|
404
|
+
assert_equal true, I18n.inflector.strict.has_token?(:f, :gender)
|
405
|
+
assert_equal false, I18n.inflector.strict.has_token?(:you, :gender)
|
406
|
+
assert_equal false, I18n.inflector.strict.has_token?(:faafaffafafa)
|
407
|
+
end
|
408
|
+
|
409
|
+
test "inflector has_kind?: checks if an inflection kind exists" do
|
410
|
+
assert_equal true, I18n.inflector.has_kind?(:gender, :xx)
|
411
|
+
assert_equal true, I18n.inflector.has_kind?(:person, :xx)
|
412
|
+
assert_equal false, I18n.inflector.has_kind?(:nonono, :xx)
|
413
|
+
assert_equal false, I18n.inflector.has_kind?(nil, :xx)
|
414
|
+
I18n.locale = :xx
|
415
|
+
assert_equal true, I18n.inflector.has_kind?(:gender)
|
416
|
+
assert_equal true, I18n.inflector.has_kind?(:person)
|
417
|
+
assert_equal false, I18n.inflector.has_kind?(:faafaffafafa)
|
418
|
+
end
|
419
|
+
|
420
|
+
test "inflector.strict has_kind?: checks if an inflection kind exists" do
|
421
|
+
assert_equal true, I18n.inflector.strict.has_kind?(:gender, :xx)
|
422
|
+
assert_equal false, I18n.inflector.strict.has_kind?(:person, :xx)
|
423
|
+
assert_equal false, I18n.inflector.strict.has_kind?(nil, :xx)
|
424
|
+
I18n.locale = :xx
|
425
|
+
assert_equal true, I18n.inflector.strict.has_kind?(:gender)
|
426
|
+
assert_equal false, I18n.inflector.strict.has_kind?(nil)
|
427
|
+
assert_equal false, I18n.inflector.strict.has_kind?(:faafaffa)
|
428
|
+
end
|
429
|
+
|
276
430
|
test "inflector kind: checks what is the inflection kind of the given token" do
|
277
|
-
assert_equal :gender, I18n.inflector.kind(:neuter,
|
278
|
-
assert_equal :gender, I18n.inflector.kind(:f,
|
279
|
-
assert_equal :person, I18n.inflector.kind(:you,
|
431
|
+
assert_equal :gender, I18n.inflector.kind(:neuter, :xx)
|
432
|
+
assert_equal :gender, I18n.inflector.kind(:f, :xx)
|
433
|
+
assert_equal :person, I18n.inflector.kind(:you, :xx)
|
434
|
+
assert_equal nil, I18n.inflector.kind(nil, :xx)
|
435
|
+
assert_equal nil, I18n.inflector.kind(nil, nil)
|
436
|
+
assert_equal nil, I18n.inflector.kind(:nononono,:xx)
|
280
437
|
I18n.locale = :xx
|
281
438
|
assert_equal :gender, I18n.inflector.kind(:neuter)
|
282
439
|
assert_equal :gender, I18n.inflector.kind(:f)
|
283
440
|
assert_equal :person, I18n.inflector.kind(:you)
|
284
|
-
assert_equal nil,
|
441
|
+
assert_equal nil, I18n.inflector.kind(nil)
|
442
|
+
assert_equal nil, I18n.inflector.kind(:faafaffa)
|
443
|
+
end
|
444
|
+
|
445
|
+
test "inflector.strict kind: checks what is the inflection kind of the given token" do
|
446
|
+
assert_equal :gender, I18n.inflector.strict.kind(:neuter, :gender, :xx)
|
447
|
+
assert_equal :gender, I18n.inflector.strict.kind(:f, :gender, :xx)
|
448
|
+
assert_equal nil, I18n.inflector.strict.kind(:f, :nontrue, :xx)
|
449
|
+
assert_equal nil, I18n.inflector.strict.kind(:f, nil, :xx)
|
450
|
+
assert_equal nil, I18n.inflector.strict.kind(nil, :gender, :xx)
|
451
|
+
assert_equal nil, I18n.inflector.strict.kind(nil, nil, :xx)
|
452
|
+
assert_equal nil, I18n.inflector.strict.kind(:faafaffafafa, nil, :xx)
|
453
|
+
assert_equal nil, I18n.inflector.strict.kind(:nil, :faafafa, :xx)
|
454
|
+
I18n.locale = :xx
|
455
|
+
assert_equal :gender, I18n.inflector.strict.kind(:neuter, :gender)
|
456
|
+
assert_equal :gender, I18n.inflector.strict.kind(:f, :gender)
|
457
|
+
assert_equal nil, I18n.inflector.strict.kind(:f, :nontrue)
|
458
|
+
assert_equal nil, I18n.inflector.strict.kind(nil, :gender)
|
459
|
+
assert_equal nil, I18n.inflector.strict.kind(nil, nil)
|
460
|
+
assert_equal nil, I18n.inflector.strict.kind(:faafaffa)
|
285
461
|
end
|
286
462
|
|
287
|
-
test "inflector true_token: gets true token for
|
463
|
+
test "inflector true_token: gets true token for the given token name" do
|
288
464
|
assert_equal :n, I18n.inflector.true_token(:neuter, :xx)
|
289
465
|
assert_equal :f, I18n.inflector.true_token(:f, :xx)
|
290
466
|
I18n.locale = :xx
|
@@ -293,19 +469,78 @@ class I18nInflectorTest < Test::Unit::TestCase
|
|
293
469
|
assert_equal :f, I18n.inflector.true_token(:f, :xx)
|
294
470
|
assert_equal nil, I18n.inflector.true_token(:f, :person, :xx)
|
295
471
|
assert_equal nil, I18n.inflector.true_token(:f, :nokind, :xx)
|
296
|
-
assert_equal nil, I18n.inflector.true_token(:
|
472
|
+
assert_equal nil, I18n.inflector.true_token(:faafaffa)
|
473
|
+
end
|
474
|
+
|
475
|
+
test "inflector.strict true_token: gets true token for the given token name" do
|
476
|
+
assert_equal :n, I18n.inflector.strict.true_token(:neuter, :gender, :xx )
|
477
|
+
assert_equal :f, I18n.inflector.strict.true_token(:f, :gender, :xx )
|
478
|
+
I18n.locale = :xx
|
479
|
+
assert_equal :n, I18n.inflector.strict.true_token(:neuter, :gender )
|
480
|
+
assert_equal :f, I18n.inflector.strict.true_token(:f, :gender )
|
481
|
+
assert_equal :f, I18n.inflector.strict.true_token(:f, :gender, :xx )
|
482
|
+
assert_equal nil, I18n.inflector.strict.true_token(:f, :person, :xx )
|
483
|
+
assert_equal nil, I18n.inflector.strict.true_token(:f, nil, :xx )
|
484
|
+
assert_equal nil, I18n.inflector.strict.true_token(:faafaffa)
|
297
485
|
end
|
298
486
|
|
299
|
-
test "inflector has_true_token?: tests if true token exists for
|
300
|
-
assert_equal false, I18n.inflector.has_true_token?(:neuter, :xx)
|
301
|
-
assert_equal true, I18n.inflector.has_true_token?(:f,
|
487
|
+
test "inflector has_true_token?: tests if true token exists for the given token name" do
|
488
|
+
assert_equal false, I18n.inflector.has_true_token?(:neuter, :xx )
|
489
|
+
assert_equal true, I18n.inflector.has_true_token?(:f, :xx )
|
302
490
|
I18n.locale = :xx
|
303
|
-
assert_equal false, I18n.inflector.has_true_token?(:neuter)
|
304
|
-
assert_equal true, I18n.inflector.has_true_token?(:f)
|
305
|
-
assert_equal true, I18n.inflector.has_true_token?(:f,
|
306
|
-
assert_equal false, I18n.inflector.has_true_token?(:f,
|
307
|
-
assert_equal false, I18n.inflector.has_true_token?(:f,
|
308
|
-
assert_equal false, I18n.inflector.has_true_token?(:
|
491
|
+
assert_equal false, I18n.inflector.has_true_token?(:neuter )
|
492
|
+
assert_equal true, I18n.inflector.has_true_token?(:f )
|
493
|
+
assert_equal true, I18n.inflector.has_true_token?(:f, :xx )
|
494
|
+
assert_equal false, I18n.inflector.has_true_token?(:f, :person, :xx)
|
495
|
+
assert_equal false, I18n.inflector.has_true_token?(:f, :nokind, :xx)
|
496
|
+
assert_equal false, I18n.inflector.has_true_token?(:faafaff)
|
497
|
+
end
|
498
|
+
|
499
|
+
test "inflector strict markers: tests if named markers in kinds are working for API calls" do
|
500
|
+
tt= {:m=>"male",:f=>"female",:n=>"neuter",:s=>"strange"}
|
501
|
+
t = tt.merge({:masculine=>"male",:feminine=>"female",:neuter=>"neuter",:neutral=>"neuter"})
|
502
|
+
al= {:masculine=>:m,:feminine=>:f,:neuter=>:n,:neutral=>:n}
|
503
|
+
tr= tt.merge(al)
|
504
|
+
assert_equal [:xx], I18n.inflector.inflected_locales( :@gender )
|
505
|
+
assert_equal t, I18n.inflector.tokens( :@gender, :xx )
|
506
|
+
assert_equal tt, I18n.inflector.true_tokens( :@gender, :xx )
|
507
|
+
assert_equal tr, I18n.inflector.raw_tokens( :@gender, :xx )
|
508
|
+
assert_equal :n, I18n.inflector.default_token( :@gender, :xx )
|
509
|
+
assert_equal al, I18n.inflector.aliases( :@gender, :xx )
|
510
|
+
assert_equal true, I18n.inflector.has_kind?( :@gender, :xx )
|
511
|
+
assert_equal true, I18n.inflector.has_alias?( :neuter, :@gender, :xx )
|
512
|
+
assert_equal true, I18n.inflector.has_token?( :n, :@gender, :xx )
|
513
|
+
assert_equal false, I18n.inflector.has_true_token?( :neuter, :@gender, :xx )
|
514
|
+
assert_equal true, I18n.inflector.has_true_token?( :n, :@gender, :xx )
|
515
|
+
assert_equal :n, I18n.inflector.true_token( :neuter, :@gender, :xx )
|
516
|
+
assert_equal "neuter",I18n.inflector.token_description( :neuter, :@gender, :xx )
|
517
|
+
assert_equal "neuter",I18n.inflector.token_description( :n, :@gender, :xx )
|
518
|
+
I18n.locale = :xx
|
519
|
+
assert_equal t, I18n.inflector.tokens( :@gender )
|
520
|
+
assert_equal tt, I18n.inflector.true_tokens( :@gender )
|
521
|
+
assert_equal tr, I18n.inflector.raw_tokens( :@gender )
|
522
|
+
assert_equal :n, I18n.inflector.default_token( :@gender )
|
523
|
+
assert_equal al, I18n.inflector.aliases( :@gender )
|
524
|
+
assert_equal true, I18n.inflector.has_kind?( :@gender )
|
525
|
+
assert_equal true, I18n.inflector.has_alias?( :neuter, :@gender )
|
526
|
+
assert_equal true, I18n.inflector.has_token?( :n, :@gender )
|
527
|
+
assert_equal false, I18n.inflector.has_true_token?( :neuter, :@gender )
|
528
|
+
assert_equal true, I18n.inflector.has_true_token?( :n, :@gender )
|
529
|
+
assert_equal :n, I18n.inflector.true_token( :neuter, :@gender )
|
530
|
+
assert_equal "neuter",I18n.inflector.token_description( :neuter, :@gender )
|
531
|
+
assert_equal "neuter",I18n.inflector.token_description( :n, :@gender )
|
532
|
+
end
|
533
|
+
|
534
|
+
test "inflector.strict has_true_token?: tests if true token exists for the given token name" do
|
535
|
+
assert_equal false, I18n.inflector.strict.has_true_token?(:neuter, :gender, :xx )
|
536
|
+
assert_equal true, I18n.inflector.strict.has_true_token?(:f, :gender, :xx )
|
537
|
+
I18n.locale = :xx
|
538
|
+
assert_equal false, I18n.inflector.strict.has_true_token?(:neuter, :gender )
|
539
|
+
assert_equal true, I18n.inflector.strict.has_true_token?(:f, :gender )
|
540
|
+
assert_equal true, I18n.inflector.strict.has_true_token?(:f, :gender, :xx )
|
541
|
+
assert_equal false, I18n.inflector.strict.has_true_token?(:f, :person, :xx )
|
542
|
+
assert_equal false, I18n.inflector.strict.has_true_token?(:f, nil, :xx )
|
543
|
+
assert_equal false, I18n.inflector.strict.has_true_token?(:faafaff)
|
309
544
|
end
|
310
545
|
|
311
546
|
test "inflector kinds: lists inflection kinds" do
|
@@ -315,6 +550,13 @@ class I18nInflectorTest < Test::Unit::TestCase
|
|
315
550
|
assert_equal [:gender,:person], I18n.inflector.kinds.sort{|k,v| k.to_s<=>v.to_s}
|
316
551
|
end
|
317
552
|
|
553
|
+
test "inflector.strict kinds: lists inflection kinds" do
|
554
|
+
assert_not_nil I18n.inflector.strict.kinds(:xx)
|
555
|
+
assert_equal [:gender], I18n.inflector.strict.kinds(:xx)
|
556
|
+
I18n.locale = :xx
|
557
|
+
assert_equal [:gender], I18n.inflector.strict.kinds
|
558
|
+
end
|
559
|
+
|
318
560
|
test "inflector tokens: lists all inflection tokens including aliases" do
|
319
561
|
h = {:m=>"male",:f=>"female",:n=>"neuter",:s=>"strange",
|
320
562
|
:masculine=>"male",:feminine=>"female",:neuter=>"neuter",
|
@@ -326,6 +568,16 @@ class I18nInflectorTest < Test::Unit::TestCase
|
|
326
568
|
assert_equal ha, I18n.inflector.tokens
|
327
569
|
end
|
328
570
|
|
571
|
+
test "inflector.strict tokens: lists all inflection tokens including aliases" do
|
572
|
+
h = {:m=>"male",:f=>"female",:n=>"neuter",:s=>"strange",
|
573
|
+
:masculine=>"male",:feminine=>"female",:neuter=>"neuter",
|
574
|
+
:neutral=>"neuter"}
|
575
|
+
assert_equal h, I18n.inflector.strict.tokens(:gender, :xx)
|
576
|
+
I18n.locale = :xx
|
577
|
+
assert_equal h, I18n.inflector.strict.tokens(:gender)
|
578
|
+
assert_equal Hash.new, I18n.inflector.strict.tokens
|
579
|
+
end
|
580
|
+
|
329
581
|
test "inflector true_tokens: lists true tokens" do
|
330
582
|
h = {:m=>"male",:f=>"female",:n=>"neuter",:s=>"strange"}
|
331
583
|
ha = h.merge(:i=>"I",:you=>"You")
|
@@ -335,6 +587,14 @@ class I18nInflectorTest < Test::Unit::TestCase
|
|
335
587
|
assert_equal ha, I18n.inflector.true_tokens
|
336
588
|
end
|
337
589
|
|
590
|
+
test "inflector.strict true_tokens: lists true tokens" do
|
591
|
+
h = {:m=>"male",:f=>"female",:n=>"neuter",:s=>"strange"}
|
592
|
+
assert_equal h, I18n.inflector.strict.true_tokens(:gender, :xx)
|
593
|
+
I18n.locale = :xx
|
594
|
+
assert_equal h, I18n.inflector.strict.true_tokens(:gender)
|
595
|
+
assert_equal Hash.new, I18n.inflector.strict.true_tokens
|
596
|
+
end
|
597
|
+
|
338
598
|
test "inflector raw_tokens: lists tokens in a so called raw format" do
|
339
599
|
h = {:m=>"male",:f=>"female",:n=>"neuter",:s=>"strange",
|
340
600
|
:masculine=>:m,:feminine=>:f,:neuter=>:n,
|
@@ -346,12 +606,28 @@ class I18nInflectorTest < Test::Unit::TestCase
|
|
346
606
|
assert_equal ha, I18n.inflector.raw_tokens
|
347
607
|
end
|
348
608
|
|
609
|
+
test "inflector.strict raw_tokens: lists tokens in a so called raw format" do
|
610
|
+
h = {:m=>"male",:f=>"female",:n=>"neuter",:s=>"strange",
|
611
|
+
:masculine=>:m,:feminine=>:f,:neuter=>:n,
|
612
|
+
:neutral=>:n}
|
613
|
+
assert_equal h, I18n.inflector.strict.raw_tokens(:gender, :xx)
|
614
|
+
I18n.locale = :xx
|
615
|
+
assert_equal h, I18n.inflector.strict.raw_tokens(:gender)
|
616
|
+
assert_equal Hash.new, I18n.inflector.strict.raw_tokens
|
617
|
+
end
|
618
|
+
|
349
619
|
test "inflector default_token: returns a default token for a kind" do
|
350
620
|
assert_equal :n, I18n.inflector.default_token(:gender, :xx)
|
351
621
|
I18n.locale = :xx
|
352
622
|
assert_equal :n, I18n.inflector.default_token(:gender)
|
353
623
|
end
|
354
624
|
|
625
|
+
test "inflector.strict default_token: returns a default token for a kind" do
|
626
|
+
assert_equal :n, I18n.inflector.strict.default_token(:gender, :xx)
|
627
|
+
I18n.locale = :xx
|
628
|
+
assert_equal :n, I18n.inflector.strict.default_token(:gender)
|
629
|
+
end
|
630
|
+
|
355
631
|
test "inflector aliases: lists aliases" do
|
356
632
|
a = {:masculine=>:m, :feminine=>:f, :neuter=>:n, :neutral=>:n}
|
357
633
|
assert_equal a, I18n.inflector.aliases(:gender, :xx)
|
@@ -360,22 +636,46 @@ class I18nInflectorTest < Test::Unit::TestCase
|
|
360
636
|
assert_equal a, I18n.inflector.aliases
|
361
637
|
end
|
362
638
|
|
639
|
+
test "inflector.strict aliases: lists aliases" do
|
640
|
+
a = {:masculine=>:m, :feminine=>:f, :neuter=>:n, :neutral=>:n}
|
641
|
+
assert_equal a, I18n.inflector.strict.aliases(:gender, :xx)
|
642
|
+
I18n.locale = :xx
|
643
|
+
assert_equal a, I18n.inflector.strict.aliases(:gender)
|
644
|
+
assert_equal Hash.new, I18n.inflector.strict.aliases
|
645
|
+
end
|
646
|
+
|
363
647
|
test "inflector token_description: returns token's description" do
|
364
648
|
assert_equal "male", I18n.inflector.token_description(:m, :xx)
|
365
649
|
I18n.locale = :xx
|
366
650
|
assert_equal "male", I18n.inflector.token_description(:m)
|
367
|
-
assert_equal nil, I18n.inflector.token_description(:nonexistent,
|
368
|
-
assert_equal "neuter", I18n.inflector.token_description(:neutral,
|
651
|
+
assert_equal nil, I18n.inflector.token_description(:nonexistent, :xx)
|
652
|
+
assert_equal "neuter", I18n.inflector.token_description(:neutral, :xx)
|
653
|
+
end
|
654
|
+
|
655
|
+
test "inflector.strict token_description: returns token's description" do
|
656
|
+
assert_equal "male", I18n.inflector.strict.token_description(:m, :gender, :xx)
|
657
|
+
I18n.locale = :xx
|
658
|
+
assert_equal "male", I18n.inflector.strict.token_description(:m, :gender)
|
659
|
+
assert_equal nil, I18n.inflector.strict.token_description(:nonexistent, :gender, :xx)
|
660
|
+
assert_equal "neuter", I18n.inflector.strict.token_description(:neutral, :gender, :xx)
|
369
661
|
end
|
370
662
|
|
371
663
|
test "inflector has_alias?: tests whether a token is an alias" do
|
372
664
|
assert_equal true, I18n.inflector.has_alias?(:neutral, :xx)
|
373
|
-
assert_equal false, I18n.inflector.has_alias?(:you,
|
665
|
+
assert_equal false, I18n.inflector.has_alias?(:you, :xx)
|
374
666
|
assert_equal true, I18n.inflector.has_alias?(:neutral, :gender, :xx)
|
375
|
-
assert_equal false, I18n.inflector.has_alias?(:you,
|
667
|
+
assert_equal false, I18n.inflector.has_alias?(:you, :gender, :xx)
|
376
668
|
assert_equal false, I18n.inflector.has_alias?(:neutral, :nokind, :xx)
|
377
669
|
I18n.locale = :xx
|
378
670
|
assert_equal true, I18n.inflector.has_alias?(:neutral)
|
379
671
|
end
|
380
672
|
|
673
|
+
test "inflector.strict has_alias?: tests whether a token is an alias" do
|
674
|
+
assert_equal true, I18n.inflector.strict.has_alias?(:neutral, :gender, :xx)
|
675
|
+
assert_equal false, I18n.inflector.strict.has_alias?(:you, :person, :xx)
|
676
|
+
assert_equal false, I18n.inflector.strict.has_alias?(:you, :gender, :xx)
|
677
|
+
I18n.locale = :xx
|
678
|
+
assert_equal true, I18n.inflector.strict.has_alias?(:neutral, :gender)
|
679
|
+
end
|
680
|
+
|
381
681
|
end
|
data/test/test_helper.rb
CHANGED
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 2
|
7
|
-
- 0
|
8
7
|
- 1
|
9
|
-
|
8
|
+
- 0
|
9
|
+
version: 2.1.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- "Pawe\xC5\x82 Wilk"
|
@@ -34,7 +34,7 @@ cert_chain:
|
|
34
34
|
NK3TIZaPCh1S2/ES6wXNvjQ+5EnEEL9j/pSEop9DYEBPaM2WDVR5i0jJTAaRWw==
|
35
35
|
-----END CERTIFICATE-----
|
36
36
|
|
37
|
-
date: 2011-01-
|
37
|
+
date: 2011-01-27 00:00:00 +01:00
|
38
38
|
default_executable:
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
@@ -160,7 +160,9 @@ files:
|
|
160
160
|
- README.rdoc
|
161
161
|
- Rakefile
|
162
162
|
- ci/i18n-inflector.gemspec
|
163
|
+
- ci/i18nv4-Gemfile
|
163
164
|
- docs/COPYING
|
165
|
+
- docs/EXAMPLES
|
164
166
|
- docs/HISTORY
|
165
167
|
- docs/LEGAL
|
166
168
|
- docs/LGPL
|
@@ -168,13 +170,16 @@ files:
|
|
168
170
|
- docs/TODO
|
169
171
|
- docs/rdoc.css
|
170
172
|
- lib/i18n-inflector.rb
|
173
|
+
- lib/i18n-inflector/api.rb
|
174
|
+
- lib/i18n-inflector/api_strict.rb
|
171
175
|
- lib/i18n-inflector/backend.rb
|
172
176
|
- lib/i18n-inflector/errors.rb
|
173
177
|
- lib/i18n-inflector/inflection_data.rb
|
178
|
+
- lib/i18n-inflector/inflection_data_strict.rb
|
174
179
|
- lib/i18n-inflector/inflector.rb
|
180
|
+
- lib/i18n-inflector/lazy_enum.rb
|
175
181
|
- lib/i18n-inflector/long_comments.rb
|
176
182
|
- lib/i18n-inflector/options.rb
|
177
|
-
- lib/i18n-inflector/util.rb
|
178
183
|
- lib/i18n-inflector/version.rb
|
179
184
|
- test/inflector_test.rb
|
180
185
|
- test/test_helper.rb
|
@@ -194,7 +199,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
194
199
|
requirements:
|
195
200
|
- - ">="
|
196
201
|
- !ruby/object:Gem::Version
|
197
|
-
hash:
|
202
|
+
hash: 3836781751216313437
|
198
203
|
segments:
|
199
204
|
- 0
|
200
205
|
version: "0"
|
@@ -203,7 +208,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
203
208
|
requirements:
|
204
209
|
- - ">="
|
205
210
|
- !ruby/object:Gem::Version
|
206
|
-
hash: -2908677002477829649
|
207
211
|
segments:
|
208
212
|
- 0
|
209
213
|
version: "0"
|
metadata.gz.sig
CHANGED
Binary file
|
data/lib/i18n-inflector/util.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
|
-
# Author:: Paweł Wilk (mailto:pw@gnu.org)
|
4
|
-
# Copyright:: (c) 2011 by Paweł Wilk
|
5
|
-
# License:: This program is licensed under the terms of {file:LGPL GNU Lesser General Public License} or {file:COPYING Ruby License}.
|
6
|
-
#
|
7
|
-
# This file contains utility methods,
|
8
|
-
# that are used by I18n::Inflector.
|
9
|
-
|
10
|
-
module I18n
|
11
|
-
module Inflector
|
12
|
-
|
13
|
-
# This module contains some methods that are helpful.
|
14
|
-
module Util
|
15
|
-
|
16
|
-
protected
|
17
|
-
|
18
|
-
# Processes +locale+ name and validates
|
19
|
-
# if it's correct (not empty and not +nil+).
|
20
|
-
#
|
21
|
-
# @note If the +locale+ is not correct, it
|
22
|
-
# tries to use locale from {I18n.locale} and validates it
|
23
|
-
# as well.
|
24
|
-
# @param [Symbol,String] locale the locale identifier
|
25
|
-
# @raise [I18n::InvalidLocale] if there is no proper locale name
|
26
|
-
# @return [Symbol] the given locale or the global locale
|
27
|
-
def prep_locale(locale=nil)
|
28
|
-
locale ||= I18n.locale
|
29
|
-
raise I18n::InvalidLocale.new(locale) if locale.to_s.empty?
|
30
|
-
locale.to_sym
|
31
|
-
end
|
32
|
-
|
33
|
-
# This method is the internal helper that prepares arguments
|
34
|
-
# containing +token+, +kind+ and +locale+.
|
35
|
-
#
|
36
|
-
# @note This method leaves +kind+ as is when it's +nil+ or empty. It sets
|
37
|
-
# +token+ to +nil+ when it's empty.
|
38
|
-
# @raise [I18n::InvalidLocale] if there is no proper locale name
|
39
|
-
# @raise [ArgumentError] if the count of arguments is invalid
|
40
|
-
# @return [Array<Symbol,Symbol,Symbol>] the array containing
|
41
|
-
# cleaned and validated +token+, +kind+ and +locale+
|
42
|
-
# @overload tkl_args(token, kind, locale)
|
43
|
-
# Prepares arguments containing +token+, +kind+ and +locale+.
|
44
|
-
# @param [String,Hash] token the token
|
45
|
-
# @param [String,Hash] kind the inflection kind
|
46
|
-
# @param [String,Hash] locale the locale identifier
|
47
|
-
# @return [Array<Symbol,Symbol,Symbol>] the array containing
|
48
|
-
# cleaned and validated +token+, +kind+ and +locale+
|
49
|
-
# @overload tkl_args(token, locale)
|
50
|
-
# Prepares arguments containing +token+ and +locale+.
|
51
|
-
# @param [String,Hash] token the token
|
52
|
-
# @param [String,Hash] locale the locale identifier
|
53
|
-
# @return [Array<Symbol,Symbol,Symbol>] the array containing
|
54
|
-
# cleaned and validated +token+, +kind+ and +locale+
|
55
|
-
def tkl_args(args)
|
56
|
-
token, kind, locale = case args.count
|
57
|
-
when 1 then [args[0], nil, nil]
|
58
|
-
when 2 then [args[0], nil, args[1]]
|
59
|
-
when 3 then args
|
60
|
-
else raise ArgumentError.new("wrong number of arguments: #{args.count} for (1..3)")
|
61
|
-
end
|
62
|
-
[token,kind,locale]
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|