@@ -13,14 +13,18 @@ def piece(type, prefix = nil, suffix = nil)
13
13
end
14
14
15
15
def to_s
16
- @types . each_with_object ( @base || '' ) do |( type , segments ) , str |
16
+ string = @base || ''
17
+ @types . each do |type , segments |
17
18
if f = self . class . formatter ( type )
18
- str << ' ' << f . call ( segments )
19
+ current = f . call ( segments )
19
20
else
20
21
next if segments . empty?
21
- str << ' ' << self . class . sentence ( segments )
22
+ current = self . class . sentence ( segments )
22
23
end
24
+ f = I18n . t ( 'ice_cube.string.format' ) [ type ] ? type : 'default'
25
+ string = I18n . t ( "ice_cube.string.format.#{ f } " , rest : string , current : current )
23
26
end
27
+ string
24
28
end
25
29
26
30
def self . formatter ( type )
@@ -39,8 +43,8 @@ def sentence(array)
39
43
case array . length
40
44
when 0 ; ''
41
45
when 1 ; array [ 0 ] . to_s
42
- when 2 ; "#{ array [ 0 ] } and #{ array [ 1 ] } "
43
- else ; "#{ array [ 0 ...-1 ] . join ( ', ' ) } , and #{ array [ -1 ] } "
46
+ when 2 ; "#{ array [ 0 ] } #{ I18n . t ( 'ice_cube.array.two_words_connector' ) } #{ array [ 1 ] } "
47
+ else ; "#{ array [ 0 ...-1 ] . join ( I18n . t ( 'ice_cube.array.words_connector' ) ) } #{ I18n . t ( 'ice_cube.array.last_word_connector' ) } #{ array [ -1 ] } "
44
48
end
45
49
end
46
50
@@ -49,7 +53,7 @@ def nice_number(number)
49
53
end
50
54
51
55
def ordinalize ( number )
52
- " #{ number } #{ ordinal ( number ) } "
56
+ I18n . t ( 'ice_cube.integer.ordinal' , number : number , ordinal : ordinal ( number ) )
53
57
end
54
58
55
59
def literal_ordinal ( number )
0 commit comments