r18n-core 3.2.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +39 -33
  3. data/lib/r18n-core.rb +29 -15
  4. data/lib/r18n-core/filter_list.rb +15 -10
  5. data/lib/r18n-core/filters.rb +22 -26
  6. data/lib/r18n-core/helpers.rb +2 -2
  7. data/lib/r18n-core/i18n.rb +61 -59
  8. data/lib/r18n-core/locale.rb +120 -97
  9. data/{locales → lib/r18n-core/locales}/af.rb +12 -8
  10. data/lib/r18n-core/locales/az.rb +38 -0
  11. data/lib/r18n-core/locales/bg.rb +29 -0
  12. data/{locales → lib/r18n-core/locales}/ca.rb +9 -6
  13. data/{locales → lib/r18n-core/locales}/cs.rb +11 -7
  14. data/lib/r18n-core/locales/cy.rb +50 -0
  15. data/{locales → lib/r18n-core/locales}/da.rb +10 -7
  16. data/lib/r18n-core/locales/de.rb +33 -0
  17. data/{locales → lib/r18n-core/locales}/en-au.rb +1 -1
  18. data/{locales → lib/r18n-core/locales}/en-gb.rb +1 -1
  19. data/{locales → lib/r18n-core/locales}/en-us.rb +2 -1
  20. data/{locales → lib/r18n-core/locales}/en.rb +8 -5
  21. data/{locales → lib/r18n-core/locales}/eo.rb +5 -3
  22. data/lib/r18n-core/locales/es-cl.rb +16 -0
  23. data/{locales → lib/r18n-core/locales}/es-us.rb +4 -3
  24. data/{locales → lib/r18n-core/locales}/es.rb +5 -3
  25. data/{locales → lib/r18n-core/locales}/fa.rb +1 -1
  26. data/lib/r18n-core/locales/fi.rb +39 -0
  27. data/{locales → lib/r18n-core/locales}/fr.rb +10 -6
  28. data/{locales → lib/r18n-core/locales}/gl.rb +5 -3
  29. data/{locales → lib/r18n-core/locales}/hr.rb +8 -5
  30. data/{locales → lib/r18n-core/locales}/hu.rb +8 -5
  31. data/{locales → lib/r18n-core/locales}/id.rb +8 -4
  32. data/{locales → lib/r18n-core/locales}/it.rb +8 -5
  33. data/{locales → lib/r18n-core/locales}/ja.rb +4 -3
  34. data/{locales → lib/r18n-core/locales}/kk.rb +11 -7
  35. data/{locales → lib/r18n-core/locales}/ko.rb +0 -0
  36. data/lib/r18n-core/locales/lv.rb +46 -0
  37. data/lib/r18n-core/locales/mn.rb +30 -0
  38. data/{locales → lib/r18n-core/locales}/nb.rb +5 -3
  39. data/{locales → lib/r18n-core/locales}/nl.rb +10 -7
  40. data/{locales → lib/r18n-core/locales}/no.rb +0 -0
  41. data/lib/r18n-core/locales/pl.rb +45 -0
  42. data/{locales → lib/r18n-core/locales}/pt-br.rb +1 -1
  43. data/lib/r18n-core/locales/pt.rb +35 -0
  44. data/lib/r18n-core/locales/ru.rb +46 -0
  45. data/{locales → lib/r18n-core/locales}/sk.rb +10 -6
  46. data/{locales → lib/r18n-core/locales}/sr-latn.rb +5 -3
  47. data/{locales → lib/r18n-core/locales}/sv-se.rb +6 -4
  48. data/lib/r18n-core/locales/th.rb +41 -0
  49. data/{locales → lib/r18n-core/locales}/tr.rb +5 -4
  50. data/lib/r18n-core/locales/uk.rb +31 -0
  51. data/{locales → lib/r18n-core/locales}/vi.rb +11 -7
  52. data/{locales → lib/r18n-core/locales}/zh-cn.rb +1 -1
  53. data/{locales → lib/r18n-core/locales}/zh-tw.rb +3 -3
  54. data/{locales → lib/r18n-core/locales}/zh.rb +4 -3
  55. data/lib/r18n-core/translated.rb +35 -34
  56. data/lib/r18n-core/translated_string.rb +4 -2
  57. data/lib/r18n-core/translation.rb +16 -17
  58. data/lib/r18n-core/unsupported_locale.rb +6 -5
  59. data/lib/r18n-core/untranslated.rb +10 -4
  60. data/lib/r18n-core/utils.rb +1 -14
  61. data/lib/r18n-core/version.rb +1 -1
  62. data/lib/r18n-core/yaml_loader.rb +13 -13
  63. data/lib/r18n-core/yaml_methods.rb +3 -1
  64. data/r18n-core.gemspec +1 -1
  65. data/spec/filters_spec.rb +3 -0
  66. data/spec/i18n_spec.rb +22 -8
  67. data/spec/locale_spec.rb +4 -5
  68. data/spec/locales/af_spec.rb +9 -0
  69. data/spec/locales/en-us_spec.rb +16 -1
  70. data/spec/locales/es-us_spec.rb +11 -0
  71. data/spec/locales/fi_spec.rb +9 -0
  72. data/spec/locales/hu_spec.rb +2 -0
  73. data/spec/locales/id_spec.rb +23 -0
  74. data/spec/locales/vi_spec.rb +4 -3
  75. data/spec/r18n_spec.rb +21 -7
  76. data/spec/spec_helper.rb +0 -7
  77. data/spec/translated_spec.rb +121 -65
  78. data/spec/translation_spec.rb +5 -2
  79. data/spec/translations/with_regions/en-US.yml +0 -0
  80. data/spec/translations/yaml/en-GB.yml +1 -0
  81. data/spec/translations/yaml/en-us.yml +1 -0
  82. data/spec/yaml_loader_spec.rb +4 -2
  83. metadata +64 -50
  84. data/locales/az.rb +0 -34
  85. data/locales/bg.rb +0 -25
  86. data/locales/cy.rb +0 -50
  87. data/locales/de.rb +0 -29
  88. data/locales/fi.rb +0 -35
  89. data/locales/lv.rb +0 -41
  90. data/locales/mn.rb +0 -27
  91. data/locales/pl.rb +0 -40
  92. data/locales/pt.rb +0 -29
  93. data/locales/ru.rb +0 -41
  94. data/locales/th.rb +0 -37
  95. data/locales/uk.rb +0 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea9e0df5d7d9a6465ecbb70590f24b69578fe9bcf703a825f7f861dae17ab8d5
4
- data.tar.gz: ce67040d879d2edd3e14bb17d5b3cebff9a4824a25ace0d4caf15d5c4292a6e2
3
+ metadata.gz: 8a07951d2b74c13c824f759f496022ba65a190760e6b681958bfd037304713e2
4
+ data.tar.gz: 118665d95730bc8984258f0c0d29ab1d174acc99631319633f475bd3374aca70
5
5
  SHA512:
6
- metadata.gz: ed567f238f886118551f5243c409fea38722c3508733943731489840bb69507613edb9f5d46031bfbe230d1f339d1c7f757d3cdc5adb102d92559df07b3c18d4
7
- data.tar.gz: 825933ccff178daf0648cf78f1f8b9378149cb151bfcddf2835165c66c7dec0bb785368910b6ec0435ccfb39331d953de6d9029b8e5f916ee7420e53fa0b6cab
6
+ metadata.gz: f7fe8b6c0ab1bb0804050d24c6ca85f0b47b388d83a4ce8c459b76e232c3bc1a9635e87ebd23e044280e4e68d189ca87910a4a57fab6153a763254707a29248e
7
+ data.tar.gz: b8cf0b271f94bdccefcd3d5e10351a05837c5d483cf0fc78bad43cf687a8c2742701ef38c4874e5c8720c1726690eb9c758f9f815ef982bdae07a1789385c5fb
data/README.md CHANGED
@@ -10,11 +10,11 @@ Use `r18n-rails` or `sinatra-r18n` to localize Web applications and
10
10
  * Nice Ruby-style syntax.
11
11
  * Filters.
12
12
  * Model Translation (or any Ruby object).
13
- * Autodetect user locales.
13
+ * Auto-detect user locales.
14
14
  * Flexible locales.
15
15
  * Total flexibility.
16
16
 
17
- See full features in [main README](https://github.com/ai/r18n/blob/master/README.md).
17
+ See full features in [main README](https://github.com/r18n/r18n/blob/master/README.md).
18
18
 
19
19
  ## Usage
20
20
 
@@ -47,7 +47,8 @@ To set locale only for current thread use `R18n.thread_set`.
47
47
 
48
48
  Translation files are in YAML format by default and have names like
49
49
  `en.yml` (English) or `en-us.yml` (USA English dialect) with
50
- language/country code (RFC 3066).
50
+ language/country code (RFC 3066). Upcased region (`en-US`) and
51
+ `.yaml` file extension are also allowed.
51
52
 
52
53
  In your translation files you can use:
53
54
 
@@ -96,7 +97,7 @@ t.post.add #=> "Add post"
96
97
  t[:post][:add] #=> "Add post"
97
98
  ```
98
99
 
99
- If the locale isnt found in the users requested locale, R18n will search for
100
+ If the locale isn't found in the user's requested locale, R18n will search for
100
101
  it in sublocales or in another locale, which the user also can accept:
101
102
 
102
103
  ```ruby
@@ -104,7 +105,7 @@ t.not.in.english #=> "В английском нет"
104
105
  ```
105
106
 
106
107
  The translated string has a `locale` method for determining its locale (Locale
107
- instance or code string if locale ist supported in R18n):
108
+ instance or code string if locale is't supported in R18n):
108
109
 
109
110
  ```ruby
110
111
  i18n.not.in.english.locale #=> Locale ru (Русский)
@@ -128,8 +129,8 @@ t.robots(1) #=> "One robot"
128
129
  t.robots(50) #=> "50 robots"
129
130
  ```
130
131
 
131
- If there isnt a pluralization for a particular number, translation will be use
132
- `n`. If there isnt a locale file for translation, it will use the English
132
+ If there isn't a pluralization for a particular number, translation will be use
133
+ `n`. If there isn't a locale file for translation, it will use the English
133
134
  pluralization rule (`0`, `1` and `n`).
134
135
 
135
136
  You can check if the key has a translation:
@@ -193,7 +194,7 @@ To create a filter you pass the following to `R18n::Filters.add`:
193
194
  * Optional filter name, to disable, enable or delete it later by
194
195
  `R18n::Filters.off`, `R18n::Filters.on` and
195
196
  `R18n::Filters.delete`.
196
- * Hash with options:
197
+ * `Hash` with options:
197
198
  * `passive: true` to filter translations only on load;
198
199
  * `:position` within the list of current filters of this type
199
200
  (by default a new filter will be inserted into last position).
@@ -201,7 +202,7 @@ To create a filter you pass the following to `R18n::Filters.add`:
201
202
  The filter will receive at least two arguments:
202
203
  * Translation (possibly already filtered by other filters for this type earlier
203
204
  in the list).
204
- * A Hash with translation `locale` and `path`.
205
+ * A `Hash` with translation `locale` and `path`.
205
206
  * Parameters from translation request will be in the remaining arguments.
206
207
 
207
208
  In Rails application put your filters to `app/i18n/filters.rb`, it will be
@@ -254,7 +255,7 @@ hi: !!markdown
254
255
  t.hi #=> "<p><strong>Hi</strong>, people!</p>"
255
256
  ```
256
257
 
257
- If you cant use Kramdown you can redefine Markdown filter
258
+ If you can't use Kramdown you can redefine Markdown filter
258
259
  to use your own parser:
259
260
 
260
261
  ```ruby
@@ -270,7 +271,7 @@ end
270
271
 
271
272
  #### Textile
272
273
 
273
- To use Textile in your translations you must install the RedCloth gem:
274
+ To use Textile in your translations you must install the `RedCloth` gem:
274
275
 
275
276
  ```yaml
276
277
  alarm: !!textile
@@ -311,8 +312,8 @@ l -12000.5 #=> "−12,000.5"
311
312
  Number and float formatters will also put real typographic minus and put
312
313
  non-breakable thin spaces (for locale, which use it as digit separator).
313
314
 
314
- You can translate months and week day names in Time, Date and DateTime by the
315
- `strftime` method:
315
+ You can translate months and week day names in `Time`, `Date` and `DateTime`
316
+ by the `strftime` method:
316
317
 
317
318
  ```ruby
318
319
  l Time.now, '%B' #=> "September"
@@ -330,8 +331,8 @@ l Time.now.to_date #=> "2009-08-09"
330
331
 
331
332
  ### Model
332
333
 
333
- You can add i18n support to any classes, including ORM models (ActiveRecord,
334
- DataMapper, MongoMapper, Mongoid or others):
334
+ You can add i18n support to any classes, including ORM models (`ActiveRecord`,
335
+ `Sequel`, `DataMapper`, `MongoMapper`, `Mongoid` or others):
335
336
 
336
337
  ```ruby
337
338
  class Product
@@ -361,9 +362,9 @@ See `R18n::Translated` for documentation.
361
362
 
362
363
  ### Locale
363
364
 
364
- All supported locales are stored in R18n gem in `locales` directory. If you want
365
- to add your locale, please fork this project and send a pull request or email me
366
- at <andrey@sitnik.ru>.
365
+ All supported locales are stored in `r18n-core` gem in `locales/` directory.
366
+ If you want to add your locale, please see the ["Add Locale"](#add-locale)
367
+ section.
367
368
 
368
369
  To get information about a locale create an `R18n::Locale` instance:
369
370
 
@@ -398,7 +399,7 @@ You can load translations from anywhere, not just from YAML files. To load
398
399
  translation you must create loader class with 2 methods:
399
400
 
400
401
  * `available` – return array of locales of available translations;
401
- * `load(locale)` – return Hash of translation.
402
+ * `load(locale)` – return `Hash` of translation.
402
403
 
403
404
  Pass its instance to `R18n.default_places` or `R18n.set(locales, loaders)`
404
405
 
@@ -448,32 +449,37 @@ R18n.extension_places << R18n::Loader::YAML.new('./error_messages/')
448
449
 
449
450
  ## Add Locale
450
451
 
451
- If R18n hasn’t got locale file for your language, please add it. Its very
452
+ If R18n has not got locale file for your language, please add it. It's very
452
453
  simple:
453
454
 
454
- * Create the file <tt><i>code</i>.rb</tt> in the `locales/` directory for your
455
- language and describe locale. Just copy from another locale and change the
455
+ * Create the file `%{code}.rb` for your language and describe locale, then
456
+ require it in the project. Just copy from another locale and change the
456
457
  values.
457
458
  * If your country has alternate languages (for example, in exUSSR countries
458
459
  most people also know Russian), add
459
- <tt>sublocales %w[<i>another_locale</i> en]</tt>.
460
- * Create in `base/` file <tt><i>code</i>.yml</tt> for your language and
461
- translate the base messages. Just copy file from language, which you know,
462
- and rewrite values.
460
+ `sublocales %w[%{another_locale} en]`.
463
461
  * If your language needs some special logic (for example, different
464
462
  pluralization or time formatters) you can extend `R18n::Locale` class methods.
465
- * Send a pull request via GitHub <http://github.com/ai/r18n> or just write email
466
- with the files to me <andrey@sitnik.ru>.
467
463
 
468
- *Code* is RFC 3066 code for your language (for example, “en” for English and
469
- “fr-CA” for Canadian French). Email me with any questions you may have, you will
470
- find other contact addresses at http://sitnik.ru.
464
+ If you want to send a pull request:
465
+
466
+ * Move your `%{code}.rb` file in the `locales/` directory.
467
+ * Create `%{code}.yml` file for your language in the `base/` directory and
468
+ translate the base messages. Just copy file from language, which you know,
469
+ and rewrite values.
470
+ * Send a pull request via GitHub <http://github.com/r18n/r18n> or just write
471
+ email with the files to [Andrey Sitnik](mailto:andrey@sitnik.ru)
472
+ or [Alexander Popov](mailto:alex.wayfer@gmail.com).
473
+
474
+ `%{code}` is RFC 3066 code for your language (for example, `en` for English and
475
+ `fr-CA` for Canadian French). Email me with any questions you may have, you will
476
+ find other contact addresses at [sitnik.ru](https://sitnik.ru/).
471
477
 
472
478
  ## License
473
479
 
474
480
  R18n is licensed under the GNU Lesser General Public License version 3.
475
- See the LICENSE file or http://www.gnu.org/licenses/lgpl.html.
481
+ See the LICENSE file or [www.gnu.org/licenses/lgpl-3.0.html](https://www.gnu.org/licenses/lgpl-3.0.html).
476
482
 
477
483
  ## Author
478
484
 
479
- Andrey “A.I.” Sitnik <andrey@sitnik.ru>
485
+ Andrey “A.I.” Sitnik [andrey@sitnik.ru](mailto:andrey@sitnik.ru)
@@ -39,8 +39,8 @@ module R18n
39
39
  autoload :Translated, 'r18n-core/translated'
40
40
 
41
41
  class << self
42
- # Set I18n object globally. You can miss translation +places+, it will be
43
- # taken from <tt>R18n.default_places</tt>.
42
+ # Set I18n object globally. You can miss translation `places`, it will be
43
+ # taken from `R18n.default_places`.
44
44
  def set(i18n = nil, places = R18n.default_places, &block)
45
45
  @i18n =
46
46
  if block_given?
@@ -90,41 +90,55 @@ module R18n
90
90
  Thread.current
91
91
  end
92
92
 
93
- # Translate message. Alias for <tt>R18n.get.t</tt>.
93
+ # Translate message. Alias for `R18n.get.t`.
94
94
  def t(*params)
95
95
  get.t(*params)
96
96
  end
97
97
 
98
- # Localize object. Alias for <tt>R18n.get.l</tt>.
98
+ # Localize object. Alias for `R18n.get.l`.
99
99
  def l(*params)
100
100
  get.l(*params)
101
101
  end
102
102
 
103
- # Return I18n object for +locale+. Useful to temporary change locale,
103
+ # Return I18n object for `locale`. Useful to temporary change locale,
104
104
  # for example, to show text in locales list:
105
105
  #
106
106
  # - R18n.available_locales.each do |locale|
107
107
  # - R18n.change(locale).t.language_title
108
+ #
109
+ # It also can be used with block:
110
+ #
111
+ # - R18n.change(locale) { t.language_title }
108
112
  def change(locale)
109
113
  locale = locale.code if locale.is_a? Locale
110
114
  exists = get ? get.locales.map(&:code) : []
111
115
  places = get ? get.translation_places : R18n.default_places
112
- R18n::I18n.new([locale] + exists, places)
116
+
117
+ i18n = R18n::I18n.new([locale] + exists, places)
118
+
119
+ if block_given?
120
+ old_thread_i18n = thread[:r18n_i18n]
121
+ thread_set i18n
122
+ yield
123
+ thread[:r18n_i18n] = old_thread_i18n
124
+ end
125
+
126
+ i18n
113
127
  end
114
128
 
115
- # Return Locale object by locale code. Its shortcut for
116
- # <tt>R18n::Locale.load(code)</tt>.
129
+ # Return Locale object by locale code. It's shortcut for
130
+ # `R18n::Locale.load(code)`.
117
131
  def locale(code)
118
132
  R18n::Locale.load(code)
119
133
  end
120
134
 
121
- # Return Array of locales with available translations. You can miss
122
- # translation +places+, it will be taken from <tt>R18n.default_places</tt>.
135
+ # Return `Array` of locales with available translations. You can miss
136
+ # translation `places`, it will be taken from `R18n.default_places`.
123
137
  def available_locales(places = R18n.default_places)
124
138
  R18n::I18n.convert_places(places).map(&:available).flatten.uniq
125
139
  end
126
140
 
127
- # Default places for <tt>R18n.set</tt> and <tt>R18n.available_locales</tt>.
141
+ # Default places for `R18n.set` and `R18n.available_locales`.
128
142
  #
129
143
  # You can set block to calculate places dynamically:
130
144
  # R18n.default_places { settings.i18n_places }
@@ -140,15 +154,15 @@ module R18n
140
154
  end
141
155
  end
142
156
 
143
- # Default loader class, which will be used if you didnt send loader to
144
- # +I18n.new+ (object with +available+ and +load+ methods).
157
+ # Default loader class, which will be used if you didn't send loader to
158
+ # `I18n.new` (object with `available` and `load` methods).
145
159
  attr_accessor :default_loader
146
160
 
147
161
  # Loaders with extension translations. If application translations with
148
- # same locale isnt exists, extension file willnt be used.
162
+ # same locale isn't exists, extension file willn't be used.
149
163
  attr_accessor :extension_places
150
164
 
151
- # Hash of hash-like (see Moneta) object to store loaded translations.
165
+ # `Hash` of hash-like (see Moneta) object to store loaded translations.
152
166
  attr_accessor :cache
153
167
  end
154
168
 
@@ -18,10 +18,10 @@
18
18
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
20
  module R18n
21
- # Superclass for +GlobalFilterList+ and +CustomFilterList+ with filters
21
+ # Superclass for `GlobalFilterList` and `CustomFilterList` with filters
22
22
  # processing.
23
23
  class FilterList
24
- # Process +value+ by filters in +enabled+.
24
+ # Process `value` by filters in `enabled`.
25
25
  def process(filters_type, type, value, locale, path, params)
26
26
  config = { locale: locale, path: path }
27
27
 
@@ -39,15 +39,17 @@ module R18n
39
39
 
40
40
  # Shortcut to process `R18n::Typed`.
41
41
  def process_typed(filters_type, typed_value, params)
42
- process(filters_type,
43
- typed_value.type,
44
- typed_value.value,
45
- typed_value.locale,
46
- typed_value.path,
47
- params)
42
+ process(
43
+ filters_type,
44
+ typed_value.type,
45
+ typed_value.value,
46
+ typed_value.locale,
47
+ typed_value.path,
48
+ params
49
+ )
48
50
  end
49
51
 
50
- # Process +value+ by global filters in +enabled+.
52
+ # Process `value` by global filters in `enabled`.
51
53
  def process_string(filters_type, value, config, params)
52
54
  config = { locale: value.locale, path: config } if config.is_a? String
53
55
 
@@ -62,7 +64,7 @@ module R18n
62
64
  end
63
65
  end
64
66
 
65
- # Array of enabled filters with +filters_type+ for +type+.
67
+ # `Array` of enabled filters with `filters_type` for `type`.
66
68
  def enabled(filters_type, type)
67
69
  if filters_type == :passive
68
70
  passive(type)
@@ -137,6 +139,7 @@ module R18n
137
139
  def passive(type)
138
140
  enabled = Filters.passive_enabled[type]
139
141
  return enabled unless @changed_passive.include? type
142
+
140
143
  enabled = enabled.reject { |i| @off_by_type[type].include? i }
141
144
  enabled + @on_by_type[type].select(&:passive)
142
145
  end
@@ -144,6 +147,7 @@ module R18n
144
147
  def active(type)
145
148
  enabled = Filters.active_enabled[type]
146
149
  return enabled unless @changed_active.include? type
150
+
147
151
  enabled = enabled.reject { |i| @off_by_type[type].include? i }
148
152
  enabled + @on_by_type[type].reject(&:passive)
149
153
  end
@@ -151,6 +155,7 @@ module R18n
151
155
  def all(type)
152
156
  enabled = Filters.enabled[type]
153
157
  return enabled unless @changed_types.include? type
158
+
154
159
  enabled = enabled.reject { |i| @off_by_type[type].include? i }
155
160
  enabled + @on_by_type[type]
156
161
  end
@@ -42,14 +42,14 @@ module R18n
42
42
  #
43
43
  # i18n.filtered('_') #=> "This_content_will_be_processed_by_filter!"
44
44
  #
45
- # Use String class as type to add global filter for all translated strings:
45
+ # Use `String` class as type to add global filter for all translated strings:
46
46
  #
47
47
  # R18n::Filters.add(String, :escape_html) do |content, config, params|
48
48
  # escape_html(content)
49
49
  # end
50
50
  #
51
51
  # Filter config contain two parameters: translation locale and path. But it is
52
- # Hash and you can add you own parameter to cross-filter communications:
52
+ # `Hash` and you can add you own parameter to cross-filter communications:
53
53
  #
54
54
  # R18n::Filters.add(String, :hide_truth) do |content, config|
55
55
  # return content if config[:censorship_check]
@@ -74,28 +74,28 @@ module R18n
74
74
  # i18n.filtered('_') #=> "This_content_will_be_processed_by_filter!"
75
75
  # R18n::Filters.delete(:no_space)
76
76
  #
77
- # You can enabled/disabled filters only for special I18n object:
77
+ # You can enabled/disabled filters only for special `I18n` object:
78
78
  #
79
79
  # R18n::I18n.new('en', nil, on_filters: [:untranslated_html, :no_space],
80
80
  # off_filters: :untranslated )
81
81
  module Filters
82
82
  class << self
83
- # Hash of filter names to Filters.
83
+ # `Hash` of filter names to Filters.
84
84
  attr_accessor :defined
85
85
 
86
- # Hash of types to all Filters.
86
+ # `Hash` of types to all Filters.
87
87
  attr_accessor :by_type
88
88
 
89
- # Hash of types to enabled active filters.
89
+ # `Hash` of types to enabled active filters.
90
90
  attr_accessor :active_enabled
91
91
 
92
- # Hash of types to enabled passive filters.
92
+ # `Hash` of types to enabled passive filters.
93
93
  attr_accessor :passive_enabled
94
94
 
95
- # Hash of types to enabled passive and active filters.
95
+ # `Hash` of types to enabled passive and active filters.
96
96
  attr_accessor :enabled
97
97
 
98
- # Rebuild +active_enabled+ and +passive_enabled+ for +type+.
98
+ # Rebuild `active_enabled` and `passive_enabled` for `type`.
99
99
  def rebuild_enabled!(type)
100
100
  @passive_enabled[type] = []
101
101
  @active_enabled[type] = []
@@ -103,6 +103,7 @@ module R18n
103
103
 
104
104
  @by_type[type].each do |filter|
105
105
  next unless filter.enabled?
106
+
106
107
  @enabled[type] << filter
107
108
  if filter.passive?
108
109
  @passive_enabled[type] << filter
@@ -112,17 +113,17 @@ module R18n
112
113
  end
113
114
  end
114
115
 
115
- # Add new filter for +type+ with +name+ and return filter object. You
116
- # can use String class as +type+ to add global filter for all translated
116
+ # Add new filter for `type` with `name` and return filter object. You
117
+ # can use `String` class as `type` to add global filter for all translated
117
118
  # string.
118
119
  #
119
- # Filter content will be sent to +block+ as first argument, struct with
120
+ # Filter content will be sent to `block` as first argument, struct with
120
121
  # config as second and filters parameters will be in next arguments.
121
122
  #
122
123
  # Options:
123
- # * +position+ – change order on processing several filters for same type.
124
+ # * `position` – change order on processing several filters for same type.
124
125
  # Note that passive filters will be always run before active.
125
- # * +passive+ – if +true+, filter will process only on translation
126
+ # * `passive` – if `true`, filter will process only on translation
126
127
  # loading. Note that you must add all passive before load translation.
127
128
  def add(types, name = nil, options = {}, &block)
128
129
  if name.is_a? Hash
@@ -161,7 +162,7 @@ module R18n
161
162
  filter
162
163
  end
163
164
 
164
- # Delete +filter+ by name or Filter object.
165
+ # Delete `filter` by name or Filter object.
165
166
  def delete(filter)
166
167
  filter = @defined[filter] unless filter.is_a? Filter
167
168
  return unless filter
@@ -173,7 +174,7 @@ module R18n
173
174
  end
174
175
  end
175
176
 
176
- # Disable +filter+ by name or Filter object.
177
+ # Disable `filter` by name or Filter object.
177
178
  def off(filter)
178
179
  filter = @defined[filter] unless filter.is_a? Filter
179
180
  return unless filter
@@ -182,7 +183,7 @@ module R18n
182
183
  filter.types.each { |type| rebuild_enabled! type }
183
184
  end
184
185
 
185
- # Turn on disabled +filter+ by name or Filter object.
186
+ # Turn on disabled `filter` by name or Filter object.
186
187
  def on(filter)
187
188
  filter = @defined[filter] unless filter.is_a? Filter
188
189
  return unless filter
@@ -191,7 +192,7 @@ module R18n
191
192
  filter.types.each { |type| rebuild_enabled! type }
192
193
  end
193
194
 
194
- # Return filters, which be added inside +block+.
195
+ # Return filters, which be added inside `block`.
195
196
  def listen(&_block)
196
197
  filters = []
197
198
  @new_filter_listener = proc { |i| filters << i }
@@ -222,12 +223,6 @@ module R18n
222
223
  end
223
224
  end
224
225
 
225
- Filters.add('proc', :procedure) do |content, _config, *params|
226
- # rubocop:disable Security/Eval
227
- eval("proc { #{content} }", nil, __FILE__, __LINE__).call(*params)
228
- # rubocop:enable Security/Eval
229
- end
230
-
231
226
  # Class to mark unpluralized translation.
232
227
  class UnpluralizetedTranslation < Translation
233
228
  end
@@ -310,8 +305,9 @@ module R18n
310
305
  content
311
306
  end
312
307
 
313
- Filters.add([String, 'markdown', 'textile'],
314
- :global_escape_html, passive: true) do |html, config|
308
+ Filters.add(
309
+ [String, 'markdown', 'textile'], :global_escape_html, passive: true
310
+ ) do |html, config|
315
311
  if config[:dont_escape_html]
316
312
  html
317
313
  else