i18n-inflector 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
data/ChangeLog CHANGED
@@ -1,3 +1,33 @@
1
+ commit 2fddd234ffe5847ad21d46c36495c02431684ad4
2
+ Author: Paweł Wilk <siefca@gnu.org>
3
+ Date: Wed Feb 23 23:12:04 2011 +0100
4
+
5
+ Release 2.5.0
6
+
7
+ commit 0b49cd677a695db4b8f50151529555155fadce59
8
+ Author: Paweł Wilk <siefca@gnu.org>
9
+ Date: Wed Feb 23 23:08:06 2011 +0100
10
+
11
+ Added tests covering fixed bug that caused Arrays to be interpolated in a wrong way
12
+
13
+ commit 80fa0b092de9bc08ee16e64ae6d93b799e6ee521
14
+ Author: Paweł Wilk <siefca@gnu.org>
15
+ Date: Wed Feb 23 23:07:34 2011 +0100
16
+
17
+ Interpolation wrapper refactored; it now operates on Arrays, Hashes, Symbols and other objects
18
+
19
+ commit ab5f5bc04814c1181bd9919ce159292362abc3bb
20
+ Author: Paweł Wilk <siefca@gnu.org>
21
+ Date: Wed Feb 23 23:06:18 2011 +0100
22
+
23
+ Added string version of regexps to constants for debugging purposes
24
+
25
+ commit 8a27302b1535c68496cc60b55bcdfc958f837300
26
+ Author: Paweł Wilk <siefca@gnu.org>
27
+ Date: Wed Feb 23 23:05:34 2011 +0100
28
+
29
+ Dependencies updated
30
+
1
31
  commit 6d343ad3137735492e130b7abdd8f86bf23a4a06
2
32
  Author: Paweł Wilk <siefca@gnu.org>
3
33
  Date: Wed Feb 23 02:20:18 2011 +0100
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = Simple Inflector for I18n
2
2
 
3
- <b>i18n-inflector version <tt>2.3</tt></b> (<b><tt>Dogma</tt></b>)
3
+ <b>i18n-inflector version <tt>2.5</tt></b> (<b><tt>Akasha</tt></b>)
4
4
 
5
5
 
6
6
 
data/Rakefile CHANGED
@@ -56,9 +56,9 @@ Hoe.spec 'i18n-inflector' do
56
56
  self.history_file = 'docs/HISTORY'
57
57
 
58
58
  extra_deps << ['i18n', '>= 0.4.1']
59
- extra_dev_deps << ['test_declarative', '>= 0.0.4'] <<
60
- ['yard', '>= 0.6.4'] <<
61
- ['bundler', '>= 1.0.7'] <<
59
+ extra_dev_deps << ['test_declarative', '>= 0.0.4'] <<
60
+ ['yard', '>= 0.6.4'] <<
61
+ ['bundler', '>= 1.0.10'] <<
62
62
  ['hoe-bundler', '>= 1.0.0']
63
63
 
64
64
  unless extra_dev_deps.flatten.include?('hoe-yard')
@@ -19,13 +19,14 @@ Gem::Specification.new do |s|
19
19
  s.platform = Gem::Platform::RUBY
20
20
  s.require_path = 'lib'
21
21
  s.rubyforge_project = '[none]'
22
- s.required_rubygems_version = '>= 1.3.5'
22
+ s.required_rubygems_version = '>= 1.4.0'
23
23
  s.specification_version = 3
24
24
 
25
25
  s.add_dependency 'i18n', '>= 0.4.1'
26
26
  s.add_development_dependency 'test_declarative', '>= 0.0.4'
27
27
  s.add_development_dependency 'rspec', '>= 2.3.0'
28
28
  s.add_development_dependency 'yard', '>= 1.0.7'
29
+ s.add_development_dependency 'yard', '>= 1.0.10'
29
30
  s.add_development_dependency 'hoe-yard', '>= 0.1.2'
30
31
  s.add_development_dependency 'hoe-bundler', '>= 1.0.0'
31
32
 
data/docs/HISTORY CHANGED
@@ -1,8 +1,29 @@
1
+ === 2.5.0 / 2011-02-24
2
+
3
+ * major enhancements
4
+
5
+ * Interpolation wrapper refactored; works with many types of results
6
+ * Added :inflector_interpolate_symbols switch
7
+
8
+ * minor enhancements
9
+
10
+ * Added TOKENS_RESTR, MULTI_RESTR and PATTERN_RESTR configuration constants
11
+ * Dependencies updated
12
+
13
+ * major bugfixes
14
+
15
+ * Fixed interpolation of Arrays
16
+
17
+ * minor bugfixes
18
+
19
+ * Fixed pattern filtering when locale is invalid or not inflected
20
+
1
21
  === 2.4.0 / 2011-02-23
2
22
 
3
23
  * major enhancements
4
24
 
5
25
  * Added nested translations (collections) support
26
+ * Added :inflector_traverses switch
6
27
 
7
28
  === 2.3.1 / 2011-02-14
8
29
 
@@ -258,24 +258,33 @@ module I18n
258
258
 
259
259
  end # module Reserved
260
260
 
261
+ # A string for regular expression that catches patterns.
262
+ PATTERN_RESTR = '(.?)' + Markers::PATTERN +
263
+ '([^\\' + Markers::PATTERN_BEGIN + ']*)\\' + Markers::PATTERN_BEGIN +
264
+ '([^\\' + Markers::PATTERN_END + ']+)\\' + Markers::PATTERN_END +
265
+ '((?:\\'+ Markers::PATTERN_BEGIN + '([^\\' + Markers::PATTERN_BEGIN +
266
+ ']+)\\' + Markers::PATTERN_END + ')*)'
267
+
268
+ # A string for regular expression that extracts additional patterns attached.
269
+ MULTI_RESTR = '\\' + Markers::PATTERN_BEGIN +
270
+ '([^\\' + Markers::PATTERN_END + ']+)\\' +
271
+ Markers::PATTERN_END
272
+
273
+ # A regular expression that catches token groups or single tokens.
274
+ TOKENS_RESTR = '(?:' +
275
+ '([^' + Operators::Tokens::ASSIGN + '\\' + Operators::Tokens::OR + ']+)' +
276
+ Operators::Tokens::ASSIGN + '+' +
277
+ '([^\\' + Operators::Tokens::OR + ']+)\1?)' +
278
+ '|([^' + Operators::Tokens::ASSIGN + '\\' + Operators::Tokens::OR + ']+)'
279
+
261
280
  # A regular expression that catches patterns.
262
- PATTERN_REGEXP = Regexp.new '(.?)' + Markers::PATTERN +
263
- '([^\\' + Markers::PATTERN_BEGIN + ']*)\\' + Markers::PATTERN_BEGIN +
264
- '([^\\' + Markers::PATTERN_END + ']+)\\' + Markers::PATTERN_END +
265
- '((?:\\'+ Markers::PATTERN_BEGIN + '([^\\' + Markers::PATTERN_BEGIN +
266
- ']+)\\' + Markers::PATTERN_END + ')*)'
281
+ PATTERN_REGEXP = Regexp.new PATTERN_RESTR
267
282
 
268
283
  # A regular expression that extracts additional patterns attached.
269
- MULTI_REGEXP = Regexp.new '\\' + Markers::PATTERN_BEGIN +
270
- '([^\\' + Markers::PATTERN_END + ']+)\\' +
271
- Markers::PATTERN_END
284
+ MULTI_REGEXP = Regexp.new MULTI_RESTR
272
285
 
273
286
  # A regular expression that catches token groups or single tokens.
274
- TOKENS_REGEXP = Regexp.new '(?:' +
275
- '([^' + Operators::Tokens::ASSIGN + '\\' + Operators::Tokens::OR + ']+)' +
276
- Operators::Tokens::ASSIGN + '+' +
277
- '([^\\' + Operators::Tokens::OR + ']+)\1?)' +
278
- '|([^' + Operators::Tokens::ASSIGN + '\\' + Operators::Tokens::OR + ']+)'
287
+ TOKENS_REGEXP = Regexp.new TOKENS_RESTR
279
288
 
280
289
  end # module Config
281
290
 
@@ -22,7 +22,7 @@ module I18n
22
22
  end
23
23
  end
24
24
 
25
- # @version 2.3
25
+ # @version 2.5
26
26
  # @api public
27
27
  #
28
28
  # This module contains inflection classes and modules for enabling
@@ -40,29 +40,48 @@ module I18n
40
40
  # that overrides global setting (see: {I18n::Inflector::InflectionOptions#cache_aware})
41
41
  # @option options [Boolean] :inflector_traverses (true) local switch
42
42
  # that overrides global setting (see: {I18n::Inflector::InflectionOptions#traverses})
43
+ # @option options [Boolean] :inflector_interpolate_symbols (false) local switch
44
+ # that overrides global setting (see: {I18n::Inflector::InflectionOptions#interpolate_symbols})
43
45
  # @return [String] the string with interpolated patterns
44
46
  def interpolate(string, locale, options = {})
45
47
 
46
- # traverse tree and call interpolate for each value
47
- if string.is_a?(Hash)
48
- return string unless options[:inflector_traverses]
49
- return string.merge(string) do |k, v|
50
- interpolate(v, locale, options)
48
+ case string
49
+
50
+ when String
51
+
52
+ if (locale.nil? || !inflected_locale?(locale))
53
+ string.gsub(PATTERN_REGEXP) { Escapes::PATTERN[$1] ? $& : $1 }
54
+ elsif !string.include?(Markers::PATTERN)
55
+ string
56
+ else
57
+ interpolate_core(string, locale, options)
51
58
  end
52
- end
53
59
 
54
- # return immediatelly if something is wrong with locale (preventive)
55
- # return if locale is not inflected - return string cleaned from pattern
56
- if (locale.nil? || !inflected_locale?(locale))
57
- return string.to_s.gsub(PATTERN_REGEXP) do
58
- Escapes::PATTERN[$1] ? $& : ''
60
+ when Hash
61
+
62
+ options[:inflector_traverses] ?
63
+ string.merge(string) { |k,v| interpolate(v, locale, options) } : string
64
+
65
+ when Array
66
+
67
+ options[:inflector_traverses] ?
68
+ string.map { |v| interpolate(v, locale, options) } : string
69
+
70
+ when Symbol
71
+
72
+ if options[:inflector_interpolate_symbols]
73
+ r = interpolate(string.to_s, locale, options)
74
+ r.to_sym rescue :" "
75
+ else
76
+ string
59
77
  end
60
- end
61
78
 
62
- # no pattern in a string - return string as is
63
- return string unless string.to_s.include?(Markers::PATTERN)
79
+ else
80
+
81
+ string
82
+
83
+ end
64
84
 
65
- interpolate_core(string, locale, options)
66
85
  end
67
86
 
68
87
  # This method creates an inflection pattern
@@ -121,6 +121,27 @@ module I18n
121
121
  # @param [Boolean] state +true+ enables, +false+ disables this switch
122
122
  attr_accessor :traverses
123
123
 
124
+ # This is a switch that enables interpolation of symbols. Whenever
125
+ # interpolation method will receive a collection of symbols as a result
126
+ # of calling underlying translation method
127
+ # it won't process them, returning as they are, unless
128
+ # this switch is enabled.
129
+ #
130
+ # Note that using symbols as values in translation data creates
131
+ # I18n aliases. This option is intended to work with arrays of
132
+ # symbols or hashes with symbols as values, if the original translation
133
+ # method returns such structures.
134
+ #
135
+ # This switch is by default set to +false+.
136
+ #
137
+ # @note Local option +:inflector_interpolate_symbols+ passed to the
138
+ # {I18n::Backend::Inflector#translate} overrides this setting.
139
+ #
140
+ # @api public
141
+ # @return [Boolean] state of the switch
142
+ # @param [Boolean] state +true+ enables, +false+ disables this switch
143
+ attr_accessor :interpolate_symbols
144
+
124
145
  # When this switch is set to +true+ then inflector falls back to the default
125
146
  # token for a kind if an inflection option passed to the
126
147
  # {I18n::Backend::Inflector#translate} is unknown or +nil+.
@@ -264,6 +285,7 @@ module I18n
264
285
  def reset
265
286
  @unknown_defaults = true
266
287
  @traverses = true
288
+ @interpolate_symbols= false
267
289
  @excluded_defaults = false
268
290
  @aliased_patterns = false
269
291
  @cache_aware = false
@@ -14,7 +14,7 @@ module I18n
14
14
  # @private
15
15
  EMAIL = 'pw@gnu.org'
16
16
  # @private
17
- VERSION = '2.4.0'
17
+ VERSION = '2.5.0'
18
18
  # @private
19
19
  NAME = 'i18n-inflector'
20
20
  # @private
@@ -373,6 +373,32 @@ class I18nInflectorTest < Test::Unit::TestCase
373
373
  assert_equal h, I18n.t('welcomes', :gender => :m, :foo => 5, :locale => :xx)
374
374
  end
375
375
 
376
+ test "backend inflector translate: works with arrays as results" do
377
+ a = [ :one, :two, :three ]
378
+ store_translations(:xx, 'welcomes' => {'hi' => a})
379
+ store_translations(:uu, 'welcomes' => {'hi' => a})
380
+ assert_equal a, I18n.t('welcomes.hi', :gender => :m, :locale => :xx)
381
+ assert_equal a, I18n.t('welcomes.hi', :gender => :m, :locale => :uu)
382
+ a = [ :one, :two, :"x@{m:man|woman}d" ]
383
+ store_translations(:xx, 'welcomes' => {'hi' => a})
384
+ store_translations(:uu, 'welcomes' => {'hi' => a})
385
+ assert_equal a, I18n.t('welcomes.hi', :gender => :m, :locale => :xx)
386
+ assert_equal a, I18n.t('welcomes.hi', :gender => :m, :locale => :uu)
387
+ a = [ :one, :two, :xmand ]
388
+ assert_equal a, I18n.t('welcomes.hi', :gender => :m, :locale => :xx, :inflector_interpolate_symbols => true)
389
+ a = [ :one, :two, :xd ]
390
+ assert_equal a, I18n.t('welcomes.hi', :gender => :m, :locale => :uu, :inflector_interpolate_symbols => true)
391
+ a = [ :one, :two, :"x@{m:man|woman}d" ]
392
+ assert_equal a, I18n.t('welcomes.hi', :gender => :m, :locale => :xx, :inflector_traverses => false, :inflector_interpolate_symbols => true)
393
+ a = [ :one, :two, :"x@{m:man|woman}d" ]
394
+ assert_equal a, I18n.t('welcomes.hi', :gender => :m, :locale => :uu, :inflector_traverses => false, :inflector_interpolate_symbols => true)
395
+ end
396
+
397
+ test "backend inflector translate: works with other types as results" do
398
+ store_translations(:xx, 'welcomes' => {'hi' => 31337})
399
+ assert_equal 31337, I18n.t('welcomes.hi', :gender => :m, :locale => :xx)
400
+ end
401
+
376
402
  test "backend inflector translate: works with negative tokens" do
377
403
  store_translations(:xx, 'hi' => 'Dear @{!m:Lady|m:Sir|n:You|All}!')
378
404
  assert_equal 'Dear Lady!', I18n.t('hi', :gender => :n, :locale => :xx)
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-inflector
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 2
7
- - 4
8
- - 0
9
- version: 2.4.0
4
+ prerelease:
5
+ version: 2.5.0
10
6
  platform: ruby
11
7
  authors:
12
8
  - "Pawe\xC5\x82 Wilk"
@@ -44,10 +40,6 @@ dependencies:
44
40
  requirements:
45
41
  - - ">="
46
42
  - !ruby/object:Gem::Version
47
- segments:
48
- - 0
49
- - 4
50
- - 1
51
43
  version: 0.4.1
52
44
  type: :runtime
53
45
  prerelease: false
@@ -59,10 +51,6 @@ dependencies:
59
51
  requirements:
60
52
  - - ">="
61
53
  - !ruby/object:Gem::Version
62
- segments:
63
- - 0
64
- - 1
65
- - 2
66
54
  version: 0.1.2
67
55
  type: :development
68
56
  prerelease: false
@@ -74,10 +62,6 @@ dependencies:
74
62
  requirements:
75
63
  - - ">="
76
64
  - !ruby/object:Gem::Version
77
- segments:
78
- - 0
79
- - 0
80
- - 4
81
65
  version: 0.0.4
82
66
  type: :development
83
67
  prerelease: false
@@ -89,10 +73,6 @@ dependencies:
89
73
  requirements:
90
74
  - - ">="
91
75
  - !ruby/object:Gem::Version
92
- segments:
93
- - 0
94
- - 6
95
- - 4
96
76
  version: 0.6.4
97
77
  type: :development
98
78
  prerelease: false
@@ -104,11 +84,7 @@ dependencies:
104
84
  requirements:
105
85
  - - ">="
106
86
  - !ruby/object:Gem::Version
107
- segments:
108
- - 1
109
- - 0
110
- - 7
111
- version: 1.0.7
87
+ version: 1.0.10
112
88
  type: :development
113
89
  prerelease: false
114
90
  version_requirements: *id005
@@ -119,10 +95,6 @@ dependencies:
119
95
  requirements:
120
96
  - - ">="
121
97
  - !ruby/object:Gem::Version
122
- segments:
123
- - 1
124
- - 0
125
- - 0
126
98
  version: 1.0.0
127
99
  type: :development
128
100
  prerelease: false
@@ -134,11 +106,7 @@ dependencies:
134
106
  requirements:
135
107
  - - ">="
136
108
  - !ruby/object:Gem::Version
137
- segments:
138
- - 2
139
- - 8
140
- - 0
141
- version: 2.8.0
109
+ version: 2.9.1
142
110
  type: :development
143
111
  prerelease: false
144
112
  version_requirements: *id007
@@ -186,7 +154,8 @@ files:
186
154
  - lib/i18n-inflector/version.rb
187
155
  - test/inflector_test.rb
188
156
  - test/test_helper.rb
189
- has_rdoc: yard
157
+ - .gemtest
158
+ has_rdoc: true
190
159
  homepage: https://rubygems.org/gems/i18n-inflector/
191
160
  licenses: []
192
161
 
@@ -202,7 +171,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
202
171
  requirements:
203
172
  - - ">="
204
173
  - !ruby/object:Gem::Version
205
- hash: -1561613972170107536
174
+ hash: -3056232506908455898
206
175
  segments:
207
176
  - 0
208
177
  version: "0"
@@ -211,13 +180,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
211
180
  requirements:
212
181
  - - ">="
213
182
  - !ruby/object:Gem::Version
214
- segments:
215
- - 0
216
183
  version: "0"
217
184
  requirements: []
218
185
 
219
186
  rubyforge_project: i18n-inflector
220
- rubygems_version: 1.3.7
187
+ rubygems_version: 1.5.2
221
188
  signing_key:
222
189
  specification_version: 3
223
190
  summary: Simple inflection module for I18n
metadata.gz.sig CHANGED
Binary file