r18n-core 1.1.11 → 2.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 +4 -4
- data/ChangeLog.md +4 -0
- data/README.md +2 -2
- data/lib/r18n-core/filter_list.rb +2 -3
- data/lib/r18n-core/filters.rb +9 -10
- data/lib/r18n-core/helpers.rb +0 -1
- data/lib/r18n-core/i18n.rb +1 -2
- data/lib/r18n-core/locale.rb +10 -12
- data/lib/r18n-core/translated.rb +3 -4
- data/lib/r18n-core/translated_string.rb +0 -1
- data/lib/r18n-core/translation.rb +2 -3
- data/lib/r18n-core/unsupported_locale.rb +0 -1
- data/lib/r18n-core/untranslated.rb +0 -1
- data/lib/r18n-core/utils.rb +0 -11
- data/lib/r18n-core/version.rb +1 -2
- data/lib/r18n-core/yaml_loader.rb +0 -1
- data/lib/r18n-core/yaml_methods.rb +2 -8
- data/lib/r18n-core.rb +0 -3
- data/locales/bg.rb +11 -13
- data/locales/ca.rb +13 -14
- data/locales/cs.rb +15 -16
- data/locales/da.rb +13 -15
- data/locales/de.rb +14 -15
- data/locales/en-au.rb +2 -2
- data/locales/en-gb.rb +2 -2
- data/locales/en-us.rb +5 -7
- data/locales/en.rb +14 -14
- data/locales/eo.rb +11 -12
- data/locales/es-us.rb +6 -8
- data/locales/es.rb +11 -12
- data/locales/fi.rb +16 -17
- data/locales/fr.rb +10 -11
- data/locales/gl.rb +12 -13
- data/locales/hr.rb +12 -13
- data/locales/hu.rb +12 -13
- data/locales/id.rb +9 -9
- data/locales/it.rb +9 -10
- data/locales/ja.rb +11 -12
- data/locales/kk.rb +16 -18
- data/locales/lv.rb +16 -17
- data/locales/mn.rb +12 -14
- data/locales/nb.rb +12 -13
- data/locales/nl.rb +13 -14
- data/locales/no.rb +12 -13
- data/locales/pl.rb +13 -14
- data/locales/pt-br.rb +2 -3
- data/locales/pt.rb +13 -14
- data/locales/ru.rb +14 -15
- data/locales/sk.rb +15 -16
- data/locales/sr-latn.rb +12 -14
- data/locales/sv-se.rb +11 -13
- data/locales/th.rb +13 -14
- data/locales/tr.rb +12 -15
- data/locales/uk.rb +11 -15
- data/locales/zh-cn.rb +2 -3
- data/locales/zh-tw.rb +5 -6
- data/locales/zh.rb +10 -11
- data/r18n-core.gemspec +5 -4
- data/spec/filters_spec.rb +94 -91
- data/spec/i18n_spec.rb +66 -68
- data/spec/locale_spec.rb +74 -74
- data/spec/locales/cs_spec.rb +14 -14
- data/spec/locales/en-us_spec.rb +6 -6
- data/spec/locales/en_spec.rb +6 -6
- data/spec/locales/fr_spec.rb +2 -2
- data/spec/locales/hu_spec.rb +6 -7
- data/spec/locales/it_spec.rb +3 -4
- data/spec/locales/pl_spec.rb +14 -14
- data/spec/locales/ru_spec.rb +13 -13
- data/spec/locales/sk_spec.rb +14 -14
- data/spec/locales/th_spec.rb +2 -2
- data/spec/r18n_spec.rb +47 -49
- data/spec/spec_helper.rb +0 -7
- data/spec/translated_spec.rb +26 -28
- data/spec/translation_spec.rb +38 -40
- data/spec/yaml_loader_spec.rb +14 -16
- metadata +2 -2
data/spec/filters_spec.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
require File.expand_path('../spec_helper', __FILE__)
|
3
2
|
|
4
3
|
describe R18n::Filters do
|
@@ -22,79 +21,79 @@ describe R18n::Filters do
|
|
22
21
|
it "adds new filter" do
|
23
22
|
filter = R18n::Filters.add('my', :my_filter) { |i, config| i }
|
24
23
|
|
25
|
-
filter.
|
26
|
-
filter.name.
|
27
|
-
filter.types.
|
28
|
-
filter.
|
24
|
+
expect(filter).to be_kind_of(R18n::Filters::Filter)
|
25
|
+
expect(filter.name).to eq(:my_filter)
|
26
|
+
expect(filter.types).to eq(['my'])
|
27
|
+
expect(filter).to be_enabled
|
29
28
|
|
30
|
-
R18n::Filters.defined.
|
29
|
+
expect(R18n::Filters.defined).to have_key(:my_filter)
|
31
30
|
|
32
31
|
@i18n.reload!
|
33
|
-
@i18n.my_filter.
|
34
|
-
@i18n.my_tree_filter.
|
32
|
+
expect(@i18n.my_filter).to eq('value')
|
33
|
+
expect(@i18n.my_tree_filter).to eq({'name' => 'value'})
|
35
34
|
end
|
36
35
|
|
37
36
|
it "adds filter for several types" do
|
38
37
|
filter = R18n::Filters.add(['my', 'your']) { |i, config| i + '1' }
|
39
38
|
@i18n.reload!
|
40
|
-
@i18n.my_filter.
|
41
|
-
@i18n.your_filter.
|
39
|
+
expect(@i18n.my_filter).to eq('value1')
|
40
|
+
expect(@i18n.your_filter).to eq('another1')
|
42
41
|
end
|
43
42
|
|
44
43
|
it "uses passive filters" do
|
45
44
|
filter = double()
|
46
|
-
filter.
|
45
|
+
expect(filter).to receive(:process).twice.and_return(1)
|
47
46
|
|
48
|
-
R18n::Filters.add('my', :passive, :
|
47
|
+
R18n::Filters.add('my', :passive, passive: true) { filter.process }
|
49
48
|
|
50
|
-
@i18n.my_filter.
|
49
|
+
expect(@i18n.my_filter).to eq('value')
|
51
50
|
@i18n.reload!
|
52
51
|
|
53
|
-
@i18n.my_tree_filter.
|
54
|
-
@i18n.my_filter.
|
55
|
-
@i18n.my_filter.
|
52
|
+
expect(@i18n.my_tree_filter).to eq(1)
|
53
|
+
expect(@i18n.my_filter).to eq(1)
|
54
|
+
expect(@i18n.my_filter).to eq(1)
|
56
55
|
end
|
57
56
|
|
58
57
|
it "uses cascade filters" do
|
59
58
|
filter = R18n::Filters.add('my', :one) { |i, config| i + '1' }
|
60
59
|
filter = R18n::Filters.add('my', :two) { |i, config| i + '2' }
|
61
|
-
filter = R18n::Filters.add('my', :three, :
|
62
|
-
@i18n.my_filter.
|
60
|
+
filter = R18n::Filters.add('my', :three, position: 0) { |i, c| i + '3' }
|
61
|
+
expect(@i18n.my_filter).to eq('value312')
|
63
62
|
end
|
64
63
|
|
65
64
|
it "returns name for nameless filter" do
|
66
65
|
R18n::Filters.instance_variable_set(:@last_auto_name, 0)
|
67
66
|
|
68
|
-
R18n::Filters.add('some').name.
|
69
|
-
R18n::Filters.add('some', :
|
67
|
+
expect(R18n::Filters.add('some').name).to eq(1)
|
68
|
+
expect(R18n::Filters.add('some', position: 0).name).to eq(2)
|
70
69
|
|
71
70
|
R18n::Filters.add('some', 3)
|
72
|
-
R18n::Filters.add('some').name.
|
71
|
+
expect(R18n::Filters.add('some').name).to eq(4)
|
73
72
|
end
|
74
73
|
|
75
74
|
it "deletes filter by name" do
|
76
75
|
R18n::Filters.add('my', :my_filter) { '1' }
|
77
|
-
@i18n.my_filter.
|
76
|
+
expect(@i18n.my_filter).to eq('1')
|
78
77
|
|
79
78
|
R18n::Filters.delete(:my_filter)
|
80
|
-
R18n::Filters.defined.
|
81
|
-
@i18n.my_filter.
|
79
|
+
expect(R18n::Filters.defined).not_to have_key(:my_filter)
|
80
|
+
expect(@i18n.my_filter).to eq('value')
|
82
81
|
end
|
83
82
|
|
84
83
|
it "deletes filter by object" do
|
85
84
|
filter = R18n::Filters.add('my') { '1' }
|
86
|
-
@i18n.my_filter.
|
85
|
+
expect(@i18n.my_filter).to eq('1')
|
87
86
|
|
88
87
|
R18n::Filters.delete(filter)
|
89
|
-
R18n::Filters.defined.
|
90
|
-
@i18n.my_filter.
|
88
|
+
expect(R18n::Filters.defined).not_to have_key(filter.name)
|
89
|
+
expect(@i18n.my_filter).to eq('value')
|
91
90
|
end
|
92
91
|
|
93
92
|
it "uses global filters" do
|
94
93
|
R18n::Filters.add(String) { |result, config, a, b| result + a + b }
|
95
94
|
R18n::Filters.add(String) { |result, config| result + '!' }
|
96
95
|
|
97
|
-
@i18n.one('1', '2').
|
96
|
+
expect(@i18n.one('1', '2')).to eq('One12!')
|
98
97
|
end
|
99
98
|
|
100
99
|
it "turns off filter" do
|
@@ -102,12 +101,12 @@ describe R18n::Filters do
|
|
102
101
|
filter = R18n::Filters.add('my', :two) { |i, config| i + '2' }
|
103
102
|
|
104
103
|
R18n::Filters.off(:one)
|
105
|
-
R18n::Filters.defined[:one].
|
106
|
-
@i18n.my_filter.
|
104
|
+
expect(R18n::Filters.defined[:one]).not_to be_enabled
|
105
|
+
expect(@i18n.my_filter).to eq('value2')
|
107
106
|
|
108
107
|
R18n::Filters.on(:one)
|
109
|
-
R18n::Filters.defined[:one].
|
110
|
-
@i18n.my_filter.
|
108
|
+
expect(R18n::Filters.defined[:one]).to be_enabled
|
109
|
+
expect(@i18n.my_filter).to eq('value12')
|
111
110
|
end
|
112
111
|
|
113
112
|
it "sends config to filter" do
|
@@ -115,10 +114,10 @@ describe R18n::Filters do
|
|
115
114
|
config[:secret_value] = 1
|
116
115
|
config
|
117
116
|
end
|
118
|
-
@i18n.my_filter[:locale].
|
119
|
-
@i18n.my_filter[:path].
|
120
|
-
@i18n.my_filter[:secret_value].
|
121
|
-
@i18n.my_filter[:unknown_value].
|
117
|
+
expect(@i18n.my_filter[:locale]).to eq(@i18n.locale)
|
118
|
+
expect(@i18n.my_filter[:path]).to eq('my_filter')
|
119
|
+
expect(@i18n.my_filter[:secret_value]).to eq(1)
|
120
|
+
expect(@i18n.my_filter[:unknown_value]).to be_nil
|
122
121
|
end
|
123
122
|
|
124
123
|
it "sets path in config" do
|
@@ -126,164 +125,169 @@ describe R18n::Filters do
|
|
126
125
|
config[:path]
|
127
126
|
end
|
128
127
|
|
129
|
-
@i18n.in.another.level.
|
128
|
+
expect(@i18n.in.another.level).to eq('in.another.level')
|
130
129
|
end
|
131
130
|
|
132
131
|
it "returns translated string after filters" do
|
133
132
|
R18n::Filters.add(String) { |i, config| i + '1' }
|
134
133
|
|
135
|
-
@i18n.one.
|
136
|
-
@i18n.one.path.
|
137
|
-
@i18n.one.locale.
|
134
|
+
expect(@i18n.one).to be_kind_of(R18n::TranslatedString)
|
135
|
+
expect(@i18n.one.path).to eq('one')
|
136
|
+
expect(@i18n.one.locale).to eq(R18n.locale('en'))
|
138
137
|
end
|
139
138
|
|
140
139
|
it "uses one config for cascade filters" do
|
141
140
|
R18n::Filters.add('my') { |content, config| config[:new_secret] ? 2 : 1 }
|
142
|
-
@i18n.my_filter.
|
141
|
+
expect(@i18n.my_filter).to eq(1)
|
143
142
|
|
144
|
-
R18n::Filters.add('my', :second, :
|
143
|
+
R18n::Filters.add('my', :second, position: 0) do |content, config|
|
145
144
|
config[:new_secret] = true
|
146
145
|
content
|
147
146
|
end
|
148
|
-
@i18n.my_filter.
|
147
|
+
expect(@i18n.my_filter).to eq(2)
|
149
148
|
end
|
150
149
|
|
151
150
|
it "sends parameters to filter" do
|
152
151
|
R18n::Filters.add('my') { |i, config, a, b| "#{i}#{a}#{b}" }
|
153
|
-
@i18n['my_filter', 1, 2].
|
154
|
-
@i18n.my_filter(1, 2).
|
152
|
+
expect(@i18n['my_filter', 1, 2]).to eq('value12')
|
153
|
+
expect(@i18n.my_filter(1, 2)).to eq('value12')
|
155
154
|
end
|
156
155
|
|
157
156
|
it "calls proc from translation" do
|
158
|
-
@i18n.sum(2, 3).
|
157
|
+
expect(@i18n.sum(2, 3)).to eq(5)
|
159
158
|
end
|
160
159
|
|
161
160
|
it "pluralizes translation" do
|
162
|
-
@i18n.comments(0, 'article').
|
163
|
-
@i18n.comments(1, 'article').
|
164
|
-
@i18n.comments(5, 'article').
|
161
|
+
expect(@i18n.comments(0, 'article')).to eq('no comments for article')
|
162
|
+
expect(@i18n.comments(1, 'article')).to eq('one comment for article')
|
163
|
+
expect(@i18n.comments(5, 'article')).to eq('5 comments for article')
|
165
164
|
|
166
|
-
@i18n.files(0).
|
167
|
-
@i18n.files(-5.5).
|
168
|
-
@i18n.files(5000).
|
165
|
+
expect(@i18n.files(0)).to eq('0 files')
|
166
|
+
expect(@i18n.files(-5.5)).to eq('−5.5 files')
|
167
|
+
expect(@i18n.files(5000)).to eq('5,000 files')
|
169
168
|
end
|
170
169
|
|
171
170
|
it "doesn't pluralize without first numeric parameter" do
|
172
|
-
@i18n.files.
|
173
|
-
@i18n.files('').
|
174
|
-
@i18n.files[1].
|
175
|
-
@i18n.files.n(5).
|
171
|
+
expect(@i18n.files).to be_kind_of(R18n::UnpluralizetedTranslation)
|
172
|
+
expect(@i18n.files('')).to be_kind_of(R18n::UnpluralizetedTranslation)
|
173
|
+
expect(@i18n.files[1]).to eq('1 file')
|
174
|
+
expect(@i18n.files.n(5)).to eq('5 files')
|
176
175
|
end
|
177
176
|
|
178
177
|
it "converts first float parameter to number" do
|
179
|
-
@i18n.files(1.2).
|
178
|
+
expect(@i18n.files(1.2)).to eq('1 file')
|
180
179
|
end
|
181
180
|
|
182
181
|
it "pluralizes translation without locale" do
|
183
182
|
i18n = R18n::I18n.new('nolocale', DIR)
|
184
|
-
i18n.entries(1).
|
185
|
-
i18n.entries(5).
|
183
|
+
expect(i18n.entries(1)).to eq('ONE')
|
184
|
+
expect(i18n.entries(5)).to eq('N')
|
186
185
|
end
|
187
186
|
|
188
187
|
it "cans use params in translation" do
|
189
|
-
@i18n.params(-1, 2).
|
188
|
+
expect(@i18n.params(-1, 2)).to eq('Is −1 between −1 and 2?')
|
190
189
|
end
|
191
190
|
|
192
191
|
it "substitutes '%2' as param but not value of second param" do
|
193
|
-
@i18n.params('%2 FIRST', 'SECOND').
|
192
|
+
expect(@i18n.params('%2 FIRST', 'SECOND')).to eq(
|
194
193
|
'Is %2 FIRST between %2 FIRST and SECOND?'
|
194
|
+
)
|
195
195
|
end
|
196
196
|
|
197
197
|
it "formats untranslated" do
|
198
|
-
@i18n.in.not.to_s.
|
199
|
-
@i18n.in.not.to_str.
|
198
|
+
expect(@i18n.in.not.to_s).to eq('in.[not]')
|
199
|
+
expect(@i18n.in.not.to_str).to eq('in.[not]')
|
200
200
|
|
201
201
|
R18n::Filters.off(:untranslated)
|
202
|
-
@i18n.in.not.to_s.
|
202
|
+
expect(@i18n.in.not.to_s).to eq('in.not')
|
203
203
|
|
204
204
|
R18n::Filters.add(R18n::Untranslated) do |v, c, trans, untrans, path|
|
205
205
|
"#{path} #{trans}[#{untrans}]"
|
206
206
|
end
|
207
|
-
@i18n.in.not.to_s.
|
207
|
+
expect(@i18n.in.not.to_s).to eq('in.not in.[not]')
|
208
208
|
end
|
209
209
|
|
210
210
|
it "formats translation path" do
|
211
|
-
@i18n.in.another.to_s.
|
211
|
+
expect(@i18n.in.another.to_s).to eq('in.another[]')
|
212
212
|
|
213
213
|
R18n::Filters.off(:untranslated)
|
214
|
-
@i18n.in.another.to_s.
|
214
|
+
expect(@i18n.in.another.to_s).to eq('in.another')
|
215
215
|
|
216
216
|
R18n::Filters.add(R18n::Untranslated) do |v, c, trans, untrans, path|
|
217
217
|
"#{path} #{trans}[#{untrans}]"
|
218
218
|
end
|
219
|
-
@i18n.in.another.to_s.
|
219
|
+
expect(@i18n.in.another.to_s).to eq('in.another in.another[]')
|
220
220
|
end
|
221
221
|
|
222
222
|
it "formats untranslated for web" do
|
223
223
|
R18n::Filters.off(:untranslated)
|
224
224
|
R18n::Filters.on(:untranslated_html)
|
225
|
-
@i18n.in.not.to_s.
|
226
|
-
@i18n['<b>'].to_s.
|
225
|
+
expect(@i18n.in.not.to_s).to eq('in.<span style="color: red">[not]</span>')
|
226
|
+
expect(@i18n['<b>'].to_s).to eq('<span style="color: red">[<b>]</span>')
|
227
227
|
end
|
228
228
|
|
229
229
|
it "allows to set custom filters" do
|
230
230
|
R18n::Filters.add(R18n::Untranslated, :a) { |v, c| "a #{v}" }
|
231
231
|
R18n::Filters.off(:a)
|
232
232
|
|
233
|
-
html = R18n::I18n.new('en', DIR, :
|
234
|
-
:
|
235
|
-
html.in.not.to_s.
|
233
|
+
html = R18n::I18n.new('en', DIR, off_filters: :untranslated,
|
234
|
+
on_filters: [:untranslated_html, :a])
|
235
|
+
expect(html.in.not.to_s).to eq('a in.<span style="color: red">[not]</span>')
|
236
236
|
end
|
237
237
|
|
238
238
|
it "has filter for escape HTML" do
|
239
|
-
@i18n.html.
|
239
|
+
expect(@i18n.html).to eq(
|
240
|
+
'<script>true && false</script>')
|
240
241
|
end
|
241
242
|
|
242
243
|
it "has disabled global filter for escape HTML" do
|
243
|
-
@i18n.greater('true').
|
244
|
+
expect(@i18n.greater('true')).to eq('1 < 2 is true')
|
244
245
|
|
245
246
|
R18n::Filters.on(:global_escape_html)
|
246
247
|
@i18n.reload!
|
247
|
-
@i18n.greater('true').
|
248
|
-
@i18n.html.
|
248
|
+
expect(@i18n.greater('true')).to eq('1 < 2 is true')
|
249
|
+
expect(@i18n.html).to eq(
|
250
|
+
'<script>true && false</script>')
|
249
251
|
end
|
250
252
|
|
251
253
|
it "has filter to disable global HTML escape" do
|
252
|
-
@i18n.no_escape.
|
254
|
+
expect(@i18n.no_escape).to eq('<b>Warning</b>')
|
253
255
|
|
254
256
|
R18n::Filters.on(:global_escape_html)
|
255
257
|
@i18n.reload!
|
256
|
-
@i18n.no_escape.
|
258
|
+
expect(@i18n.no_escape).to eq('<b>Warning</b>')
|
257
259
|
end
|
258
260
|
|
259
261
|
it "has Markdown filter" do
|
260
|
-
@i18n.markdown.simple.
|
262
|
+
expect(@i18n.markdown.simple).to eq("<p><strong>Hi!</strong></p>\n")
|
261
263
|
end
|
262
264
|
|
263
265
|
it "has Textile filter" do
|
264
|
-
@i18n.textile.simple.
|
266
|
+
expect(@i18n.textile.simple).to eq('<p><em>Hi!</em></p>')
|
265
267
|
end
|
266
268
|
|
267
269
|
it "HTML escapes before Markdown and Textile filters" do
|
268
|
-
@i18n.markdown.html.
|
269
|
-
@i18n.textile.html.
|
270
|
+
expect(@i18n.markdown.html).to eq("<p><strong>Hi!</strong> <br /></p>\n")
|
271
|
+
expect(@i18n.textile.html).to eq('<p><em>Hi!</em><br /></p>')
|
270
272
|
|
271
273
|
R18n::Filters.on(:global_escape_html)
|
272
274
|
@i18n.reload!
|
273
|
-
@i18n.markdown.html.
|
274
|
-
|
275
|
+
expect(@i18n.markdown.html).to eq(
|
276
|
+
"<p><strong>Hi!</strong> <br /></p>\n")
|
277
|
+
expect(@i18n.textile.html).to eq(
|
278
|
+
'<p><em>Hi!</em><br /></p>')
|
275
279
|
end
|
276
280
|
|
277
281
|
it "allows to listen filters adding" do
|
278
|
-
R18n::Filters.listen {
|
282
|
+
expect(R18n::Filters.listen {
|
279
283
|
R18n::Filters.add(String, :a) { }
|
280
|
-
}.
|
284
|
+
}).to eq([R18n::Filters.defined[:a]])
|
281
285
|
end
|
282
286
|
|
283
287
|
it "escapes variables if ActiveSupport is loaded" do
|
284
|
-
@i18n.escape_params('<br>').
|
288
|
+
expect(@i18n.escape_params('<br>')).to eq('<b><br></b>')
|
285
289
|
require 'active_support'
|
286
|
-
@i18n.escape_params('<br>').
|
290
|
+
expect(@i18n.escape_params('<br>')).to eq('<b><br></b>')
|
287
291
|
end
|
288
292
|
|
289
293
|
it "uses SafeBuffer if it is loaded" do
|
@@ -292,7 +296,6 @@ describe R18n::Filters do
|
|
292
296
|
R18n::Filters.on(:global_escape_html)
|
293
297
|
@i18n.reload!
|
294
298
|
|
295
|
-
@i18n.greater('<b>'.html_safe).
|
299
|
+
expect(@i18n.greater('<b>'.html_safe)).to eq('1 < 2 is <b>')
|
296
300
|
end
|
297
|
-
|
298
301
|
end
|