i18n-inflector 2.6.5 → 2.6.6

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
data/ChangeLog CHANGED
@@ -1,3 +1,27 @@
1
+ commit c0bcc1dd60256076d9ac79d6f57d11d6a578f3ee
2
+ Author: Paweł Wilk <siefca@gnu.org>
3
+ Date: Wed Mar 14 02:10:49 2012 +0100
4
+
5
+ Release 2.6.6
6
+
7
+ commit 3d2292b4dec50c628fc2feaeba2639e21c44c5c7
8
+ Author: Paweł Wilk <siefca@gnu.org>
9
+ Date: Wed Mar 14 02:06:50 2012 +0100
10
+
11
+ Added LazyEnumerator#empty?
12
+
13
+ commit f912309d9f9d0d2e41c901778f885259f907e8ef
14
+ Author: Paweł Wilk <siefca@gnu.org>
15
+ Date: Wed Mar 14 02:06:29 2012 +0100
16
+
17
+ Documentation and examples updated
18
+
19
+ commit 7d5f57ec1ff967051e693b332c0e72f9bbbbea2a
20
+ Author: Paweł Wilk <siefca@gnu.org>
21
+ Date: Wed Mar 14 02:06:04 2012 +0100
22
+
23
+ Added support for integers as token names
24
+
1
25
  commit d08273f935a3fecc51e4ce27a3ebe01342a338f3
2
26
  Author: Paweł Wilk <siefca@gnu.org>
3
27
  Date: Sat Mar 10 21:03:04 2012 +0100
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
- = Simple Inflector for I18n
1
+ = I18n Inflector
2
2
 
3
- <b>i18n-inflector version <tt>2.6.5</tt></b> (<b><tt>Healthy Beaver</tt></b>)
3
+ <b>i18n-inflector version <tt>2.6.6</tt></b> (<b><tt>Little Kózka</tt></b>)
4
4
 
5
5
 
6
6
  * https://rubygems.org/gems/i18n-inflector
@@ -8,6 +8,56 @@
8
8
  * mailto:pw@gnu.org
9
9
 
10
10
 
11
+ == Summary
12
+
13
+ This library contains a backend module for I18n that adds some extra
14
+ functionality to standard backend. It overwrites the translate method
15
+ in a way that it will interpolate additional inflection tokens present
16
+ in translations.
17
+
18
+ == Synopsis
19
+
20
+ require 'i18n-inflector'
21
+
22
+ I18n.translate( 'to_be', :number => :singular,
23
+ :tense => :past,
24
+ :person => 2 )
25
+ #=> You were here
26
+
27
+ I18n.translate('welcome', :gender => :female)
28
+ #=> Dear Lady
29
+
30
+ == Why?
31
+
32
+ You can use I18n Inflector to (relatively easy) create
33
+ translations for highly inflected languages (like those
34
+ belonging to Slavic language family). You can also use it
35
+ in translation services that may operate on sentences
36
+ instead of exact words.
37
+
38
+ == When?
39
+
40
+ It is intended to be used in a web projects or other projects where
41
+ translations are performed by many people, yet there is a need to
42
+ inflect sentences with some external variables. To achieve similar
43
+ functionality lambdas can be used but including many Proc objects
44
+ might be considered unsafe or memory consuming.
45
+
46
+ See i18n-inflector-rails[https://rubygems.org/gems/i18n-inflector-rails] if
47
+ you need Rails integration.
48
+
49
+ == How?
50
+
51
+ I18n Inflector lets you build you own inflection patterns
52
+ contained in translation entries. The patterns may contain simple
53
+ conditions and tokens, which combined with parameters
54
+ passed to +I18n.translate+ method can produce inflected
55
+ strings.
56
+
57
+ * See {USAGE}[http://rubydoc.info/gems/i18n-inflector/file/docs/USAGE] for detailed information about the usage.
58
+ * See {EXAMPLES}[http://rubydoc.info/gems/i18n-inflector/file/docs/EXAMPLES] for examples.
59
+ * See {whole documentation}[http://rubydoc.info/gems/i18n-inflector/] to browse all documents.
60
+
11
61
  == Features
12
62
 
13
63
  * Inline inflection using patterns in translation data.
@@ -21,9 +71,8 @@
21
71
 
22
72
  == Description
23
73
 
24
- This library contains a backend module for I18n that adds some extra
25
- functionality to standard backend. It overwrites the translate method
26
- so that it will interpolate additional inflection tokens present in
74
+ The I18n Inflector extends the translate method from I18n in a way that
75
+ it will interpolate additional inflection tokens present in
27
76
  translations. These tokens may appear in *patterns* which are contained
28
77
  within <tt>@{</tt> and <tt>}</tt> symbols. Configuration is stored
29
78
  also in translation data, in a scope <tt><locale>.i18n.inflections</tt>,
@@ -38,7 +87,9 @@ It adds the +inflector+ object to the default backend so you can use many
38
87
  methods for accessing loaded inflection data at runtime, or to set up global
39
88
  switches that are controlling the engine.
40
89
 
41
- Example translation data:
90
+ == Short example
91
+
92
+ Example configuration which uses translation data:
42
93
 
43
94
  en:
44
95
  i18n:
@@ -51,7 +102,10 @@ Example translation data:
51
102
  male: @m
52
103
  default: n
53
104
 
54
-
105
+
106
+ Example translation data:
107
+
108
+ en:
55
109
  welcome: "Dear @{f:Lady|m:Sir|n:You|All}!"
56
110
 
57
111
  @same_but_as_key:
@@ -61,7 +115,8 @@ Example translation data:
61
115
  @prefix: "Dear "
62
116
  @suffix: "!"
63
117
  @free: "All"
64
-
118
+
119
+
65
120
  === Note about YAML parsing
66
121
 
67
122
  The example above is not compatible with Psych parser, which is used
@@ -101,23 +156,6 @@ languages. An example pattern:
101
156
 
102
157
  welcome: "Dear @gender+number{f+s:Lady|f+p:Ladies|m+s:Sir|m+p:Gentlemen|All}"
103
158
 
104
- == Why?
105
-
106
- It's intended to be used in a web projects or other projects where
107
- translations are performed by many people, yet there is a need to
108
- inflect sentences with some external variables.
109
-
110
- To achieve similar functionality lambdas can be used but including
111
- Proc objects in translations might be considered unsafe or memory
112
- consuming.
113
-
114
- If you have a troop of happy translators that shouldn't have the
115
- ability to execute any code yet you need some simple inflection
116
- then this module might help you.
117
-
118
- See i18n-inflector-rails[https://rubygems.org/gems/i18n-inflector-rails] if
119
- you need Rails integration.
120
-
121
159
  == Requirements
122
160
 
123
161
  * i18n[https://rubygems.org/gems/i18n]
@@ -125,11 +163,6 @@ you need Rails integration.
125
163
  * rubygems[http://docs.rubygems.org/]
126
164
  * bundler[http://gembundler.com/]
127
165
 
128
- == Important documentation and more on usage
129
-
130
- * See {file:docs/USAGE} for detailed information about the usage.
131
- * See {whole documentation}[http://rubydoc.info/gems/i18n-inflector/] to browse all documents.
132
-
133
166
  == Download
134
167
 
135
168
  ==== Source code
@@ -145,12 +178,7 @@ you need Rails integration.
145
178
 
146
179
  * <tt>gem install i18n-inflector</tt>
147
180
 
148
- == Synopsis
149
-
150
- require 'i18n-inflector'
151
- i18n.translate('welcome')
152
-
153
- Detailed example:
181
+ == Detailed example
154
182
 
155
183
  <b>YAML:</b>
156
184
 
data/docs/EXAMPLES CHANGED
@@ -307,5 +307,51 @@ But then you have to change the translation call too, e.g.:
307
307
  The split is necessary because we have two patterns here and no way to express them
308
308
  as one inflection key.
309
309
 
310
+ == To be or not to be
311
+
312
+ Here is the example pattern that inflects English <i>to be</i> by tense,
313
+ person and grammatical number:
314
+
315
+ en:
316
+ i18n:
317
+ inflections:
318
+ @person:
319
+ 1: first
320
+ 2: second
321
+ 3: third
322
+ i: :@1
323
+ you: :@2
324
+ He: :@3
325
+ She: :@3
326
+ it: :@3
327
+ @tense:
328
+ past: past
329
+ present: present
330
+ now: @present
331
+ default: present
332
+ @num:
333
+ s: singular
334
+ p: plural
335
+ default: s
336
+
337
+ to_be: >
338
+ @num+person{s+1:I|*+2:You|s+3:%{person}|p+3:They|p+1:We}
339
+ @num+person+tense{s+1+present:am|s+2+present:are|s+3+present:is|
340
+ p+*+present:are|s+1,3+past:was|p+*+past:were|s+2+past:were}
341
+
342
+ And the code that prints all possible combinations:
343
+
344
+ [:i, :you, :He, :She, :It].each do |person|
345
+ puts I18n.translate(:to_be, :num => :s, :person => person, :tense => :now) + "\t| " +
346
+ I18n.translate(:to_be, :num => :s, :person => person, :tense => :past)
347
+ end
348
+
349
+ puts
350
+
351
+ (1..3).each do |person|
352
+ puts I18n.translate(:to_be, :num => :p, :person => person, :tense => :now) + " | " +
353
+ I18n.translate(:to_be, :num => :p, :person => person, :tense => :past)
354
+ end
355
+
310
356
  <i>to be continued…</i>
311
357
 
data/docs/HISTORY CHANGED
@@ -1,3 +1,15 @@
1
+ === 2.6.6 / 2012-03-14
2
+
3
+ * major enhancements
4
+
5
+ * Added support for integers as token names
6
+ * Added nice example of "to be" inflection in English
7
+
8
+ * minor enhancements
9
+
10
+ * Documentation updated
11
+ * Added instance method empty? to LazyEnumerator
12
+
1
13
  === 2.6.5 / 2012-03-10
2
14
 
3
15
  * minor enhancements
data/docs/USAGE CHANGED
@@ -513,7 +513,7 @@ Elements in the example above are:
513
513
  * +en+: language
514
514
  * +i18n+: configuration scope
515
515
  * +inflections+: inflections configuration scope
516
- * +gender+: <bb>strict kind</bb> scope
516
+ * +gender+: <b>strict kind</b> scope
517
517
  * +f+: inflection token
518
518
  * <tt>"female"</tt>: token's description
519
519
  * +woman+: inflection alias
@@ -630,7 +630,7 @@ containing no tokens but just a free text consisting
630
630
  of single space character.
631
631
 
632
632
  == Complex patterns
633
- A <bb>complex pattern</bb> is a named pattern that uses more than
633
+ A <b>complex pattern</b> is a named pattern that uses more than
634
634
  one inflection kind and sets of a respective tokens. The given identifiers
635
635
  of kinds should be separated by the plus sign and instead of single
636
636
  tokens there should be token sets (a tokens separated by the plus
@@ -247,6 +247,7 @@ module I18n
247
247
  def load_inflection_tokens(locale, subtree=nil)
248
248
  inflections_tree = subtree || inflection_subtree(locale)
249
249
  return nil if (inflections_tree.nil? || inflections_tree.empty?)
250
+ inflections_tree = deep_symbolize(inflections_tree)
250
251
 
251
252
  idb = I18n::Inflector::InflectionData.new(locale)
252
253
  idb_strict = I18n::Inflector::InflectionData_Strict.new(locale)
@@ -255,6 +256,7 @@ module I18n
255
256
 
256
257
  inflections = prepare_inflections(locale, inflections_tree, idb, idb_strict)
257
258
 
259
+ # add inflection tokens and kinds to internal database
258
260
  inflections.each do |orig_kind, kind, strict_kind, subdb, tokens|
259
261
 
260
262
  # validate token's kind
@@ -345,6 +347,16 @@ module I18n
345
347
  end
346
348
  end
347
349
 
350
+ # @private
351
+ def deep_symbolize(obj)
352
+ obj.inject({}) do |result, (key, value)|
353
+ value = deep_symbolize(value) if value.is_a?(Hash)
354
+ result[(key.to_s.to_sym rescue key) || key] = value
355
+ result
356
+ end
357
+ end
358
+
359
+
348
360
  end # module Inflector
349
361
  end # module Backend
350
362
  end # module I18n
@@ -57,7 +57,8 @@ module I18n
57
57
 
58
58
  # All keys
59
59
  ALL = HSet.new Config.all_consts(self, Symbol)
60
- end
60
+
61
+ end # module Keys
61
62
 
62
63
  # This module contains characters that are markers
63
64
  # giving the shape for a pattern and its elements.
@@ -353,7 +353,7 @@ module I18n
353
353
 
354
354
  # resolve token from options and check if it's known
355
355
  unless passed_token.nil?
356
- passed_token = subdb.get_true_token(passed_token.to_sym, parsed_kind)
356
+ passed_token = subdb.get_true_token(passed_token.to_s.to_sym, parsed_kind)
357
357
  passed_token = default_token if passed_token.nil? && unknown_defaults
358
358
  end
359
359
 
@@ -128,6 +128,17 @@ module I18n
128
128
  end
129
129
  end
130
130
 
131
+ # Checks if a collection is empty
132
+ # @return [Boolean] +true+ if collection is empty, +false+ otherwise
133
+ def empty?
134
+ self.class.new do |yielder|
135
+ each do |k,v|
136
+ return false
137
+ end
138
+ end
139
+ true
140
+ end
141
+
131
142
  end
132
143
 
133
144
  # This class implements simple enumerators for arrays
@@ -14,7 +14,7 @@ module I18n
14
14
  # @private
15
15
  EMAIL = 'pw@gnu.org'
16
16
  # @private
17
- VERSION = '2.6.5'
17
+ VERSION = '2.6.6'
18
18
  # @private
19
19
  NAME = 'i18n-inflector'
20
20
  # @private
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-inflector
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.5
4
+ version: 2.6.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -48,11 +48,11 @@ cert_chain:
48
48
  -----END CERTIFICATE-----
49
49
 
50
50
  '
51
- date: 2012-03-10 00:00:00.000000000 Z
51
+ date: 2012-03-14 00:00:00.000000000 Z
52
52
  dependencies:
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: i18n
55
- requirement: &2161409560 !ruby/object:Gem::Requirement
55
+ requirement: &2161408440 !ruby/object:Gem::Requirement
56
56
  none: false
57
57
  requirements:
58
58
  - - ! '>='
@@ -60,10 +60,10 @@ dependencies:
60
60
  version: 0.4.1
61
61
  type: :runtime
62
62
  prerelease: false
63
- version_requirements: *2161409560
63
+ version_requirements: *2161408440
64
64
  - !ruby/object:Gem::Dependency
65
65
  name: hoe-yard
66
- requirement: &2161408900 !ruby/object:Gem::Requirement
66
+ requirement: &2161407820 !ruby/object:Gem::Requirement
67
67
  none: false
68
68
  requirements:
69
69
  - - ! '>='
@@ -71,10 +71,10 @@ dependencies:
71
71
  version: 0.1.2
72
72
  type: :development
73
73
  prerelease: false
74
- version_requirements: *2161408900
74
+ version_requirements: *2161407820
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: test_declarative
77
- requirement: &2161408400 !ruby/object:Gem::Requirement
77
+ requirement: &2161407160 !ruby/object:Gem::Requirement
78
78
  none: false
79
79
  requirements:
80
80
  - - ! '>='
@@ -82,10 +82,10 @@ dependencies:
82
82
  version: 0.0.5
83
83
  type: :development
84
84
  prerelease: false
85
- version_requirements: *2161408400
85
+ version_requirements: *2161407160
86
86
  - !ruby/object:Gem::Dependency
87
87
  name: yard
88
- requirement: &2161407740 !ruby/object:Gem::Requirement
88
+ requirement: &2161406440 !ruby/object:Gem::Requirement
89
89
  none: false
90
90
  requirements:
91
91
  - - ! '>='
@@ -93,10 +93,10 @@ dependencies:
93
93
  version: 0.7.2
94
94
  type: :development
95
95
  prerelease: false
96
- version_requirements: *2161407740
96
+ version_requirements: *2161406440
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rdoc
99
- requirement: &2161407020 !ruby/object:Gem::Requirement
99
+ requirement: &2161405660 !ruby/object:Gem::Requirement
100
100
  none: false
101
101
  requirements:
102
102
  - - ! '>='
@@ -104,10 +104,10 @@ dependencies:
104
104
  version: 3.8.0
105
105
  type: :development
106
106
  prerelease: false
107
- version_requirements: *2161407020
107
+ version_requirements: *2161405660
108
108
  - !ruby/object:Gem::Dependency
109
109
  name: bundler
110
- requirement: &2161406460 !ruby/object:Gem::Requirement
110
+ requirement: &2161405020 !ruby/object:Gem::Requirement
111
111
  none: false
112
112
  requirements:
113
113
  - - ! '>='
@@ -115,10 +115,10 @@ dependencies:
115
115
  version: 1.0.15
116
116
  type: :development
117
117
  prerelease: false
118
- version_requirements: *2161406460
118
+ version_requirements: *2161405020
119
119
  - !ruby/object:Gem::Dependency
120
120
  name: hoe-bundler
121
- requirement: &2161405700 !ruby/object:Gem::Requirement
121
+ requirement: &2161404300 !ruby/object:Gem::Requirement
122
122
  none: false
123
123
  requirements:
124
124
  - - ! '>='
@@ -126,10 +126,10 @@ dependencies:
126
126
  version: 1.1.0
127
127
  type: :development
128
128
  prerelease: false
129
- version_requirements: *2161405700
129
+ version_requirements: *2161404300
130
130
  - !ruby/object:Gem::Dependency
131
131
  name: hoe
132
- requirement: &2161405100 !ruby/object:Gem::Requirement
132
+ requirement: &2161403320 !ruby/object:Gem::Requirement
133
133
  none: false
134
134
  requirements:
135
135
  - - ~>
@@ -137,7 +137,7 @@ dependencies:
137
137
  version: '2.16'
138
138
  type: :development
139
139
  prerelease: false
140
- version_requirements: *2161405100
140
+ version_requirements: *2161403320
141
141
  description: Enhances simple I18n backend in a way that it inflects translation data
142
142
  using pattern interpolation.
143
143
  email:
@@ -202,7 +202,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
202
202
  version: '0'
203
203
  segments:
204
204
  - 0
205
- hash: 4537310741031489808
205
+ hash: -404233212743185379
206
206
  required_rubygems_version: !ruby/object:Gem::Requirement
207
207
  none: false
208
208
  requirements:
metadata.gz.sig CHANGED
Binary file