r18n-core 2.2.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +5 -5
  2. data/.rspec +1 -1
  3. data/ChangeLog.md +6 -1
  4. data/README.md +1 -20
  5. data/Rakefile +5 -3
  6. data/lib/r18n-core.rb +55 -55
  7. data/lib/r18n-core/filter_list.rb +34 -36
  8. data/lib/r18n-core/filters.rb +68 -51
  9. data/lib/r18n-core/helpers.rb +17 -17
  10. data/lib/r18n-core/i18n.rb +46 -39
  11. data/lib/r18n-core/locale.rb +79 -70
  12. data/lib/r18n-core/translated.rb +65 -66
  13. data/lib/r18n-core/translated_string.rb +24 -24
  14. data/lib/r18n-core/translation.rb +31 -30
  15. data/lib/r18n-core/unsupported_locale.rb +22 -24
  16. data/lib/r18n-core/untranslated.rb +35 -33
  17. data/lib/r18n-core/utils.rb +26 -25
  18. data/lib/r18n-core/version.rb +4 -1
  19. data/lib/r18n-core/yaml_loader.rb +26 -25
  20. data/lib/r18n-core/yaml_methods.rb +25 -28
  21. data/locales/af.rb +15 -8
  22. data/locales/az.rb +19 -12
  23. data/locales/bg.rb +16 -9
  24. data/locales/ca.rb +16 -9
  25. data/locales/cs.rb +27 -20
  26. data/locales/da.rb +15 -8
  27. data/locales/de.rb +16 -9
  28. data/locales/en-au.rb +10 -5
  29. data/locales/en-gb.rb +12 -5
  30. data/locales/en-us.rb +12 -5
  31. data/locales/en.rb +29 -22
  32. data/locales/eo.rb +14 -7
  33. data/locales/es-us.rb +12 -5
  34. data/locales/es.rb +14 -7
  35. data/locales/fa.rb +48 -32
  36. data/locales/fi.rb +19 -12
  37. data/locales/fr.rb +22 -15
  38. data/locales/gl.rb +15 -8
  39. data/locales/hr.rb +24 -17
  40. data/locales/hu.rb +28 -21
  41. data/locales/id.rb +14 -7
  42. data/locales/it.rb +21 -14
  43. data/locales/ja.rb +15 -8
  44. data/locales/kk.rb +17 -10
  45. data/locales/ko.rb +15 -9
  46. data/locales/lv.rb +24 -17
  47. data/locales/mn.rb +10 -3
  48. data/locales/nb.rb +15 -8
  49. data/locales/nl.rb +15 -8
  50. data/locales/no.rb +11 -16
  51. data/locales/pl.rb +26 -19
  52. data/locales/pt-br.rb +12 -5
  53. data/locales/pt.rb +17 -10
  54. data/locales/ru.rb +26 -19
  55. data/locales/sk.rb +27 -20
  56. data/locales/sr-latn.rb +27 -22
  57. data/locales/sv-se.rb +15 -8
  58. data/locales/th.rb +27 -20
  59. data/locales/tr.rb +16 -9
  60. data/locales/uk.rb +19 -12
  61. data/locales/vi.rb +14 -7
  62. data/locales/zh-cn.rb +12 -5
  63. data/locales/zh-tw.rb +15 -8
  64. data/locales/zh.rb +14 -7
  65. data/r18n-core.gemspec +5 -3
  66. data/spec/filters_spec.rb +71 -67
  67. data/spec/i18n_spec.rb +73 -51
  68. data/spec/locale_spec.rb +73 -68
  69. data/spec/locales/cs_spec.rb +2 -2
  70. data/spec/locales/en-us_spec.rb +9 -9
  71. data/spec/locales/en_spec.rb +2 -2
  72. data/spec/locales/fa_spec.rb +3 -3
  73. data/spec/locales/fr_spec.rb +2 -2
  74. data/spec/locales/hu_spec.rb +7 -7
  75. data/spec/locales/it_spec.rb +3 -3
  76. data/spec/locales/no_spec.rb +9 -0
  77. data/spec/locales/pl_spec.rb +2 -2
  78. data/spec/locales/ru_spec.rb +2 -2
  79. data/spec/locales/sk_spec.rb +2 -2
  80. data/spec/locales/th_spec.rb +2 -2
  81. data/spec/locales/vi_spec.rb +2 -2
  82. data/spec/r18n_spec.rb +44 -38
  83. data/spec/spec_helper.rb +13 -9
  84. data/spec/translated_spec.rb +48 -31
  85. data/spec/translation_spec.rb +29 -27
  86. data/spec/translations/general/en.yml +0 -2
  87. data/spec/yaml_loader_spec.rb +22 -18
  88. metadata +5 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 710530bf79e2d31499094507a16c89fecda6c4be
4
- data.tar.gz: 2fd094bdbc14d67b78bddb7b827ce384f16320c0
2
+ SHA256:
3
+ metadata.gz: 832545b20bcd716bdbad20fcc65c3d1e64ccfd18475c23c55fdedb00e57ad6a7
4
+ data.tar.gz: d3a3476380d2a6579f2033298b3a4cdcab6d4995616e73f8e04f973d6f7bd04f
5
5
  SHA512:
6
- metadata.gz: 3e65ed82bdf22bdce12a170f7ac84512a8b9ad6d7c758bc090da96a03f9d0ccdf2038c81e33da1669c54847c1babcd85d4744a142d7f8d967d0162deb89e5efc
7
- data.tar.gz: d6b7573f5739b1723681a9aab973a8acf816b9fdbfd22233bf724b214eeadcb71096ee77b4f40478f3195631649eb2713a178175573c3fa95d3ae67e7a8eb46e
6
+ metadata.gz: 617afab79d7fc3a2193a74e276f862524c1571eaed8efd264aaab659d3a18c0605d1b7d7572d196ce251beda5feca86ff367d5d55c1e87cb91a646c4bc37c36c
7
+ data.tar.gz: 2dcb2f81f3a54a086bd6d4d207cb61e13789643d649507496a1924bc686902a53cc1b032c1ae8880eb084f93b167106d877a04520845024248659c49077e68b4
data/.rspec CHANGED
@@ -1 +1 @@
1
- --format documentation --colour
1
+ --format documentation --colour --warnings --require spec_helper
@@ -1,11 +1,16 @@
1
1
  # Change Log
2
2
 
3
+ ## 3.0 (New York)
4
+ * Deprecate `no` locale, use `nb` instead (by Alexander Popov).
5
+ * Remove unsafe `!!proc` filter.
6
+ * Reduce `eval` calls (by Alexander Popov).
7
+
3
8
  ## 2.2 (La Habana)
4
9
  * Change date format in `en` locale to `YYYY-MM-DD` (by Alexander Popov).
5
10
  * Add `TranslatedString#as_json` for ActiveSupport compatibility (by Tim Craft).
6
11
  * Fix `TranslatedString#html_safe?` behaviour (by Tim Craft).
7
12
  * Fix unsupported `LANG` environment (by Chris Poirier).
8
- * Fix `Locale#localize` method for `DateTime` objects (by Alexander Popov).s
13
+ * Fix `Locale#localize` method for `DateTime` objects (by Alexander Popov).
9
14
 
10
15
  ## 2.1.8 (Ѣ)
11
16
  * Fix `true` and `false` keys support (by Alexander Popov).
data/README.md CHANGED
@@ -281,25 +281,6 @@ alarm: !!textile
281
281
  t.alarm #=> "<p>It will delete <em>all</em> users!</p>"
282
282
  ```
283
283
 
284
- #### Lambdas
285
-
286
- You can use lambdas in your translations.
287
-
288
- ```yaml
289
- sum: !!proc |x, y| x + y
290
- ```
291
-
292
- ```ruby
293
- t.sum(1, 2) #=> 3
294
- ```
295
-
296
- If this is unsafe in your application (for example, user can change
297
- translations), you can disable it:
298
-
299
- ```ruby
300
- R18n::Filters.off(:procedure)
301
- ```
302
-
303
284
  ### Localization
304
285
 
305
286
  You can print numbers and floats according to the rules of the user locale:
@@ -456,7 +437,7 @@ simple:
456
437
  values.
457
438
  * If your country has alternate languages (for example, in exUSSR countries
458
439
  most people also know Russian), add
459
- <tt>sublocales %w{<i>another_locale</i> en}</tt>.
440
+ <tt>sublocales %w[<i>another_locale</i> en]</tt>.
460
441
  * Create in `base/` file <tt><i>code</i>.yml</tt> for your language and
461
442
  translate the base messages. Just copy file from language, which you know,
462
443
  and rewrite values.
data/Rakefile CHANGED
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/setup'
2
4
  Bundler::GemHelper.install_tasks
3
5
 
4
6
  require 'rspec/core/rake_task'
5
7
  RSpec::Core::RakeTask.new
6
- task :default => :spec
8
+ task default: :spec
7
9
 
8
10
  task :clobber_package do
9
- rm_r 'pkg' rescue nil
11
+ rm_rf 'pkg'
10
12
  end
11
- task :clobber => [:clobber_package]
13
+ task clobber: [:clobber_package]
@@ -1,55 +1,56 @@
1
- =begin
2
- Main file to load all neccessary classes for i18n support.
3
-
4
- Copyright (C) 2008 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
5
-
6
- This program is free software: you can redistribute it and/or modify
7
- it under the terms of the GNU Lesser General Public License as published by
8
- the Free Software Foundation, either version 3 of the License, or
9
- (at your option) any later version.
10
-
11
- This program is distributed in the hope that it will be useful,
12
- but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- GNU Lesser General Public License for more details.
15
-
16
- You should have received a copy of the GNU Lesser General Public License
17
- along with this program. If not, see <http://www.gnu.org/licenses/>.
18
- =end
19
-
20
- require 'pathname'
21
-
22
- dir = Pathname(__FILE__).dirname.expand_path + 'r18n-core'
23
- require dir.join('version').to_s
24
- require dir.join('utils').to_s
25
- require dir.join('locale').to_s
26
- require dir.join('unsupported_locale').to_s
27
- require dir.join('translated_string').to_s
28
- require dir.join('untranslated').to_s
29
- require dir.join('translation').to_s
30
- require dir.join('filters').to_s
31
- require dir.join('filter_list').to_s
32
- require dir.join('yaml_methods').to_s
33
- require dir.join('yaml_loader').to_s
34
- require dir.join('i18n').to_s
35
- require dir.join('helpers').to_s
1
+ # frozen_string_literal: true
2
+
3
+ # Main file to load all neccessary classes for i18n support.
4
+ #
5
+ # Copyright (C) 2008 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
6
+ #
7
+ # This program is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ %w[
21
+ version
22
+ utils
23
+ locale
24
+ unsupported_locale
25
+ translated_string
26
+ untranslated
27
+ translation
28
+ filters
29
+ filter_list
30
+ yaml_methods
31
+ yaml_loader
32
+ i18n
33
+ helpers
34
+ ].each do |file|
35
+ require_relative File.join('r18n-core', file)
36
+ end
36
37
 
37
38
  module R18n
38
39
  autoload :Translated, 'r18n-core/translated'
39
40
 
40
41
  class << self
41
-
42
42
  # Set I18n object globally. You can miss translation +places+, it will be
43
43
  # taken from <tt>R18n.default_places</tt>.
44
44
  def set(i18n = nil, places = R18n.default_places, &block)
45
- if block_given?
46
- @setter = block
47
- @i18n = nil
48
- elsif i18n.is_a? I18n
49
- @i18n = i18n
50
- else
51
- @i18n = I18n.new(i18n, places)
52
- end
45
+ @i18n =
46
+ if block_given?
47
+ @setter = block
48
+ nil
49
+ elsif i18n.is_a? I18n
50
+ i18n
51
+ else
52
+ I18n.new(i18n, places)
53
+ end
53
54
  end
54
55
 
55
56
  # Set I18n object to current thread.
@@ -65,14 +66,14 @@ module R18n
65
66
  # Get I18n object for current thread.
66
67
  def get
67
68
  thread[:r18n_i18n] ||
68
- (thread[:r18n_setter] && thread_set(thread[:r18n_setter].call)) ||
69
- @i18n ||
70
- (@setter && set(@setter.call))
69
+ (thread[:r18n_setter] && thread_set(thread[:r18n_setter].call)) ||
70
+ @i18n ||
71
+ (@setter && set(@setter.call))
71
72
  end
72
73
 
73
74
  # Clean translations cache.
74
75
  def clear_cache!
75
- self.cache = { }
76
+ self.cache = {}
76
77
  end
77
78
 
78
79
  # Delete I18n object from current thread and global variable.
@@ -82,7 +83,7 @@ module R18n
82
83
  end
83
84
 
84
85
  # Deprecated.
85
- alias :reset :reset!
86
+ alias reset reset!
86
87
 
87
88
  # Get the current thread.
88
89
  def thread
@@ -106,7 +107,7 @@ module R18n
106
107
  # - R18n.change(locale).t.language_title
107
108
  def change(locale)
108
109
  locale = locale.code if locale.is_a? Locale
109
- exists = get ? get.locales.map { |i| i.code } : []
110
+ exists = get ? get.locales.map(&:code) : []
110
111
  places = get ? get.translation_places : R18n.default_places
111
112
  R18n::I18n.new([locale] + exists, places)
112
113
  end
@@ -120,14 +121,14 @@ module R18n
120
121
  # Return Array of locales with available translations. You can miss
121
122
  # translation +places+, it will be taken from <tt>R18n.default_places</tt>.
122
123
  def available_locales(places = R18n.default_places)
123
- R18n::I18n.convert_places(places).map { |i| i.available }.flatten.uniq
124
+ R18n::I18n.convert_places(places).map(&:available).flatten.uniq
124
125
  end
125
126
 
126
127
  # Default places for <tt>R18n.set</tt> and <tt>R18n.available_locales</tt>.
127
128
  #
128
129
  # You can set block to calculate places dynamically:
129
130
  # R18n.default_places { settings.i18n_places }
130
- attr_accessor :default_places
131
+ attr_writer :default_places
131
132
 
132
133
  def default_places(&block)
133
134
  if block_given?
@@ -151,9 +152,8 @@ module R18n
151
152
  attr_accessor :cache
152
153
  end
153
154
 
154
- dir = Pathname(__FILE__).dirname.expand_path
155
155
  self.default_loader = R18n::Loader::YAML
156
156
  self.default_places = nil
157
- self.extension_places = [Loader::YAML.new(dir + '../base')]
158
- self.clear_cache!
157
+ self.extension_places = [Loader::YAML.new(File.join(__dir__, '..', 'base'))]
158
+ clear_cache!
159
159
  end
@@ -1,21 +1,21 @@
1
- =begin
2
- Filters for translations content.
3
-
4
- Copyright (C) 2012 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
5
-
6
- This program is free software: you can redistribute it and/or modify
7
- it under the terms of the GNU Lesser General Public License as published by
8
- the Free Software Foundation, either version 3 of the License, or
9
- (at your option) any later version.
10
-
11
- This program is distributed in the hope that it will be useful,
12
- but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- GNU Lesser General Public License for more details.
15
-
16
- You should have received a copy of the GNU Lesser General Public License
17
- along with this program. If not, see <http://www.gnu.org/licenses/>.
18
- =end
1
+ # frozen_string_literal: true
2
+
3
+ # Filters for translations content.
4
+ #
5
+ # Copyright (C) 2012 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
6
+ #
7
+ # This program is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
20
  module R18n
21
21
  # Superclass for +GlobalFilterList+ and +CustomFilterList+ with filters
@@ -49,9 +49,8 @@ module R18n
49
49
 
50
50
  # Process +value+ by global filters in +enabled+.
51
51
  def process_string(filters_type, value, config, params)
52
- if config.is_a? String
53
- config = { locale: value.locale, path: config }
54
- end
52
+ config = { locale: value.locale, path: config } if config.is_a? String
53
+
55
54
  enabled(filters_type, String).each do |f|
56
55
  value = f.call(value, config, *params)
57
56
  end
@@ -75,17 +74,17 @@ module R18n
75
74
  end
76
75
 
77
76
  # List of enable passive filters.
78
- def passive(type)
77
+ def passive(_type)
79
78
  []
80
79
  end
81
80
 
82
81
  # List of enable active filters.
83
- def active(type)
82
+ def active(_type)
84
83
  []
85
84
  end
86
85
 
87
86
  # List of enable filters.
88
- def all(type)
87
+ def all(_type)
89
88
  []
90
89
  end
91
90
  end
@@ -109,16 +108,15 @@ module R18n
109
108
 
110
109
  # Filter list for I18n object with custom disabled/enabled filters.
111
110
  class CustomFilterList < FilterList
112
-
113
111
  def initialize(on, off)
114
112
  @on = Array(on).map { |i| Filters.defined[i] }
115
113
  @off = Array(off).map { |i| Filters.defined[i] }
116
- @changed_types = (@on + @off).map { |i| i.types }.flatten.uniq
114
+ @changed_types = (@on + @off).map(&:types).flatten.uniq
117
115
 
118
- @changed_passive = (@on + @off).reject { |i| !i.passive? }.
119
- map { |i| i.types }.flatten.uniq
120
- @changed_active = (@on + @off).reject { |i| i.passive? }.
121
- map { |i| i.types }.flatten.uniq
116
+ @changed_passive = (@on + @off).select(&:passive?)
117
+ .map(&:types).flatten.uniq
118
+ @changed_active = (@on + @off).reject(&:passive?)
119
+ .map(&:types).flatten.uniq
122
120
 
123
121
  @on_by_type = {}
124
122
  @on.each do |filter|
@@ -139,22 +137,22 @@ module R18n
139
137
  def passive(type)
140
138
  enabled = Filters.passive_enabled[type]
141
139
  return enabled unless @changed_passive.include? type
142
- enabled = enabled.reject { |i| @off_by_type[type].include? i }
143
- enabled += @on_by_type[type].reject { |i| !i.passive }
140
+ enabled = enabled.reject { |i| @off_by_type[type].include? i }
141
+ enabled + @on_by_type[type].select(&:passive)
144
142
  end
145
143
 
146
144
  def active(type)
147
145
  enabled = Filters.active_enabled[type]
148
146
  return enabled unless @changed_active.include? type
149
- enabled = enabled.reject { |i| @off_by_type[type].include? i }
150
- enabled += @on_by_type[type].reject { |i| i.passive }
147
+ enabled = enabled.reject { |i| @off_by_type[type].include? i }
148
+ enabled + @on_by_type[type].reject(&:passive)
151
149
  end
152
150
 
153
151
  def all(type)
154
152
  enabled = Filters.enabled[type]
155
153
  return enabled unless @changed_types.include? type
156
- enabled = enabled.reject { |i| @off_by_type[type].include? i }
157
- enabled += @on_by_type[type]
154
+ enabled = enabled.reject { |i| @off_by_type[type].include? i }
155
+ enabled + @on_by_type[type]
158
156
  end
159
157
 
160
158
  def hash
@@ -1,24 +1,25 @@
1
- =begin
2
- Filters for translations content.
3
-
4
- Copyright (C) 2009 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
5
-
6
- This program is free software: you can redistribute it and/or modify
7
- it under the terms of the GNU Lesser General Public License as published by
8
- the Free Software Foundation, either version 3 of the License, or
9
- (at your option) any later version.
10
-
11
- This program is distributed in the hope that it will be useful,
12
- but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- GNU Lesser General Public License for more details.
15
-
16
- You should have received a copy of the GNU Lesser General Public License
17
- along with this program. If not, see <http://www.gnu.org/licenses/>.
18
- =end
1
+ # frozen_string_literal: true
2
+
3
+ # Filters for translations content.
4
+ #
5
+ # Copyright (C) 2009 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
6
+ #
7
+ # This program is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
20
  require 'ostruct'
21
21
 
22
+ # R18n filters definition
22
23
  module R18n
23
24
  # Filter is a way, to process translations: escape HTML entries, convert from
24
25
  # Markdown syntax, etc.
@@ -101,13 +102,12 @@ module R18n
101
102
  @enabled[type] = []
102
103
 
103
104
  @by_type[type].each do |filter|
104
- if filter.enabled?
105
- @enabled[type] << filter
106
- if filter.passive?
107
- @passive_enabled[type] << filter
108
- else
109
- @active_enabled[type] << filter
110
- end
105
+ next unless filter.enabled?
106
+ @enabled[type] << filter
107
+ if filter.passive?
108
+ @passive_enabled[type] << filter
109
+ else
110
+ @active_enabled[type] << filter
111
111
  end
112
112
  end
113
113
  end
@@ -125,25 +125,29 @@ module R18n
125
125
  # * +passive+ – if +true+, filter will process only on translation
126
126
  # loading. Note that you must add all passive before load translation.
127
127
  def add(types, name = nil, options = {}, &block)
128
- options, name = name, nil if name.is_a? Hash
128
+ if name.is_a? Hash
129
+ options = name
130
+ name = nil
131
+ end
129
132
  types = Array(types)
130
133
 
131
- unless name
134
+ if name
135
+ delete(name)
136
+ else
132
137
  @last_auto_name ||= 0
133
- begin
138
+ loop do
134
139
  @last_auto_name += 1
135
140
  name = @last_auto_name
136
- end while defined.has_key? name
137
- else
138
- delete(name)
141
+ break unless defined.key? name
142
+ end
139
143
  end
140
144
 
141
145
  filter = Filter.new(name, types, block, true, options[:passive])
142
146
  @defined[name] = filter
143
147
 
144
148
  types.each do |type|
145
- @by_type[type] = [] unless @by_type.has_key? type
146
- if options.has_key? :position
149
+ @by_type[type] = [] unless @by_type.key? type
150
+ if options.key? :position
147
151
  @by_type[type].insert(options[:position], filter)
148
152
  else
149
153
  @by_type[type] << filter
@@ -151,7 +155,9 @@ module R18n
151
155
  rebuild_enabled! type
152
156
  end
153
157
 
154
- @new_filter_listener.call(filter) if @new_filter_listener
158
+ if defined?(@new_filter_listener) && @new_filter_listener.is_a?(Proc)
159
+ @new_filter_listener.call(filter)
160
+ end
155
161
  filter
156
162
  end
157
163
 
@@ -186,7 +192,7 @@ module R18n
186
192
  end
187
193
 
188
194
  # Return filters, which be added inside +block+.
189
- def listen(&block)
195
+ def listen(&_block)
190
196
  filters = []
191
197
  @new_filter_listener = proc { |i| filters << i }
192
198
  yield
@@ -202,14 +208,24 @@ module R18n
202
208
  Filters.enabled = Hash.new([])
203
209
 
204
210
  Filter = Struct.new(:name, :types, :block, :enabled, :passive) do
205
- def call(*params); block.call(*params); end
206
- def enabled?; enabled; end
207
- def passive?; passive; end
211
+ def call(*params)
212
+ block.call(*params)
213
+ end
214
+
215
+ def enabled?
216
+ enabled
217
+ end
218
+
219
+ def passive?
220
+ passive
221
+ end
208
222
  end
209
223
  end
210
224
 
211
- Filters.add('proc', :procedure) do |content, config, *params|
212
- eval("proc { #{content} }").call(*params)
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
213
229
  end
214
230
 
215
231
  # Class to mark unpluralized translation.
@@ -220,11 +236,13 @@ module R18n
220
236
  param = param.to_i if param.is_a? Float
221
237
  if param.is_a? Numeric
222
238
  type = config[:locale].pluralize(param)
223
- type = 'n' if not content.has_key? type
239
+ type = 'n' unless content.key? type
224
240
  content[type]
225
241
  else
226
- UnpluralizetedTranslation.new(config[:locale], config[:path],
227
- locale: config[:locale], translations: content)
242
+ UnpluralizetedTranslation.new(
243
+ config[:locale], config[:path],
244
+ locale: config[:locale], translations: content
245
+ )
228
246
  end
229
247
  end
230
248
 
@@ -244,25 +262,24 @@ module R18n
244
262
  end
245
263
  end
246
264
 
247
- Filters.add(Untranslated, :untranslated) do |v, c, translated, untranslated|
265
+ Filters.add(Untranslated, :untranslated) do |_v, _c, translated, untranslated|
248
266
  "#{translated}[#{untranslated}]"
249
267
  end
250
268
 
251
- Filters.add(Untranslated, :untranslated_bash) do |v, c, transl, untransl|
269
+ Filters.add(Untranslated, :untranslated_bash) do |_v, _c, transl, untransl|
252
270
  "#{transl}\e[0;31m[#{untransl}]\e[0m"
253
271
  end
254
272
  Filters.off(:untranslated_bash)
255
273
 
256
- Filters.add(Untranslated, :untranslated_html) do |v, c, transl, untransl|
274
+ Filters.add(Untranslated, :untranslated_html) do |_v, _c, transl, untransl|
257
275
  prefix = '<span style="color: red">['
258
276
  postfix = ']</span>'
259
277
  if prefix.respond_to? :html_safe
260
278
  prefix = prefix.html_safe
261
279
  postfix = postfix.html_safe
262
- transl << prefix << untransl << postfix
280
+ transl + prefix + untransl + postfix
263
281
  else
264
- Utils.escape_html(transl) <<
265
- prefix << Utils.escape_html(untransl) << postfix
282
+ Utils.escape_html(transl) + prefix + Utils.escape_html(untransl) + postfix
266
283
  end
267
284
  end
268
285
  Filters.off(:untranslated_html)
@@ -288,12 +305,12 @@ module R18n
288
305
  end
289
306
  Filters.off(:global_escape_html)
290
307
 
291
- Filters.add('markdown', :kramdown, passive: true) do |content, config|
308
+ Filters.add('markdown', :kramdown, passive: true) do |content, _config|
292
309
  require 'kramdown'
293
310
  ::Kramdown::Document.new(content).to_html
294
311
  end
295
312
 
296
- Filters.add('textile', :redcloth, passive: true) do |content, config|
313
+ Filters.add('textile', :redcloth, passive: true) do |content, _config|
297
314
  require 'redcloth'
298
315
  ::RedCloth.new(content).to_html
299
316
  end