i18n-inflector 2.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +1 -1
- data/ChangeLog +156 -0
- data/Gemfile +0 -1
- data/Manifest.txt +1 -1
- data/README.rdoc +21 -8
- data/ci/i18n-inflector.gemspec +1 -1
- data/docs/EXAMPLES +2 -2
- data/docs/HISTORY +16 -0
- data/docs/TODO +1 -1
- data/docs/USAGE +939 -0
- data/lib/i18n-inflector/api.rb +14 -14
- data/lib/i18n-inflector/backend.rb +2 -2
- data/lib/i18n-inflector/config.rb +17 -11
- data/lib/i18n-inflector/errors.rb +2 -2
- data/lib/i18n-inflector/inflector.rb +11 -0
- data/lib/i18n-inflector/interpolate.rb +77 -10
- data/lib/i18n-inflector/long_comments.rb +3 -783
- data/lib/i18n-inflector/version.rb +1 -1
- data/test/inflector_test.rb +57 -2
- data.tar.gz.sig +0 -0
- metadata +5 -5
- metadata.gz.sig +0 -0
- data/docs/RELATIONS +0 -28
data/test/inflector_test.rb
CHANGED
@@ -194,9 +194,11 @@ class I18nInflectorTest < Test::Unit::TestCase
|
|
194
194
|
end
|
195
195
|
|
196
196
|
test "backend inflector translate: falls back to default token for ommited gender option when :inflector_excluded_defaults is true" do
|
197
|
-
assert_equal 'Dear You!', I18n.t('welcome',
|
197
|
+
assert_equal 'Dear You!', I18n.t('welcome', :gender => :s, :locale => :xx, :inflector_excluded_defaults => true)
|
198
|
+
assert_equal 'Dear You!', I18n.t('named_welcome', :@gender => :s, :locale => :xx, :inflector_excluded_defaults => true)
|
198
199
|
I18n.inflector.options.excluded_defaults = true
|
199
|
-
assert_equal 'Dear You!', I18n.t('welcome',
|
200
|
+
assert_equal 'Dear You!', I18n.t('welcome', :gender => :s, :locale => :xx)
|
201
|
+
assert_equal 'Dear You!', I18n.t('named_welcome', :gender => :s, :locale => :xx)
|
200
202
|
end
|
201
203
|
|
202
204
|
test "backend inflector translate: falls back to free text for ommited gender option when :inflector_excluded_defaults is false" do
|
@@ -316,9 +318,20 @@ class I18nInflectorTest < Test::Unit::TestCase
|
|
316
318
|
end
|
317
319
|
end
|
318
320
|
|
321
|
+
test "backend inflector translate: works with wildcard tokens" do
|
322
|
+
store_translations(:xx, 'hi' => 'Dear @{n:You|*:Any|All}!')
|
323
|
+
assert_equal 'Dear You!', I18n.t('hi', :gender => :n, :locale => :xx)
|
324
|
+
assert_equal 'Dear Any!', I18n.t('hi', :gender => :m, :locale => :xx)
|
325
|
+
assert_equal 'Dear Any!', I18n.t('hi', :gender => :f, :locale => :xx)
|
326
|
+
assert_equal 'Dear You!', I18n.t('hi', :gender => :xxxxxx, :locale => :xx)
|
327
|
+
assert_equal 'Dear You!', I18n.t('hi', :locale => :xx)
|
328
|
+
end
|
329
|
+
|
319
330
|
test "backend inflector translate: works with loud tokens" do
|
320
331
|
store_translations(:xx, 'hi' => 'Dear @{m:~|n:You|All}!')
|
321
332
|
assert_equal 'Dear male!', I18n.t('hi', :gender => :m, :locale => :xx)
|
333
|
+
store_translations(:xx, 'hi' => 'Dear @gender{m:~|n:You|All}!')
|
334
|
+
assert_equal 'Dear male!', I18n.t('hi', :gender => :m, :locale => :xx)
|
322
335
|
store_translations(:xx, 'hi' => 'Dear @{masculine:~|n:You|All}!')
|
323
336
|
assert_equal 'Dear male!', I18n.t('hi', :gender => :m, :locale => :xx, :inflector_aliased_patterns => true)
|
324
337
|
store_translations(:xx, 'hi' => 'Dear @{f,m:~|n:You|All}!')
|
@@ -329,6 +342,23 @@ class I18nInflectorTest < Test::Unit::TestCase
|
|
329
342
|
assert_equal 'Dear ~!', I18n.t('hi', :gender => :m, :locale => :xx)
|
330
343
|
store_translations(:xx, 'hi' => 'Dear @{!n:\\\\~|n:You|All}!')
|
331
344
|
assert_equal 'Dear \\~!', I18n.t('hi', :gender => :m, :locale => :xx)
|
345
|
+
store_translations(:xx, 'hi' => 'Dear @{*:~|n:You|All}!')
|
346
|
+
assert_equal 'Dear male!', I18n.t('hi', :gender => :m, :locale => :xx)
|
347
|
+
store_translations(:xx, 'hi' => 'Dear @{*:~|n:You|All}!')
|
348
|
+
assert_equal 'Dear neuter!', I18n.t('hi', :locale => :xx)
|
349
|
+
store_translations(:xx, 'hi' => 'Dear @{m:abc|*:~|n:You|All}!')
|
350
|
+
assert_equal 'Dear neuter!', I18n.t('hi', :locale => :xx)
|
351
|
+
store_translations(:xx, 'hi' => 'Dear @{*:~|All}!')
|
352
|
+
assert_equal 'Dear All!', I18n.t('hi', :gender => :unasdasd, :locale => :xx)
|
353
|
+
store_translations(:xx, 'hi' => 'Dear @{*:~|All}!')
|
354
|
+
assert_equal 'Dear All!', I18n.t('hi', :gender => nil, :locale => :xx)
|
355
|
+
store_translations(:xx, 'hi' => 'Dear @{*:~|All}!')
|
356
|
+
assert_equal 'Dear neuter!', I18n.t('hi', :gender => :n, :locale => :xx)
|
357
|
+
store_translations(:xx, :i18n => { :inflections => { :@tense => { :s => 's', :now => 'now', :past => 'later', :default => 'now' }}})
|
358
|
+
store_translations(:xx, 'hi' => 'Dear @gender+tense{*+*:~|All}!')
|
359
|
+
assert_equal 'Dear male now!', I18n.t('hi', :gender => :m, :person => :i, :locale => :xx)
|
360
|
+
assert_equal 'Dear neuter now!', I18n.t('hi', :locale => :xx)
|
361
|
+
assert_equal 'Dear neuter later!', I18n.t('hi', :tense => :past, :locale => :xx)
|
332
362
|
end
|
333
363
|
|
334
364
|
test "backend inflector translate: works with tokens separated by commas" do
|
@@ -376,6 +406,31 @@ class I18nInflectorTest < Test::Unit::TestCase
|
|
376
406
|
assert_equal 'Dear Sir!', I18n.t('hi', :gender => :masculine, :locale => :xx)
|
377
407
|
end
|
378
408
|
|
409
|
+
test "backend inflector translate: works with Method and Proc object given as inflection options" do
|
410
|
+
def femme
|
411
|
+
kind, locale = yield
|
412
|
+
(locale == :xx && kind == :gender) ? :f : :m
|
413
|
+
end
|
414
|
+
def excluded
|
415
|
+
:s
|
416
|
+
end
|
417
|
+
def bad_method(a,b,c)
|
418
|
+
:m
|
419
|
+
end
|
420
|
+
procek = method(:femme)
|
421
|
+
procun = method(:excluded)
|
422
|
+
badmet = method(:bad_method)
|
423
|
+
assert_equal 'Dear Lady!', I18n.t('welcome', :gender => procek, :locale => :xx, :inflector_raises => true)
|
424
|
+
assert_equal 'Dear Lady!', I18n.t('named_welcome', :gender => procek, :locale => :xx, :inflector_raises => true)
|
425
|
+
assert_equal 'Dear Sir!', I18n.t('named_welcome', :@gender => procek, :locale => :xx, :inflector_raises => true)
|
426
|
+
assert_equal 'Dear You!', I18n.t('named_welcome', :@gender => procun, :locale => :xx, :inflector_excluded_defaults => true)
|
427
|
+
assert_equal 'Dear All!', I18n.t('named_welcome', :@gender => procun, :locale => :xx, :inflector_excluded_defaults => false)
|
428
|
+
assert_raise(ArgumentError) { I18n.t('named_welcome', :@gender => badmet, :locale => :xx, :inflector_raises => true) }
|
429
|
+
assert_equal 'Dear Sir!', I18n.t('named_welcome', :@gender => lambda{|k,l|:m}, :locale => :xx, :inflector_raises => true)
|
430
|
+
assert_equal 'Dear Lady!', I18n.t('welcome', :gender => lambda{|k,l| k==:gender ? :f : :s},
|
431
|
+
:locale => :xx, :inflector_raises => true)
|
432
|
+
end
|
433
|
+
|
379
434
|
test "backend inflector translate: recognizes named patterns and strict kinds" do
|
380
435
|
store_translations(:xx, :i18n => { :inflections => { :@gender => { :s => 'sir', :o => 'other', :s => 'a', :n => 'n', :default => 'n' }}})
|
381
436
|
store_translations(:xx, 'hi' => 'Dear @gender{s:Sir|o:Other|n:You|All}!')
|
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
|
-
-
|
7
|
+
- 3
|
8
8
|
- 0
|
9
|
-
version: 2.
|
9
|
+
version: 2.3.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-02-
|
37
|
+
date: 2011-02-15 00:00:00 +01:00
|
38
38
|
default_executable:
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
@@ -166,8 +166,8 @@ files:
|
|
166
166
|
- docs/HISTORY
|
167
167
|
- docs/LEGAL
|
168
168
|
- docs/LGPL
|
169
|
-
- docs/RELATIONS
|
170
169
|
- docs/TODO
|
170
|
+
- docs/USAGE
|
171
171
|
- docs/rdoc.css
|
172
172
|
- lib/i18n-inflector.rb
|
173
173
|
- lib/i18n-inflector/api.rb
|
@@ -202,7 +202,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
202
202
|
requirements:
|
203
203
|
- - ">="
|
204
204
|
- !ruby/object:Gem::Version
|
205
|
-
hash:
|
205
|
+
hash: 328005108320986089
|
206
206
|
segments:
|
207
207
|
- 0
|
208
208
|
version: "0"
|
metadata.gz.sig
CHANGED
Binary file
|
data/docs/RELATIONS
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
== This library contains
|
2
|
-
|
3
|
-
* Module {I18n::Inflector} containing everything
|
4
|
-
* Class {I18n::Inflector::API} used to create inflector object attached to I18n backend (handles regular and strict kinds)
|
5
|
-
* Class {I18n::Inflector::API_Strict} which instance is attached to {I18n::Inflector::API} and handles strict kinds
|
6
|
-
* Class {I18n::Inflector::InflectionData} used to store inflection data for regular kinds and tokens
|
7
|
-
* Class {I18n::Inflector::InflectionData_Strict} used to store inflection data for strict kinds and tokens
|
8
|
-
* Class {I18n::Inflector::InflectionOptions} used for keeping switches and options
|
9
|
-
* Class {I18n::Inflector::LazyHashEnumerator} used to manage lazy evaluation of internal data
|
10
|
-
* Module {I18n::Backend::Inflector} used to alter methods of {I18n::Backend::Simple}
|
11
|
-
* Several classes for error reporting
|
12
|
-
|
13
|
-
== Relations
|
14
|
-
|
15
|
-
* {I18n.backend} is the currently used backend and the instance of {I18n::Backend::Simple}
|
16
|
-
* {I18n.backend.inflector} is the instance of {I18n::Inflector::API} attached to backend
|
17
|
-
* {I18n.inflector} is the proxy module method that calls inflector for currently used backend {I18n.backend.inflector}
|
18
|
-
* {I18n.backend.inflector.options} is the instance of {I18n::Inflector::InflectionOptions} and
|
19
|
-
mainly it controls a behavior of interpolation method
|
20
|
-
* {I18n.backend.inflector.strict} is the instance of {I18n::Inflector::API_Strict} and handles strict kinds
|
21
|
-
* {I18n.backend.inflector} uses {I18n.backend.inflector.strict} to access strict kinds when it's needed
|
22
|
-
* {I18n::Inflector::API} has an instance variable @idb that contains database of inflections indexed by locale
|
23
|
-
* {I18n::Inflector::API_Strict} has an instance variable @idb that contains database of inflections indexed by locale
|
24
|
-
* Translation databases are kind of {I18n::Inflector::InflectionData} and {I18n::Inflector::InflectionData_Strict}
|
25
|
-
* When initializing translations a method from {I18n::Backend::Simple} (altered by {I18n::Backend::Inflector})
|
26
|
-
takes the loaded data, processes their <tt>i18n.inflections</tt> scope for each locale and creates database
|
27
|
-
objects which are kind of {I18n::Inflector::InflectionData} and {I18n::Inflector::InflectionData_Strict}. That
|
28
|
-
objects are then attached to instances of {I18n::Inflector::API} and {I18n::Inflector::API_Strict}.
|