r18n-core 1.1.11 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog.md +4 -0
  3. data/README.md +2 -2
  4. data/lib/r18n-core/filter_list.rb +2 -3
  5. data/lib/r18n-core/filters.rb +9 -10
  6. data/lib/r18n-core/helpers.rb +0 -1
  7. data/lib/r18n-core/i18n.rb +1 -2
  8. data/lib/r18n-core/locale.rb +10 -12
  9. data/lib/r18n-core/translated.rb +3 -4
  10. data/lib/r18n-core/translated_string.rb +0 -1
  11. data/lib/r18n-core/translation.rb +2 -3
  12. data/lib/r18n-core/unsupported_locale.rb +0 -1
  13. data/lib/r18n-core/untranslated.rb +0 -1
  14. data/lib/r18n-core/utils.rb +0 -11
  15. data/lib/r18n-core/version.rb +1 -2
  16. data/lib/r18n-core/yaml_loader.rb +0 -1
  17. data/lib/r18n-core/yaml_methods.rb +2 -8
  18. data/lib/r18n-core.rb +0 -3
  19. data/locales/bg.rb +11 -13
  20. data/locales/ca.rb +13 -14
  21. data/locales/cs.rb +15 -16
  22. data/locales/da.rb +13 -15
  23. data/locales/de.rb +14 -15
  24. data/locales/en-au.rb +2 -2
  25. data/locales/en-gb.rb +2 -2
  26. data/locales/en-us.rb +5 -7
  27. data/locales/en.rb +14 -14
  28. data/locales/eo.rb +11 -12
  29. data/locales/es-us.rb +6 -8
  30. data/locales/es.rb +11 -12
  31. data/locales/fi.rb +16 -17
  32. data/locales/fr.rb +10 -11
  33. data/locales/gl.rb +12 -13
  34. data/locales/hr.rb +12 -13
  35. data/locales/hu.rb +12 -13
  36. data/locales/id.rb +9 -9
  37. data/locales/it.rb +9 -10
  38. data/locales/ja.rb +11 -12
  39. data/locales/kk.rb +16 -18
  40. data/locales/lv.rb +16 -17
  41. data/locales/mn.rb +12 -14
  42. data/locales/nb.rb +12 -13
  43. data/locales/nl.rb +13 -14
  44. data/locales/no.rb +12 -13
  45. data/locales/pl.rb +13 -14
  46. data/locales/pt-br.rb +2 -3
  47. data/locales/pt.rb +13 -14
  48. data/locales/ru.rb +14 -15
  49. data/locales/sk.rb +15 -16
  50. data/locales/sr-latn.rb +12 -14
  51. data/locales/sv-se.rb +11 -13
  52. data/locales/th.rb +13 -14
  53. data/locales/tr.rb +12 -15
  54. data/locales/uk.rb +11 -15
  55. data/locales/zh-cn.rb +2 -3
  56. data/locales/zh-tw.rb +5 -6
  57. data/locales/zh.rb +10 -11
  58. data/r18n-core.gemspec +5 -4
  59. data/spec/filters_spec.rb +94 -91
  60. data/spec/i18n_spec.rb +66 -68
  61. data/spec/locale_spec.rb +74 -74
  62. data/spec/locales/cs_spec.rb +14 -14
  63. data/spec/locales/en-us_spec.rb +6 -6
  64. data/spec/locales/en_spec.rb +6 -6
  65. data/spec/locales/fr_spec.rb +2 -2
  66. data/spec/locales/hu_spec.rb +6 -7
  67. data/spec/locales/it_spec.rb +3 -4
  68. data/spec/locales/pl_spec.rb +14 -14
  69. data/spec/locales/ru_spec.rb +13 -13
  70. data/spec/locales/sk_spec.rb +14 -14
  71. data/spec/locales/th_spec.rb +2 -2
  72. data/spec/r18n_spec.rb +47 -49
  73. data/spec/spec_helper.rb +0 -7
  74. data/spec/translated_spec.rb +26 -28
  75. data/spec/translation_spec.rb +38 -40
  76. data/spec/yaml_loader_spec.rb +14 -16
  77. 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.should be_a(R18n::Filters::Filter)
26
- filter.name.should == :my_filter
27
- filter.types.should == ['my']
28
- filter.should be_enabled
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.should have_key(:my_filter)
29
+ expect(R18n::Filters.defined).to have_key(:my_filter)
31
30
 
32
31
  @i18n.reload!
33
- @i18n.my_filter.should == 'value'
34
- @i18n.my_tree_filter.should == {'name' => 'value'}
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.should == 'value1'
41
- @i18n.your_filter.should == 'another1'
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.should_receive(:process).twice.and_return(1)
45
+ expect(filter).to receive(:process).twice.and_return(1)
47
46
 
48
- R18n::Filters.add('my', :passive, :passive => true) { filter.process }
47
+ R18n::Filters.add('my', :passive, passive: true) { filter.process }
49
48
 
50
- @i18n.my_filter.should.should == 'value'
49
+ expect(@i18n.my_filter).to eq('value')
51
50
  @i18n.reload!
52
51
 
53
- @i18n.my_tree_filter.should == 1
54
- @i18n.my_filter.should == 1
55
- @i18n.my_filter.should == 1
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, :position => 0) { |i, c| i + '3' }
62
- @i18n.my_filter.should == 'value312'
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.should == 1
69
- R18n::Filters.add('some', :position => 0).name.should == 2
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.should == 4
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.should == '1'
76
+ expect(@i18n.my_filter).to eq('1')
78
77
 
79
78
  R18n::Filters.delete(:my_filter)
80
- R18n::Filters.defined.should_not have_key(:my_filter)
81
- @i18n.my_filter.should == 'value'
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.should == '1'
85
+ expect(@i18n.my_filter).to eq('1')
87
86
 
88
87
  R18n::Filters.delete(filter)
89
- R18n::Filters.defined.should_not have_key(filter.name)
90
- @i18n.my_filter.should == 'value'
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').should == 'One12!'
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].should_not be_enabled
106
- @i18n.my_filter.should == 'value2'
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].should be_enabled
110
- @i18n.my_filter.should == 'value12'
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].should == @i18n.locale
119
- @i18n.my_filter[:path].should == 'my_filter'
120
- @i18n.my_filter[:secret_value].should == 1
121
- @i18n.my_filter[:unknown_value].should be_nil
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.should == '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.should be_a(R18n::TranslatedString)
136
- @i18n.one.path.should == 'one'
137
- @i18n.one.locale.should == R18n.locale('en')
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.should == 1
141
+ expect(@i18n.my_filter).to eq(1)
143
142
 
144
- R18n::Filters.add('my', :second, :position => 0) do |content, config|
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.should == 2
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].should == 'value12'
154
- @i18n.my_filter(1, 2).should == 'value12'
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).should == 5
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').should == 'no comments for article'
163
- @i18n.comments(1, 'article').should == 'one comment for article'
164
- @i18n.comments(5, 'article').should == '5 comments for 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).should == '0 files'
167
- @i18n.files(-5.5).should == '−5.5 files'
168
- @i18n.files(5000).should == '5,000 files'
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.should be_a(R18n::UnpluralizetedTranslation)
173
- @i18n.files('').should be_a(R18n::UnpluralizetedTranslation)
174
- @i18n.files[1].should == '1 file'
175
- @i18n.files.n(5).should == '5 files'
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).should == '1 file'
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).should == 'ONE'
185
- i18n.entries(5).should == 'N'
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).should == 'Is −1 between −1 and 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').should ==
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.should == 'in.[not]'
199
- @i18n.in.not.to_str.should == 'in.[not]'
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.should == 'in.not'
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.should == 'in.not in.[not]'
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.should == 'in.another[]'
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.should == 'in.another'
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.should == 'in.another in.another[]'
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.should == 'in.<span style="color: red">[not]</span>'
226
- @i18n['<b>'].to_s.should == '<span style="color: red">[&lt;b&gt;]</span>'
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">[&lt;b&gt;]</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, :off_filters => :untranslated,
234
- :on_filters => [:untranslated_html, :a])
235
- html.in.not.to_s.should == 'a in.<span style="color: red">[not]</span>'
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.should == '&lt;script&gt;true &amp;&amp; false&lt;/script&gt;'
239
+ expect(@i18n.html).to eq(
240
+ '&lt;script&gt;true &amp;&amp; false&lt;/script&gt;')
240
241
  end
241
242
 
242
243
  it "has disabled global filter for escape HTML" do
243
- @i18n.greater('true').should == '1 < 2 is 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').should == '1 &lt; 2 is true'
248
- @i18n.html.should == '&lt;script&gt;true &amp;&amp; false&lt;/script&gt;'
248
+ expect(@i18n.greater('true')).to eq('1 &lt; 2 is true')
249
+ expect(@i18n.html).to eq(
250
+ '&lt;script&gt;true &amp;&amp; false&lt;/script&gt;')
249
251
  end
250
252
 
251
253
  it "has filter to disable global HTML escape" do
252
- @i18n.no_escape.should == '<b>Warning</b>'
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.should == '<b>Warning</b>'
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.should == "<p><strong>Hi!</strong></p>\n"
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.should == '<p><em>Hi!</em></p>'
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.should == "<p><strong>Hi!</strong> <br /></p>\n"
269
- @i18n.textile.html.should == '<p><em>Hi!</em><br /></p>'
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.should == "<p><strong>Hi!</strong> &lt;br /&gt;</p>\n"
274
- @i18n.textile.html.should == '<p><em>Hi!</em>&lt;br /&gt;</p>'
275
+ expect(@i18n.markdown.html).to eq(
276
+ "<p><strong>Hi!</strong> &lt;br /&gt;</p>\n")
277
+ expect(@i18n.textile.html).to eq(
278
+ '<p><em>Hi!</em>&lt;br /&gt;</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
- }.should == [R18n::Filters.defined[:a]]
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>').should == '<b><br></b>'
288
+ expect(@i18n.escape_params('<br>')).to eq('<b><br></b>')
285
289
  require 'active_support'
286
- @i18n.escape_params('<br>').should == '<b>&lt;br&gt;</b>'
290
+ expect(@i18n.escape_params('<br>')).to eq('<b>&lt;br&gt;</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).should == '1 &lt; 2 is <b>'
299
+ expect(@i18n.greater('<b>'.html_safe)).to eq('1 &lt; 2 is <b>')
296
300
  end
297
-
298
301
  end