r18n-core 2.2.0 → 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.
- checksums.yaml +5 -5
- data/.rspec +1 -1
- data/ChangeLog.md +6 -1
- data/README.md +1 -20
- data/Rakefile +5 -3
- data/lib/r18n-core.rb +55 -55
- data/lib/r18n-core/filter_list.rb +34 -36
- data/lib/r18n-core/filters.rb +68 -51
- data/lib/r18n-core/helpers.rb +17 -17
- data/lib/r18n-core/i18n.rb +46 -39
- data/lib/r18n-core/locale.rb +79 -70
- data/lib/r18n-core/translated.rb +65 -66
- data/lib/r18n-core/translated_string.rb +24 -24
- data/lib/r18n-core/translation.rb +31 -30
- data/lib/r18n-core/unsupported_locale.rb +22 -24
- data/lib/r18n-core/untranslated.rb +35 -33
- data/lib/r18n-core/utils.rb +26 -25
- data/lib/r18n-core/version.rb +4 -1
- data/lib/r18n-core/yaml_loader.rb +26 -25
- data/lib/r18n-core/yaml_methods.rb +25 -28
- data/locales/af.rb +15 -8
- data/locales/az.rb +19 -12
- data/locales/bg.rb +16 -9
- data/locales/ca.rb +16 -9
- data/locales/cs.rb +27 -20
- data/locales/da.rb +15 -8
- data/locales/de.rb +16 -9
- data/locales/en-au.rb +10 -5
- data/locales/en-gb.rb +12 -5
- data/locales/en-us.rb +12 -5
- data/locales/en.rb +29 -22
- data/locales/eo.rb +14 -7
- data/locales/es-us.rb +12 -5
- data/locales/es.rb +14 -7
- data/locales/fa.rb +48 -32
- data/locales/fi.rb +19 -12
- data/locales/fr.rb +22 -15
- data/locales/gl.rb +15 -8
- data/locales/hr.rb +24 -17
- data/locales/hu.rb +28 -21
- data/locales/id.rb +14 -7
- data/locales/it.rb +21 -14
- data/locales/ja.rb +15 -8
- data/locales/kk.rb +17 -10
- data/locales/ko.rb +15 -9
- data/locales/lv.rb +24 -17
- data/locales/mn.rb +10 -3
- data/locales/nb.rb +15 -8
- data/locales/nl.rb +15 -8
- data/locales/no.rb +11 -16
- data/locales/pl.rb +26 -19
- data/locales/pt-br.rb +12 -5
- data/locales/pt.rb +17 -10
- data/locales/ru.rb +26 -19
- data/locales/sk.rb +27 -20
- data/locales/sr-latn.rb +27 -22
- data/locales/sv-se.rb +15 -8
- data/locales/th.rb +27 -20
- data/locales/tr.rb +16 -9
- data/locales/uk.rb +19 -12
- data/locales/vi.rb +14 -7
- data/locales/zh-cn.rb +12 -5
- data/locales/zh-tw.rb +15 -8
- data/locales/zh.rb +14 -7
- data/r18n-core.gemspec +5 -3
- data/spec/filters_spec.rb +71 -67
- data/spec/i18n_spec.rb +73 -51
- data/spec/locale_spec.rb +73 -68
- data/spec/locales/cs_spec.rb +2 -2
- data/spec/locales/en-us_spec.rb +9 -9
- data/spec/locales/en_spec.rb +2 -2
- data/spec/locales/fa_spec.rb +3 -3
- data/spec/locales/fr_spec.rb +2 -2
- data/spec/locales/hu_spec.rb +7 -7
- data/spec/locales/it_spec.rb +3 -3
- data/spec/locales/no_spec.rb +9 -0
- data/spec/locales/pl_spec.rb +2 -2
- data/spec/locales/ru_spec.rb +2 -2
- data/spec/locales/sk_spec.rb +2 -2
- data/spec/locales/th_spec.rb +2 -2
- data/spec/locales/vi_spec.rb +2 -2
- data/spec/r18n_spec.rb +44 -38
- data/spec/spec_helper.rb +13 -9
- data/spec/translated_spec.rb +48 -31
- data/spec/translation_spec.rb +29 -27
- data/spec/translations/general/en.yml +0 -2
- data/spec/yaml_loader_spec.rb +22 -18
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 832545b20bcd716bdbad20fcc65c3d1e64ccfd18475c23c55fdedb00e57ad6a7
|
4
|
+
data.tar.gz: d3a3476380d2a6579f2033298b3a4cdcab6d4995616e73f8e04f973d6f7bd04f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/ChangeLog.md
CHANGED
@@ -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).
|
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
|
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 :
|
8
|
+
task default: :spec
|
7
9
|
|
8
10
|
task :clobber_package do
|
9
|
-
|
11
|
+
rm_rf 'pkg'
|
10
12
|
end
|
11
|
-
task :
|
13
|
+
task clobber: [:clobber_package]
|
data/lib/r18n-core.rb
CHANGED
@@ -1,55 +1,56 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
the
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
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
|
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
|
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
|
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
|
-
|
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(
|
158
|
-
|
157
|
+
self.extension_places = [Loader::YAML.new(File.join(__dir__, '..', 'base'))]
|
158
|
+
clear_cache!
|
159
159
|
end
|
@@ -1,21 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
the
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
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(
|
77
|
+
def passive(_type)
|
79
78
|
[]
|
80
79
|
end
|
81
80
|
|
82
81
|
# List of enable active filters.
|
83
|
-
def active(
|
82
|
+
def active(_type)
|
84
83
|
[]
|
85
84
|
end
|
86
85
|
|
87
86
|
# List of enable filters.
|
88
|
-
def all(
|
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
|
114
|
+
@changed_types = (@on + @off).map(&:types).flatten.uniq
|
117
115
|
|
118
|
-
@changed_passive = (@on + @off).
|
119
|
-
map
|
120
|
-
@changed_active = (@on + @off).reject
|
121
|
-
map
|
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
|
143
|
-
enabled
|
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
|
150
|
-
enabled
|
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
|
157
|
-
enabled
|
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
|
data/lib/r18n-core/filters.rb
CHANGED
@@ -1,24 +1,25 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
the
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
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
|
-
|
128
|
+
if name.is_a? Hash
|
129
|
+
options = name
|
130
|
+
name = nil
|
131
|
+
end
|
129
132
|
types = Array(types)
|
130
133
|
|
131
|
-
|
134
|
+
if name
|
135
|
+
delete(name)
|
136
|
+
else
|
132
137
|
@last_auto_name ||= 0
|
133
|
-
|
138
|
+
loop do
|
134
139
|
@last_auto_name += 1
|
135
140
|
name = @last_auto_name
|
136
|
-
|
137
|
-
|
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.
|
146
|
-
if options.
|
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
|
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(&
|
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)
|
206
|
-
|
207
|
-
|
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,
|
212
|
-
|
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'
|
239
|
+
type = 'n' unless content.key? type
|
224
240
|
content[type]
|
225
241
|
else
|
226
|
-
UnpluralizetedTranslation.new(
|
227
|
-
|
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 |
|
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 |
|
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 |
|
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
|
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,
|
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,
|
313
|
+
Filters.add('textile', :redcloth, passive: true) do |content, _config|
|
297
314
|
require 'redcloth'
|
298
315
|
::RedCloth.new(content).to_html
|
299
316
|
end
|