i18n-inflector 2.5.1 → 2.6.1
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.tar.gz.sig +0 -0
- data/ChangeLog +80 -0
- data/Gemfile +8 -5
- data/Gemfile.lock +27 -0
- data/Manifest.txt +2 -0
- data/README.rdoc +27 -1
- data/Rakefile +14 -4
- data/ci/i18n-inflector.gemspec +7 -6
- data/ci/i18nv4-Gemfile +1 -1
- data/ci/i18nv4-Gemfile.lock +25 -0
- data/docs/HISTORY +22 -0
- data/docs/TODO +2 -1
- data/docs/USAGE +28 -0
- data/lib/i18n-inflector/api.rb +111 -107
- data/lib/i18n-inflector/api_strict.rb +164 -21
- data/lib/i18n-inflector/backend.rb +10 -7
- data/lib/i18n-inflector/config.rb +19 -19
- data/lib/i18n-inflector/errors.rb +13 -13
- data/lib/i18n-inflector/hset.rb +1 -1
- data/lib/i18n-inflector/inflection_data.rb +52 -59
- data/lib/i18n-inflector/inflection_data_strict.rb +49 -40
- data/lib/i18n-inflector/inflector.rb +3 -3
- data/lib/i18n-inflector/interpolate.rb +68 -37
- data/lib/i18n-inflector/lazy_enum.rb +119 -32
- data/lib/i18n-inflector/long_comments.rb +1 -1
- data/lib/i18n-inflector/options.rb +3 -3
- data/lib/i18n-inflector/version.rb +2 -2
- metadata +38 -27
- metadata.gz.sig +0 -0
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# Author:: Paweł Wilk (mailto:pw@gnu.org)
|
4
4
|
# Copyright:: (c) 2011 by Paweł Wilk
|
5
|
-
# License:: This program is licensed under the terms of {file:docs/LGPL GNU Lesser General Public License} or {file:COPYING Ruby License}.
|
5
|
+
# License:: This program is licensed under the terms of {file:docs/LGPL GNU Lesser General Public License} or {file:docs/COPYING Ruby License}.
|
6
6
|
#
|
7
7
|
# This file contains I18n::Inflector::API_Strict class,
|
8
8
|
# which handles public API for managing inflection data
|
@@ -57,6 +57,8 @@ module I18n
|
|
57
57
|
def initialize(idb=nil, options=nil)
|
58
58
|
@idb = idb.nil? ? {} : idb
|
59
59
|
@options = options.nil? ? I18n::Inflector::InflectionOptions.new : options
|
60
|
+
@lazy_locales = LazyHashEnumerator.new(@idb)
|
61
|
+
@inflected_locales_cache = Hash.new
|
60
62
|
end
|
61
63
|
|
62
64
|
# Creates an empty strict inflections database for the specified locale.
|
@@ -69,6 +71,7 @@ module I18n
|
|
69
71
|
# inflection data
|
70
72
|
def new_database(locale)
|
71
73
|
locale = prep_locale(locale)
|
74
|
+
@inflected_locales_cache.clear
|
72
75
|
@idb[locale] = I18n::Inflector::InflectionData_Strict.new(locale)
|
73
76
|
end
|
74
77
|
|
@@ -85,6 +88,7 @@ module I18n
|
|
85
88
|
return nil if db.nil?
|
86
89
|
locale = prep_locale(db.locale)
|
87
90
|
delete_database(locale)
|
91
|
+
@inflected_locales_cache.clear
|
88
92
|
@idb[locale] = db
|
89
93
|
end
|
90
94
|
|
@@ -99,6 +103,7 @@ module I18n
|
|
99
103
|
def delete_database(locale)
|
100
104
|
locale = prep_locale(locale)
|
101
105
|
return nil if @idb[locale].nil?
|
106
|
+
@inflected_locales_cache.clear
|
102
107
|
@idb[locale] = nil
|
103
108
|
end
|
104
109
|
|
@@ -120,6 +125,29 @@ module I18n
|
|
120
125
|
alias_method :locale?, :inflected_locale?
|
121
126
|
alias_method :locale_supported?, :inflected_locale?
|
122
127
|
|
128
|
+
# Iterates through locales which have configured strict inflection support.
|
129
|
+
#
|
130
|
+
# @api public
|
131
|
+
# @return [LazyArrayEnumerator] the lazy enumerator
|
132
|
+
# @yield [locale] optional block in which each kind will be yielded
|
133
|
+
# @yieldparam [Symbol] locale the inflected locale identifier
|
134
|
+
# @yieldreturn [LazyArrayEnumerator] the lazy enumerator
|
135
|
+
# @overload each_inflected_locale
|
136
|
+
# Iterates through locales which have configured inflection support.
|
137
|
+
# @return [LazyArrayEnumerator] the lazy enumerator
|
138
|
+
# @overload each_inflected_locale(kind)
|
139
|
+
# Iterates through locales which have configured inflection support for the given +kind+.
|
140
|
+
# @param [Symbol] kind the identifier of a kind
|
141
|
+
# @return [LazyArrayEnumerator] the lazy enumerator
|
142
|
+
def each_inflected_locale(kind=nil, &block)
|
143
|
+
kind = kind.to_s.empty? ? nil : kind.to_sym
|
144
|
+
i = @lazy_locales.reject { |lang,data| data.empty? }
|
145
|
+
i = i.select { |lang,data| data.has_kind?(kind) } unless kind.nil?
|
146
|
+
i.each_key(&block)
|
147
|
+
end
|
148
|
+
alias_method :each_locale, :each_inflected_locale
|
149
|
+
alias_method :each_supported_locale, :each_inflected_locale
|
150
|
+
|
123
151
|
# Gets locales which have configured strict inflection support.
|
124
152
|
#
|
125
153
|
# @api public
|
@@ -132,19 +160,33 @@ module I18n
|
|
132
160
|
# @param [Symbol] kind the identifier of a kind
|
133
161
|
# @return [Array<Symbol>] the array containing locales that support inflection
|
134
162
|
def inflected_locales(kind=nil)
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
reject{ |lang,data| data.nil? || data.empty? }
|
139
|
-
return inflected_locales.keys if kind.nil?
|
140
|
-
kind = kind.to_sym
|
141
|
-
inflected_locales.
|
142
|
-
reject{|land,data| !data.has_kind?(kind)}.
|
143
|
-
keys
|
163
|
+
kind = kind.to_s.empty? ? nil : kind.to_sym
|
164
|
+
r = ( @inflected_locales_cache[kind] ||= each_inflected_locale(kind).to_a )
|
165
|
+
r.nil? ? r : r.dup
|
144
166
|
end
|
145
167
|
alias_method :locales, :inflected_locales
|
146
168
|
alias_method :supported_locales, :inflected_locales
|
147
169
|
|
170
|
+
# Iterates through known strict inflection kinds.
|
171
|
+
#
|
172
|
+
# @api public
|
173
|
+
# @return [LazyArrayEnumerator] the lazy enumerator
|
174
|
+
# @yield [kind] optional block in which each kind will be yielded
|
175
|
+
# @yieldparam [Symbol] kind the inflection kind
|
176
|
+
# @yieldreturn [LazyArrayEnumerator] the lazy enumerator
|
177
|
+
# @raise [I18n::InvalidLocale] if there is no proper locale name
|
178
|
+
# @overload kinds
|
179
|
+
# Iterates through known inflection kinds for the current locale.
|
180
|
+
# @return [LazyArrayEnumerator] the lazy enumerator
|
181
|
+
# @overload kinds(locale)
|
182
|
+
# Iterates through known inflection kinds for the given +locale+.
|
183
|
+
# @param [Symbol] locale the locale for which kinds should be listed
|
184
|
+
# @return [LazyArrayEnumerator] the lazy enumerator
|
185
|
+
def each_kind(locale=nil, &block)
|
186
|
+
data_safe(locale).each_kind(&block)
|
187
|
+
end
|
188
|
+
alias_method :each_inflection_kind, :each_kind
|
189
|
+
|
148
190
|
# Gets known strict inflection kinds.
|
149
191
|
#
|
150
192
|
# @api public
|
@@ -156,9 +198,9 @@ module I18n
|
|
156
198
|
# @overload kinds(locale)
|
157
199
|
# Gets known inflection kinds for the given +locale+.
|
158
200
|
# @param [Symbol] locale the locale for which kinds should be listed
|
159
|
-
# @return [Array<Symbol>] the array containing known inflection kinds
|
201
|
+
# @return [Array<Symbol>] the array containing known inflection kinds
|
160
202
|
def kinds(locale=nil)
|
161
|
-
|
203
|
+
each_kind(locale).to_a
|
162
204
|
end
|
163
205
|
alias_method :inflection_kinds, :kinds
|
164
206
|
|
@@ -325,6 +367,35 @@ module I18n
|
|
325
367
|
data_safe(locale).get_kind(token.to_sym, kind.to_sym)
|
326
368
|
end
|
327
369
|
|
370
|
+
# Iterates through available inflection tokens belonging to a strict kind and their descriptions.
|
371
|
+
#
|
372
|
+
# @api public
|
373
|
+
# @raise [I18n::InvalidLocale] if there is no proper locale name
|
374
|
+
# @return [LazyHashEnumerator] the lazy enumerator (<tt>token => description</tt>)
|
375
|
+
# @yield [token, description] optional block in which each token will be yielded
|
376
|
+
# @yieldparam [Symbol] token a token
|
377
|
+
# @yieldparam [String] description a description string for a token
|
378
|
+
# @yieldreturn [LazyHashEnumerator] the lazy enumerator
|
379
|
+
# @note You cannot deduce where aliases are pointing to, since the information
|
380
|
+
# about a target is replaced by the description. To get targets use the
|
381
|
+
# {#raw_tokens} method. To simply list aliases and their targets use
|
382
|
+
# the {#aliases} method.
|
383
|
+
# @overload each_token(kind)
|
384
|
+
# Iterates through available inflection tokens and their descriptions for some +kind+ and
|
385
|
+
# the current locale.
|
386
|
+
# @param [Symbol,String] kind the kind of inflection tokens to be returned
|
387
|
+
# @return [LazyHashEnumerator] the lazy enumerator (<tt>token => description</tt>)
|
388
|
+
# @overload each_token(kind, locale)
|
389
|
+
# Iterates through available inflection tokens and their descriptions of the given
|
390
|
+
# +kind+ and +locale+.
|
391
|
+
# @param [Symbol,String] kind the kind of inflection tokens to be returned
|
392
|
+
# @param [Symbol] locale the locale to use
|
393
|
+
# @return [LazyHashEnumerator] the lazy enumerator (<tt>token => description</tt>)
|
394
|
+
def each_token(kind=nil, locale=nil, &block)
|
395
|
+
kind = kind.to_s.empty? ? nil : kind.to_sym
|
396
|
+
data_safe(locale).each_token(kind, &block)
|
397
|
+
end
|
398
|
+
|
328
399
|
# Gets available inflection tokens belonging to a strict kind and their descriptions.
|
329
400
|
#
|
330
401
|
# @api public
|
@@ -348,10 +419,36 @@ module I18n
|
|
348
419
|
# @return [Hash] the hash containing available inflection tokens (including
|
349
420
|
# aliases) as keys and their descriptions as values
|
350
421
|
def tokens(kind=nil, locale=nil)
|
351
|
-
|
352
|
-
data_safe(locale).get_tokens(kind.to_sym)
|
422
|
+
each_token(kind, locale).to_h
|
353
423
|
end
|
354
424
|
|
425
|
+
# Iterates through available inflection tokens belonging to a strict kind and their values.
|
426
|
+
#
|
427
|
+
# @api public
|
428
|
+
# @return [LazyHashEnumerator] the lazy enumerator (<tt>token => description|target</tt>)
|
429
|
+
# @yield [token, value] optional block in which each token will be yielded
|
430
|
+
# @yieldparam [Symbol] token a token
|
431
|
+
# @yieldparam [Symbol, String] value a description string for a token or a target (if alias)
|
432
|
+
# @yieldreturn [LazyHashEnumerator] the lazy enumerator
|
433
|
+
# @raise [I18n::InvalidLocale] if there is no proper locale name
|
434
|
+
# @note You may deduce whether the returned values are aliases or true tokens
|
435
|
+
# by testing if a value is a kind of Symbol or a String.
|
436
|
+
# @overload each_token_raw(kind)
|
437
|
+
# Iterates through available inflection tokens and their values of the given +kind+ and
|
438
|
+
# the current locale.
|
439
|
+
# @param [Symbol,String] kind the kind of inflection tokens to be returned
|
440
|
+
# @return [LazyHashEnumerator] the lazy enumerator (<tt>token => description|target</tt>)
|
441
|
+
# @overload each_token_raw(kind, locale)
|
442
|
+
# Iterates through available inflection tokens (and their values) of the given +kind+ and +locale+.
|
443
|
+
# @param [Symbol,String] kind the kind of inflection tokens to be returned
|
444
|
+
# @param [Symbol] locale the locale to use
|
445
|
+
# @return [LazyHashEnumerator] the lazy enumerator (<tt>token => description|target</tt>)
|
446
|
+
def each_token_raw(kind=nil, locale=nil, &block)
|
447
|
+
kind = kind.to_s.empty? ? nil : kind.to_sym
|
448
|
+
data_safe(locale).each_raw_token(kind, &block)
|
449
|
+
end
|
450
|
+
alias_method :each_raw_token, :each_token_raw
|
451
|
+
|
355
452
|
# Gets available inflection tokens belonging to a strict kind and their values.
|
356
453
|
#
|
357
454
|
# @api public
|
@@ -374,11 +471,36 @@ module I18n
|
|
374
471
|
# and their descriptions as values. In case of aliases the returned
|
375
472
|
# values are Symbols
|
376
473
|
def tokens_raw(kind=nil, locale=nil)
|
377
|
-
|
378
|
-
data_safe(locale).get_raw_tokens(kind.to_sym)
|
474
|
+
each_token_raw(kind, locale).to_h
|
379
475
|
end
|
380
476
|
alias_method :raw_tokens, :tokens_raw
|
381
477
|
|
478
|
+
# Iterates through inflection tokens belonging to a strict kind and their values.
|
479
|
+
#
|
480
|
+
# @api public
|
481
|
+
# @return [LazyHashEnumerator] the lazy enumerator (<tt>token => description</tt>)
|
482
|
+
# @yield [token, description] optional block in which each token will be yielded
|
483
|
+
# @yieldparam [Symbol] token a token
|
484
|
+
# @yieldparam [String] description a description string for a token
|
485
|
+
# @yieldreturn [LazyHashEnumerator] the lazy enumerator
|
486
|
+
# @raise [I18n::InvalidLocale] if there is no proper locale name
|
487
|
+
# @note It returns only true tokens, not aliases.
|
488
|
+
# @overload each_token_true(kind)
|
489
|
+
# Iterates through true inflection tokens (and their values) of the given +kind+ and
|
490
|
+
# the current locale.
|
491
|
+
# @param [Symbol,String] kind the kind of inflection tokens to be returned
|
492
|
+
# @return [LazyHashEnumerator] the lazy enumerator (<tt>token => description</tt>)
|
493
|
+
# @overload each_token_true(kind, locale)
|
494
|
+
# Iterates through true inflection tokens (and their values) of the given +kind+ and +locale+.
|
495
|
+
# @param [Symbol,String] kind the kind of inflection tokens to be returned
|
496
|
+
# @param [Symbol] locale the locale to use
|
497
|
+
# @return [LazyHashEnumerator] the lazy enumerator (<tt>token => description</tt>)
|
498
|
+
def each_token_true(kind=nil, locale=nil, &block)
|
499
|
+
kind = kind.to_s.empty? ? nil : kind.to_sym
|
500
|
+
data_safe(locale).each_true_token(kind, &block)
|
501
|
+
end
|
502
|
+
alias_method :each_true_token, :each_token_true
|
503
|
+
|
382
504
|
# Gets true inflection tokens belonging to a strict kind and their values.
|
383
505
|
#
|
384
506
|
# @api public
|
@@ -398,11 +520,33 @@ module I18n
|
|
398
520
|
# @return [Hash] the hash containing available inflection tokens as keys
|
399
521
|
# and their descriptions as values
|
400
522
|
def tokens_true(kind=nil, locale=nil)
|
401
|
-
|
402
|
-
data_safe(locale).get_true_tokens(kind.to_sym)
|
523
|
+
each_token_true(kind, locale).to_h
|
403
524
|
end
|
404
525
|
alias_method :true_tokens, :tokens_true
|
405
526
|
|
527
|
+
# Iterates through inflection aliases belonging to a strict kind and their pointers.
|
528
|
+
#
|
529
|
+
# @api public
|
530
|
+
# @raise [I18n::InvalidLocale] if there is no proper locale name
|
531
|
+
# @return [LazyHashEnumerator] the lazy enumerator (<tt>token => target</tt>)
|
532
|
+
# @yield [alias, target] optional block in which each alias will be yielded
|
533
|
+
# @yieldparam [Symbol] alias an alias
|
534
|
+
# @yieldparam [Symbol] target a name of the target token
|
535
|
+
# @yieldreturn [LazyHashEnumerator] the lazy enumerator
|
536
|
+
# @overload each_alias(kind)
|
537
|
+
# Iterates through inflection aliases (and their pointers) of the given +kind+ and the current locale.
|
538
|
+
# @param [Symbol,String] kind the kind of aliases to get
|
539
|
+
# @return [LazyHashEnumerator] the lazy enumerator (<tt>token => target</tt>)
|
540
|
+
# @overload each_alias(kind, locale)
|
541
|
+
# Iterates through inflection aliases (and their pointers) of the given +kind+ and +locale+.
|
542
|
+
# @param [Symbol,String] kind the kind of aliases to get
|
543
|
+
# @param [Symbol] locale the locale to use
|
544
|
+
# @return [LazyHashEnumerator] the lazy enumerator (<tt>token => target</tt>)
|
545
|
+
def each_alias(kind=nil, locale=nil, &block)
|
546
|
+
kind = kind.to_s.empty? ? nil : kind.to_sym
|
547
|
+
data_safe(locale).each_alias(kind, &block)
|
548
|
+
end
|
549
|
+
|
406
550
|
# Gets inflection aliases belonging to a strict kind and their pointers.
|
407
551
|
#
|
408
552
|
# @api public
|
@@ -418,8 +562,7 @@ module I18n
|
|
418
562
|
# @param [Symbol] locale the locale to use
|
419
563
|
# @return [Hash] the Hash containing available inflection aliases
|
420
564
|
def aliases(kind=nil, locale=nil)
|
421
|
-
|
422
|
-
data_safe(locale).get_aliases(kind.to_sym)
|
565
|
+
each_alias(kind, locale).to_h
|
423
566
|
end
|
424
567
|
|
425
568
|
# Gets the description of the given inflection token belonging to a strict kind.
|
@@ -509,7 +652,7 @@ module I18n
|
|
509
652
|
# @return [Symbol] the given locale or the global locale
|
510
653
|
def prep_locale(locale=nil)
|
511
654
|
locale ||= I18n.locale
|
512
|
-
raise I18n::InvalidLocale.new(locale) if
|
655
|
+
raise I18n::InvalidLocale.new(locale) if locale.to_s.empty?
|
513
656
|
locale.to_sym
|
514
657
|
end
|
515
658
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# Author:: Paweł Wilk (mailto:pw@gnu.org)
|
4
4
|
# Copyright:: (c) 2011 by Paweł Wilk
|
5
|
-
# License:: This program is licensed under the terms of {file:docs/LGPL GNU Lesser General Public License} or {file:COPYING Ruby License}.
|
5
|
+
# License:: This program is licensed under the terms of {file:docs/LGPL GNU Lesser General Public License} or {file:docs/COPYING Ruby License}.
|
6
6
|
#
|
7
7
|
# This file contains I18n::Backend::Inflector module,
|
8
8
|
# which extends I18n::Backend::Simple by adding the ability
|
@@ -14,7 +14,7 @@ module I18n
|
|
14
14
|
# @abstract This namespace is shared with I18n subsystem.
|
15
15
|
module Backend
|
16
16
|
|
17
|
-
# This module contains methods that
|
17
|
+
# This module contains methods that add
|
18
18
|
# tokenized inflection support to internal I18n classes.
|
19
19
|
# It is intened to be included in the Simple backend
|
20
20
|
# module so that it will patch translate method in order
|
@@ -114,7 +114,7 @@ module I18n
|
|
114
114
|
subdata = (subdata[:inflections] || subdata['inflections'])
|
115
115
|
unless subdata.nil?
|
116
116
|
db, db_strict = load_inflection_tokens(locale, r[:i18n][:inflections])
|
117
|
-
@inflector.
|
117
|
+
@inflector.add_database(db, db_strict)
|
118
118
|
end
|
119
119
|
end
|
120
120
|
end
|
@@ -127,9 +127,10 @@ module I18n
|
|
127
127
|
#
|
128
128
|
# @return [void]
|
129
129
|
def inflector_try_init
|
130
|
-
|
131
|
-
|
132
|
-
|
130
|
+
unless (defined?(@inflector) && !@inflector.nil?)
|
131
|
+
@inflector = I18n::Inflector::API.new
|
132
|
+
init_translations unless initialized?
|
133
|
+
end
|
133
134
|
end
|
134
135
|
|
135
136
|
# Takes care of loading inflection tokens
|
@@ -143,7 +144,9 @@ module I18n
|
|
143
144
|
# @raise [I18n::DuplicatedInflectionToken] if a token has already appeard in loaded configuration
|
144
145
|
# @return [Boolean] +true+ if everything went fine
|
145
146
|
def init_translations
|
146
|
-
|
147
|
+
unless (defined?(@inflector) && !@inflector.nil?)
|
148
|
+
@inflector = I18n::Inflector::API.new
|
149
|
+
end
|
147
150
|
super
|
148
151
|
end
|
149
152
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# Author:: Paweł Wilk (mailto:pw@gnu.org)
|
4
4
|
# Copyright:: (c) 2011 by Paweł Wilk
|
5
|
-
# License:: This program is licensed under the terms of {file:docs/LGPL GNU Lesser General Public License} or {file:COPYING Ruby License}.
|
5
|
+
# License:: This program is licensed under the terms of {file:docs/LGPL GNU Lesser General Public License} or {file:docs/COPYING Ruby License}.
|
6
6
|
#
|
7
7
|
# This file contains configuration of I18n::Inflector module.
|
8
8
|
|
@@ -36,7 +36,7 @@ module I18n
|
|
36
36
|
|
37
37
|
# @private
|
38
38
|
def gen_regexp(ary)
|
39
|
-
::Regexp.new '['
|
39
|
+
::Regexp.new '[' << ary.join << ']'
|
40
40
|
end
|
41
41
|
module_function :gen_regexp
|
42
42
|
|
@@ -45,7 +45,7 @@ module I18n
|
|
45
45
|
|
46
46
|
# Regexp matching a prefix that makes option
|
47
47
|
# a controlling option.
|
48
|
-
OPTION_PREFIX_REGEXP = Regexp.new
|
48
|
+
OPTION_PREFIX_REGEXP = Regexp.new('^' << OPTION_PREFIX)
|
49
49
|
|
50
50
|
# This module contains keys that have special
|
51
51
|
# meaning.
|
@@ -146,7 +146,7 @@ module I18n
|
|
146
146
|
end # module Token
|
147
147
|
|
148
148
|
# All operators.
|
149
|
-
ALL =
|
149
|
+
ALL = Tokens::ALL | Token::ALL
|
150
150
|
|
151
151
|
end # module Operators
|
152
152
|
|
@@ -164,7 +164,7 @@ module I18n
|
|
164
164
|
module Tokens
|
165
165
|
|
166
166
|
# Reserved characters in token identifiers placed in configuration.
|
167
|
-
DB = (Operators::ALL
|
167
|
+
DB = (Operators::ALL | Markers::ALL) - [Markers::LOUD_VALUE]
|
168
168
|
|
169
169
|
# Reserved characters in token identifiers passed as options.
|
170
170
|
OPTION = DB
|
@@ -212,13 +212,13 @@ module I18n
|
|
212
212
|
module Kinds
|
213
213
|
|
214
214
|
# Reserved characters in kind identifiers placed in configuration.
|
215
|
-
DB = (Operators::ALL
|
215
|
+
DB = (Operators::ALL | Markers::ALL) - [Markers::ALIAS, Markers::LOUD_VALUE]
|
216
216
|
|
217
217
|
# Reserved characters in kind identifiers passed as option values.
|
218
218
|
OPTION = DB
|
219
219
|
|
220
220
|
# Reserved characters in kind identifiers placed in patterns.
|
221
|
-
PATTERN = (Operators::ALL
|
221
|
+
PATTERN = (Operators::ALL | Markers::ALL) - [Markers::LOUD_VALUE]
|
222
222
|
|
223
223
|
# This module contains constants defining
|
224
224
|
# regular expressions for reserved characters
|
@@ -259,23 +259,23 @@ module I18n
|
|
259
259
|
end # module Reserved
|
260
260
|
|
261
261
|
# A string for regular expression that catches patterns.
|
262
|
-
PATTERN_RESTR = '(.?)'
|
263
|
-
'([^\\'
|
264
|
-
'([^\\'
|
265
|
-
'((?:\\'
|
266
|
-
']+)\\'
|
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
267
|
|
268
268
|
# A string for regular expression that extracts additional patterns attached.
|
269
|
-
MULTI_RESTR = '\\'
|
270
|
-
'([^\\'
|
269
|
+
MULTI_RESTR = '\\' << Markers::PATTERN_BEGIN <<
|
270
|
+
'([^\\' << Markers::PATTERN_END + ']+)\\' <<
|
271
271
|
Markers::PATTERN_END
|
272
272
|
|
273
273
|
# A regular expression that catches token groups or single tokens.
|
274
|
-
TOKENS_RESTR = '(?:'
|
275
|
-
'([^'
|
276
|
-
|
277
|
-
'([^\\'
|
278
|
-
'|([^'
|
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
279
|
|
280
280
|
# A regular expression that catches patterns.
|
281
281
|
PATTERN_REGEXP = Regexp.new PATTERN_RESTR
|
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# Author:: Paweł Wilk (mailto:pw@gnu.org)
|
4
4
|
# Copyright:: (c) 2011 by Paweł Wilk
|
5
|
-
# License:: This program is licensed under the terms of {file:docs/LGPL GNU Lesser General Public License} or {file:COPYING Ruby License}.
|
5
|
+
# License:: This program is licensed under the terms of {file:docs/LGPL GNU Lesser General Public License} or {file:docs/COPYING Ruby License}.
|
6
6
|
#
|
7
7
|
# This file contains error reporting classes for I18n::Backend::Inflector module.
|
8
8
|
|
@@ -81,7 +81,7 @@ module I18n
|
|
81
81
|
kindmsg = kind.to_sym.inspect
|
82
82
|
end
|
83
83
|
end
|
84
|
-
super
|
84
|
+
"" << super <<
|
85
85
|
"required option #{kindmsg} was not found"
|
86
86
|
end
|
87
87
|
|
@@ -92,7 +92,7 @@ module I18n
|
|
92
92
|
class InflectionOptionIncorrect < InvalidOptionForKind
|
93
93
|
|
94
94
|
def message
|
95
|
-
super
|
95
|
+
"" << super <<
|
96
96
|
"required value #{@option.inspect} of option #{@kind.inspect} " \
|
97
97
|
"does not match any token"
|
98
98
|
end
|
@@ -113,7 +113,7 @@ module I18n
|
|
113
113
|
kind = @kind.to_s.empty? ? "" : @kind.to_sym
|
114
114
|
badkind = " (processed kind: #{kind.inspect})"
|
115
115
|
end
|
116
|
-
super
|
116
|
+
"" << super << "token #{@token.to_s.inspect} is invalid" + badkind
|
117
117
|
end
|
118
118
|
|
119
119
|
end
|
@@ -127,7 +127,7 @@ module I18n
|
|
127
127
|
end
|
128
128
|
|
129
129
|
def message
|
130
|
-
super
|
130
|
+
"" << super << "inflection option #{@kind.inspect} is invalid"
|
131
131
|
end
|
132
132
|
|
133
133
|
end
|
@@ -141,7 +141,7 @@ module I18n
|
|
141
141
|
end
|
142
142
|
|
143
143
|
def message
|
144
|
-
super
|
144
|
+
"" << super << "kind #{@kind.to_s.inspect} is invalid"
|
145
145
|
end
|
146
146
|
|
147
147
|
end
|
@@ -156,7 +156,7 @@ module I18n
|
|
156
156
|
end
|
157
157
|
|
158
158
|
def message
|
159
|
-
super
|
159
|
+
"" << super <<
|
160
160
|
"token #{@token.to_s.inspect} " \
|
161
161
|
"is not of the expected kind #{@kind.inspect}"
|
162
162
|
end
|
@@ -175,7 +175,7 @@ module I18n
|
|
175
175
|
end
|
176
176
|
|
177
177
|
def message
|
178
|
-
super
|
178
|
+
"" << super << "pattern is malformed; token count differs from kind count"
|
179
179
|
end
|
180
180
|
|
181
181
|
end
|
@@ -192,7 +192,7 @@ module I18n
|
|
192
192
|
end
|
193
193
|
|
194
194
|
def message
|
195
|
-
super
|
195
|
+
"" << super <<
|
196
196
|
"token #{@token.inspect} " \
|
197
197
|
"was already assigned to the kind #{@original_kind.inspect}"
|
198
198
|
end
|
@@ -213,7 +213,7 @@ module I18n
|
|
213
213
|
|
214
214
|
def message
|
215
215
|
what = token == :default ? "default token" : "alias #{@token.inspect}"
|
216
|
-
super
|
216
|
+
"" << super <<
|
217
217
|
"the #{what} " \
|
218
218
|
"points to an unknown token #{@pointer.inspect}"
|
219
219
|
end
|
@@ -233,11 +233,11 @@ module I18n
|
|
233
233
|
|
234
234
|
def message
|
235
235
|
if @description.nil?
|
236
|
-
super
|
236
|
+
"" << super <<
|
237
237
|
"inflection token #{@token.inspect} " \
|
238
238
|
"has a bad name"
|
239
239
|
else
|
240
|
-
super
|
240
|
+
"" << super <<
|
241
241
|
"inflection token #{@token.inspect} " \
|
242
242
|
"has a bad description #{@description.inspect}"
|
243
243
|
end
|
@@ -255,7 +255,7 @@ module I18n
|
|
255
255
|
end
|
256
256
|
|
257
257
|
def message
|
258
|
-
super
|
258
|
+
"" << super <<
|
259
259
|
"inflection kind #{@kind.inspect} has bad name or type"
|
260
260
|
end
|
261
261
|
|