i18n-inflector-3 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/docs/EXAMPLES ADDED
@@ -0,0 +1,357 @@
1
+
2
+ == Configuring inflections
3
+
4
+ This data will be used in any further example:
5
+
6
+ === YAML
7
+
8
+ en:
9
+ i18n:
10
+ inflections:
11
+
12
+ @person:
13
+ i: "i"
14
+ u: "you"
15
+ he: "he"
16
+ she: "she"
17
+ it: "it"
18
+ you: @u
19
+
20
+ gender:
21
+ m: "male"
22
+ f: "female"
23
+ n: "neuter"
24
+ default: n
25
+
26
+
27
+ welcome: "Dear @{f:Lady|m:Sir|n:You|All}!"
28
+ sayit: "@person{i:I|u:You|he:He|she:She|it:It}{ }{i:am|u:are|he,she,it:is}"
29
+ tobe: "%{person} @person{i:am|u:are|he,she,it:is}"
30
+
31
+
32
+ === Code
33
+
34
+ I18n.backend.store_translations(:en, :i18n => { :inflections => {
35
+ :gender => {
36
+ :m => 'male',
37
+ :f => 'female',
38
+ :n => 'neuter',
39
+ :default => :n
40
+ },
41
+ :@person => {
42
+ :i => 'i',
43
+ :u => 'you',
44
+ :he => 'he',
45
+ :she => 'she',
46
+ :it => 'it',
47
+ :you => :@u
48
+ }
49
+ }})
50
+
51
+ I18n.backend.store_translations(:en, 'welcome' => 'Dear @{f:Lady|m:Sir|n:You|All}!')
52
+ I18n.backend.store_translations(:en, 'sayit' => '@person{i:I|u:You|he:He|she:She|it:It}{ }{i:am|u:are|he,she,it:is}')
53
+ I18n.backend.store_translations(:en, 'tobe' => '%{person} @person{i:am|u:are|he,she,it:is}')
54
+ I18n.locale = :en
55
+
56
+ == Simple interpolation
57
+
58
+ When no option, it falls back to default token (n):
59
+
60
+ I18n.translate('welcome')
61
+ #=> "Dear You!"
62
+
63
+ When :m, it interpolates the m token's value:
64
+
65
+ I18n.translate('welcome', :gender => :m)
66
+ #=> "Dear Sir!"
67
+
68
+ When unknown, it falls back to default token (n):
69
+
70
+ I18n.translate('welcome', :gender => :unknown)
71
+ #=> "Dear You!"
72
+
73
+ When +nil+, it falls back to default token (n):
74
+
75
+ I18n.translate('welcome', :gender => nil)
76
+ #=> "Dear You!"
77
+
78
+ === <tt>inflector_unknown_defaults</tt>
79
+
80
+ When <tt>:inflector_unknown_defaults</tt> is false, it falls back to free text:
81
+
82
+ I18n.translate('welcome', :gender => :unknown, :inflector_unknown_defaults => false)
83
+ #=> "Dear All!"
84
+
85
+ It also falls back when an inflection option is nil or empty:
86
+
87
+ I18n.translate('welcome', :gender => nil, :inflector_unknown_defaults => false)
88
+ #=> "Dear All!"
89
+
90
+ == Named pattern
91
+
92
+ Regular inflection option will be used if there is no strict inflection option:
93
+
94
+ I18n.translate('sayit', :person => :i)
95
+ #=> "I am"
96
+
97
+ Strict inflection option has precedence:
98
+
99
+ I18n.translate('sayit', :person => :i, :@person => :u)
100
+ #=> "You are"
101
+
102
+
103
+ Strict inflection option has precedence even if the option's value is messy:
104
+
105
+ I18n.translate('sayit', :person => :i, :@person => :unknown)
106
+ #=> " "
107
+
108
+ === Using with interpolation argument
109
+
110
+ First part is interpolated using standard interpolation variable while
111
+ second part of the sentence comes from interpolation of inflection pattern.
112
+ The same option is feeding both engines.
113
+
114
+ I18n.translate('tobe', :person => :i)
115
+ #=> "i am"
116
+
117
+ Note funny thing. The interpolation variable +test+ takes value (+i+) from
118
+ +:person+ while option +:@person+ takes precedence when it comes to inflections.
119
+ Keep that in mind when combining regular interpolation variables with named patterns
120
+ while using the same variable for controlling both. Choose non-strict notation
121
+ for an option then.
122
+
123
+ I18n.translate('tobe', :person => :i, :@person => :u)
124
+ #=> "i are"
125
+
126
+ No free text in 'tobe' so the empty string is interpolated when strict kind is unknown:
127
+
128
+ I18n.translate('tobe', :person => :i, :@person => :unknown)
129
+ #=> "i "
130
+
131
+ == API
132
+
133
+ === Getting kinds
134
+
135
+ Getting all known regular kinds:
136
+
137
+ I18n.inflector.kinds
138
+ #=> [:gender]
139
+
140
+ Getting all known strict kinds:
141
+
142
+ I18n.inflector.strict.kinds
143
+ #=> [:person]
144
+
145
+ Getting all known kinds for language 'pl':
146
+
147
+ I18n.inflector.kinds(:pl)
148
+ #=> []
149
+
150
+ === Listing all known options
151
+
152
+ I18n.inflector.options.known
153
+ #=> [:inflector_cache_aware, :inflector_raises, :inflector_aliased_patterns,
154
+ # :inflector_unknown_defaults, :inflector_excluded_defaults]
155
+
156
+ == Real-life example for Polish language
157
+
158
+ Polish is highly inflected language. Additionally, position of a word in
159
+ a sentence is mutually coupled with meaning. That makes it extreemly
160
+ hard to create finite-state machine that would handle Polish grammar.
161
+ However, flection means that the same cores are combined with suffixes
162
+ and prefixes depending on many different kinds: gender, tense, form,
163
+ animation, declination and more. That makes Polish (and other Slavic
164
+ languages) alphabetically redundant. By interpolating common cores,
165
+ prefixes and suffixes of words we're able make our patterns compact.
166
+
167
+ === YAML
168
+
169
+ pl:
170
+ are_you_sure: "@{m,f:Jesteś pew}{m:ien|f:na}{n:Na pewno}?"
171
+
172
+ i18n:
173
+ inflections:
174
+ gender:
175
+ f: "rodzaj żeński"
176
+ m: "rodzaj męski"
177
+ n: "forma bezosobowa"
178
+ masculine: @m
179
+ facet: @m
180
+ chłopak: @m
181
+ feminine: @f
182
+ pani: @f
183
+ kobieta: @f
184
+ k: @f
185
+ dziewczyna: @f
186
+ impersonal: @n
187
+ default: n
188
+
189
+ === Code
190
+
191
+ # Using shorter form than listed as YAML
192
+
193
+ I18n.backend.store_translations(:pl, :i18n => { :inflections => { :gender =>
194
+ { :f => 'f', :m=>'m', :n=>'n', :kobieta=>:@f, :facet => :@m, :default=>:n }}})
195
+
196
+ # Making use of commas makes it easy to implement DRY
197
+ # and re-use some parts of the words that are the same in two or more phrases
198
+
199
+ I18n.backend.store_translations(:pl, :are_you_sure => "@{m,f:Jesteś pew}@{m:ien|f:na}@{n:Na pewno}?")
200
+
201
+ I18n.locale = :pl
202
+
203
+ I18n.translate('are_you_sure', :gender => :kobieta)
204
+ #=> "Jesteś pewna?"
205
+
206
+ I18n.translate('are_you_sure', :gender => :facet)
207
+ #=> "Jesteś pewien?"
208
+
209
+ I18n.translate('are_you_sure')
210
+ #=> "Na pewno?"
211
+
212
+ # It would look like that without commas:
213
+ I18n.backend.store_translations(:pl, :are_you_sure => "@{m:Jesteś pewien|f:Jesteś pewna|n:Na pewno}?")
214
+
215
+ # That would also work but it's less readable.
216
+ # PS: Have you ever configured Sendmail? ;-)
217
+ I18n.backend.store_translations(:pl, :are_you_sure => "@{n:Na|m,f:Jesteś}{ pew}{m:ie}{n}{f:a|n:o}?")
218
+
219
+ === Complex pattern usage
220
+
221
+ # Store needed translations
222
+ I18n.backend.store_translations(:pl,
223
+ :i18n => { :inflections => {
224
+ :@gender =>
225
+ { :f => 'f', :m => 'm', :n => 'n',
226
+ :kobieta => :@f, :facet => :@m, :default => :n },
227
+ :@tense =>
228
+ { :t => 'teraz', :w => 'przeszły', :j => 'przyszły',
229
+ :teraz => :@t, :wczoraj => :@w, :jutro => :@j,
230
+ :default => :t }
231
+ }})
232
+
233
+ I18n.backend.store_translations(:pl,
234
+ :msg_receive => "@gender+tense{n+w:Otrzymano|Dosta}{*+t:jesz|*+j:niesz|f+w:łaś|m+w:łeś} wiadomość")
235
+
236
+ I18n.locale = :pl
237
+
238
+ p I18n.translate('msg_receive', :gender => :kobieta)
239
+ #=> "Dostajesz wiadomość"
240
+
241
+ p I18n.translate('msg_receive', :gender => :facet)
242
+ #=> "Dostajesz wiadomość"
243
+
244
+ p I18n.translate('msg_receive')
245
+ #=> "Dostajesz wiadomość"
246
+
247
+ p I18n.translate('msg_receive', :gender => :kobieta, :tense => :wczoraj)
248
+ #=> "Dostałaś wiadomość"
249
+
250
+ p I18n.translate('msg_receive', :gender => :facet, :tense => :wczoraj)
251
+ #=> "Dostałeś wiadomość"
252
+
253
+ p I18n.translate('msg_receive', :tense => :jutro)
254
+ #=> "Dostaniesz wiadomość"
255
+
256
+ p I18n.translate('msg_receive', :tense => :wczoraj)
257
+ #=> "Otrzymano wiadomość"
258
+
259
+ ==== YAML for the example above
260
+
261
+ The example above may use this YAML content instead of +store_translations+:
262
+
263
+ pl:
264
+ msg_receive: "@gender+tense{n+w:Otrzymano|Dosta}{*+t:jesz|*+j:niesz|f+w:łaś|m+w:łeś} wiadomość"
265
+
266
+ i18n:
267
+ inflections:
268
+ @gender:
269
+ m: 'male'
270
+ f: 'female'
271
+ n: 'neuter'
272
+ kobieta: @f
273
+ facet: @m
274
+ default: n
275
+ @tense:
276
+ t: 'teraźniejszy'
277
+ w: 'przeszły'
278
+ j: 'przyszły'
279
+ teraz: @t
280
+ wczoraj: @w
281
+ jutro: @j
282
+ default: @t
283
+
284
+ ===== Alternative for +msg_receive+ key
285
+
286
+ The +msg_receive+ might also be expressed using two infleciton keys:
287
+
288
+ pl:
289
+ @msg_receive_1:
290
+ @kind: gender+tense
291
+ @free: 'Dosta'
292
+ n+w: 'Otrzymano'
293
+
294
+ @msg_receive_2:
295
+ @kind: gender+tense
296
+ @suffix: " wiadomość"
297
+ m,f,n+t: "jesz"
298
+ m,f,n+j: "niesz"
299
+ f+w: "łaś"
300
+ m+w: "łeś"
301
+
302
+ But then you have to change the translation call too, e.g.:
303
+
304
+ p I18n.translate(['@msg_receive_1','@msg_receive_2'], :gender => :kobieta).join
305
+ #=> "Dostajesz wiadomość"
306
+
307
+ The split is necessary because we have two patterns here and no way to express them
308
+ as one inflection key.
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
+
356
+ <i>to be continued…</i>
357
+
data/docs/HISTORY ADDED
@@ -0,0 +1,280 @@
1
+ === 3.0.0 / 2025-11-30
2
+
3
+ * major compatibility fixes
4
+
5
+ * Ruby 4.0.0-preview2 compatibility: Fixed HSet to use public Set API (include?) instead of internal @hash
6
+ * Ruby 3.4+ compatibility: Fixed frozen string literal issues
7
+
8
+ * major enhancements
9
+
10
+ * Migrated from Hoe to Bundler build system
11
+ * Migrated tests from Test::Unit to Minitest
12
+ * Updated gemspec with modern Ruby requirements (>= 3.4)
13
+
14
+ === 2.6.7 / 2013-06-18
15
+
16
+ * major compatibility fixes
17
+
18
+ * Removed deprecation warnings for Ruby 2.0
19
+
20
+ * minor enhancements
21
+
22
+ * Updated gem dependencies
23
+
24
+ === 2.6.6 / 2012-03-14
25
+
26
+ * major enhancements
27
+
28
+ * Added support for integers as token names
29
+ * Added nice example of "to be" inflection in English
30
+
31
+ * minor enhancements
32
+
33
+ * Documentation updated
34
+ * Added instance method empty? to LazyEnumerator
35
+
36
+ === 2.6.5 / 2012-03-10
37
+
38
+ * minor enhancements
39
+
40
+ * Back to Psych YAML parser while creating gem
41
+
42
+ === 2.6.4 / 2012-03-10
43
+
44
+ * minor enhancements
45
+
46
+ * Changed documentation examples for calling rake
47
+ * Tested against Ruby 1.9.3-p0
48
+ * Updated dependencies
49
+ * Updated copyright notices
50
+ * Started codenaming each version (including minor version numbers)
51
+
52
+ === 2.6.2 / 2011-08-07
53
+
54
+ * minor bugfixes
55
+
56
+ * Applied a workaround against a buggy parser in Rubygems
57
+
58
+ === 2.6.1 / 2011-07-10
59
+
60
+ * major enhancements
61
+
62
+ * Handling of methods and Proc objects used to obtain inflection options improved by caching
63
+ * Added caching for methods reporting locales that support inflection
64
+ * Lazy operations optimized
65
+
66
+ * minor enhancements
67
+
68
+ * Fixed documentation links
69
+ * Dependencies updated
70
+
71
+ === 2.6.0 / 2011-03-08
72
+
73
+ * minor enhancements
74
+
75
+ * Strings concatenation optimized
76
+ * API methods simplified
77
+ * Added lazy iteration methods to I18n::Inflector::InflectionData and I18n::Inflector::InflectionData_Strict
78
+ * Added lazy iteration methods to I18n::Inflector::API and I18n::Inflector::API_Strict
79
+
80
+ === 2.5.1 / 2011-02-25
81
+
82
+ * minor enhancements
83
+
84
+ * Added the ability to use symbols as descriptions (values) in a configuration
85
+
86
+ === 2.5.0 / 2011-02-24
87
+
88
+ * major enhancements
89
+
90
+ * Interpolation wrapper refactored; works with many types of results
91
+ * Added :inflector_interpolate_symbols switch
92
+
93
+ * minor enhancements
94
+
95
+ * Added TOKENS_RESTR, MULTI_RESTR and PATTERN_RESTR configuration constants
96
+ * Dependencies updated
97
+
98
+ * major bugfixes
99
+
100
+ * Fixed interpolation of Arrays
101
+
102
+ * minor bugfixes
103
+
104
+ * Fixed pattern filtering when locale is invalid or not inflected
105
+
106
+ === 2.4.0 / 2011-02-23
107
+
108
+ * major enhancements
109
+
110
+ * Added nested translations (collections) support
111
+ * Added :inflector_traverses switch
112
+
113
+ === 2.3.1 / 2011-02-14
114
+
115
+ * major enhancements
116
+
117
+ * Added wildcard tokens support
118
+ * Proc and Method kind of objects might be passed as inflection options
119
+
120
+ * minor enhancements
121
+
122
+ * Added I18n::Inflector::Config::Markers::STRICT_KIND (character used when passing strict kinds)
123
+ * Important documentation moved to the USAGE file
124
+
125
+ * minor bugfixes
126
+
127
+ * Fixed parsing of named patterns when :inflector_excluded_defaults is used
128
+ * Fixed links in documentation
129
+
130
+ === 2.2.0 / 2011-02-09
131
+
132
+ * major enhancements
133
+
134
+ * Added loud tokens support
135
+ * Added complex patterns support
136
+ * Added key-based inflection support
137
+ * Added :cache_aware switch
138
+ * Improved validation of token and kind identifiers
139
+
140
+ * minor enhancements
141
+
142
+ * Refactored error reporting code
143
+ * Refactored options gathering code
144
+ * Removed magic symbols and strings
145
+ * Removed intermediate array from LazyHashEnumerator#to_h
146
+ * Added multiple patterns support (syntactic sugar)
147
+ * Added I18n::Inflector::Config module
148
+ * Added I18n::Inflector::LazyArrayEnumerator class
149
+ * Added I18n::Inflector::HSet class for keeping collections of data
150
+ * Added error classes: I18n::InvalidInflectionOption and I18n::InvalidInflectionKind
151
+ * Interpolation method moved to I18n::Inflector::Interpolate module
152
+ * All inflection related exceptions now have the attribute "key" containing key name
153
+
154
+ * major bugfixes
155
+
156
+ * Fixed handling of missing inflection option when :inflector_raises is set
157
+
158
+ * minor bugfixes
159
+
160
+ * Fixed interpolation when :excluded_defaults is on and a kind is strict
161
+ * Fixed interpolation when pattern is escaped and locale is not inflected
162
+ * Enabled filtering of reserved names in options
163
+ * Enabled filtering of inflection options for options that go to original translate method
164
+ * Updated documentation in a section describing options
165
+ * Fixed some examples
166
+
167
+ === 2.1.0 / 2011-01-27
168
+
169
+ * major enhancements
170
+
171
+ * Added named patterns support (strict kinds)
172
+ * API improved: major class is I18n::Inflector::API
173
+ * Added class I18n::Inflector::API_Strict for accessing strict inflections
174
+ * Added lazy enumerators for internal hashes, which saves some memory
175
+ * Added strict kinds detection (@-style kind names) to most of the methods from main API class
176
+ * Added new error classes: InflectionOptionNotFound and InflectionOptionIncorrect
177
+ * Added class for handling inflection data for strict kinds: I18n::Inflector::InflectionData_Strict
178
+ * Inflections for regular and strict kinds are handled by separate data structures and objects
179
+ * Documentation updated
180
+
181
+ * minor bugfixes
182
+
183
+ * Error reporting fixed in some places
184
+ * Strict kinds interpolation improved
185
+ * Removed some slow blocks
186
+ * Loading inflection tokens cleaned up
187
+
188
+ === 2.0.1 / 2011-01-15
189
+
190
+ * minor enhancements
191
+
192
+ * Documentation updated
193
+
194
+ * minor bugfixes
195
+
196
+ * Fixed duplicated dependency generation in Hoe
197
+
198
+ === 2.0.0 / 2011-01-14
199
+
200
+ * major enhancements
201
+
202
+ * API changed
203
+ * Added a class for keeping internal inflection data: I18n::Inflector::InflectionData
204
+ * Added a class for keeping options: I18n::Inflector::InflectionOptions
205
+ * Added a class for controlling the inflection: I18n::Inflector::Core
206
+ * Added a module for utilities: I18n::Inflector::Util
207
+ * Added token groups support
208
+ * Added inversed matching of tokens in inflection patterns
209
+ * Added support for aliases in inflection patterns
210
+ * Most of the methods from I18n::Backend::Inflector moved to Core submodule
211
+ * Most methods rewritten
212
+
213
+ === 1.0.10 / 2011-01-10
214
+
215
+ * major bugfixes
216
+
217
+ * Removed cause of infinite loops while initializing translations
218
+ * Disabled lookup from being used before translations are initialized
219
+ * Fixed initialization routine (dangerous typo when setting booleans)
220
+
221
+ * minor enhancements
222
+
223
+ * Switched to lazy loading of inflection data for certain locales
224
+
225
+ === 1.0.8 / 2011-01-08
226
+
227
+ * major enhancements
228
+
229
+ * Enabled escaping of patterns using @@{pattern} or \@{pattern}
230
+
231
+ === 1.0.7 / 2011-01-07
232
+
233
+ * major bugfixes
234
+
235
+ * Fixed interpolation when a translated string begins with a pattern
236
+
237
+ === 1.0.6 / 2010-12-30
238
+
239
+ * minor enhancements
240
+
241
+ * Added API method inflection_kind(token)
242
+ * Added API method inflection_true_token(token)
243
+ * Added API method inflected_locale(locale)
244
+
245
+ === 1.0.5 / 2010-12-29
246
+
247
+ * major enhancements
248
+
249
+ * Compatible with i18n >= 0.4.1
250
+
251
+ === 1.0.4 / 2010-12-27
252
+
253
+ * minor enhancements
254
+
255
+ * Documentation updated
256
+
257
+ === 1.0.3 / 2010-12-25
258
+
259
+ * major enhancements
260
+
261
+ * YARD documentation updated with metatags
262
+
263
+ * minor enhancements
264
+
265
+ * Some changes in accessors for interpolation switches
266
+
267
+ === 1.0.2 / 2010-12-22
268
+
269
+ * minor enhancements
270
+
271
+ * Switched to YARD documentation
272
+ * Tests simplified
273
+ * Depandencies simplified
274
+
275
+ === 1.0.0 / 2010-12-22
276
+
277
+ * 1 major enhancement
278
+
279
+ * Birthday!
280
+
data/docs/LEGAL ADDED
@@ -0,0 +1,10 @@
1
+ LEGAL NOTICE INFORMATION
2
+ ------------------------
3
+
4
+ i18n-inflector is Copyright (C) 2011,2012 by Paweł Wilk.
5
+
6
+ i18n-inflector is copyrighted software owned by Paweł Wilk
7
+ (pw@gnu.org). You may redistribute and/or modify this
8
+ software as long as you comply with either the terms of the LGPL
9
+ (see the file {file:docs/LGPL}),
10
+ or Ruby's license (see the file {file:docs/COPYING}).