r18n-core 0.4.10 → 0.4.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/ChangeLog +5 -0
  2. data/Gemfile.lock +1 -1
  3. data/README.rdoc +25 -25
  4. data/Rakefile +0 -1
  5. data/lib/r18n-core.rb +5 -5
  6. data/lib/r18n-core/filters.rb +45 -45
  7. data/lib/r18n-core/helpers.rb +4 -4
  8. data/lib/r18n-core/i18n.rb +30 -30
  9. data/lib/r18n-core/locale.rb +26 -26
  10. data/lib/r18n-core/translated.rb +23 -23
  11. data/lib/r18n-core/translated_string.rb +4 -4
  12. data/lib/r18n-core/translation.rb +10 -10
  13. data/lib/r18n-core/unsupported_locale.rb +6 -6
  14. data/lib/r18n-core/untranslated.rb +13 -13
  15. data/lib/r18n-core/utils.rb +4 -4
  16. data/lib/r18n-core/version.rb +1 -1
  17. data/lib/r18n-core/yaml_loader.rb +13 -11
  18. data/locales/bg.rb +3 -3
  19. data/locales/ca.rb +6 -5
  20. data/locales/cs.rb +5 -5
  21. data/locales/da.rb +4 -4
  22. data/locales/de.rb +4 -4
  23. data/locales/en-us.rb +1 -1
  24. data/locales/en.rb +6 -6
  25. data/locales/eo.rb +4 -4
  26. data/locales/es.rb +4 -4
  27. data/locales/fi.rb +5 -5
  28. data/locales/fr.rb +6 -6
  29. data/locales/hu.rb +1 -1
  30. data/locales/it.rb +5 -5
  31. data/locales/ja.rb +5 -4
  32. data/locales/kk.rb +4 -4
  33. data/locales/lv.rb +5 -5
  34. data/locales/nl.rb +5 -5
  35. data/locales/pl.rb +5 -5
  36. data/locales/pt.rb +4 -4
  37. data/locales/ru.rb +5 -5
  38. data/locales/sk.rb +5 -5
  39. data/locales/sv-se.rb +4 -4
  40. data/locales/th.rb +7 -4
  41. data/locales/zh.rb +6 -5
  42. data/r18n-core.gemspec +0 -1
  43. data/spec/filters_spec.rb +48 -48
  44. data/spec/i18n_spec.rb +32 -32
  45. data/spec/locale_spec.rb +20 -20
  46. data/spec/locales/cs_spec.rb +2 -2
  47. data/spec/locales/hu_spec.rb +1 -1
  48. data/spec/locales/it_spec.rb +1 -1
  49. data/spec/locales/pl_spec.rb +2 -2
  50. data/spec/locales/ru_spec.rb +3 -3
  51. data/spec/locales/sk_spec.rb +2 -2
  52. data/spec/r18n_spec.rb +21 -21
  53. data/spec/spec_helper.rb +3 -3
  54. data/spec/translated_spec.rb +24 -24
  55. data/spec/translation_spec.rb +10 -10
  56. data/spec/yaml_loader_spec.rb +10 -10
  57. metadata +24 -26
data/locales/zh.rb CHANGED
@@ -2,16 +2,17 @@
2
2
  module R18n
3
3
  class Locales::Zh < R18n::Locale
4
4
  set :title => '中文',
5
-
5
+
6
6
  :wday_names => %w{星期日 星期一 星期二 星期三 星期四 星期五 星期六},
7
7
  :wday_abbrs => %w{周日 周一 周二 周三 周四 周五 周六},
8
-
9
- :month_names => %w{一月 二月 三月 四月 五月 六月 七月 八月 九月 十月 十一月 十二月},
10
-
8
+
9
+ :month_names => %w{一月 二月 三月 四月 五月 六月 七月 八月 九月 十月
10
+ 十一月 十二月},
11
+
11
12
  :date_format => '%Y年%m月%d日',
12
13
  :full_format => '%m月%d日',
13
14
  :year_format => '%Y年_',
14
-
15
+
15
16
  :number_decimal => ".",
16
17
  :number_group => " "
17
18
  end
data/r18n-core.gemspec CHANGED
@@ -18,7 +18,6 @@ Gem::Specification.new do |s|
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
19
  s.extra_rdoc_files = ['README.rdoc', 'LICENSE', 'ChangeLog']
20
20
  s.require_path = 'lib'
21
- s.has_rdoc = true
22
21
 
23
22
  s.author = 'Andrey "A.I." Sitnik'
24
23
  s.email = 'andrey@sitnik.ru'
data/spec/filters_spec.rb CHANGED
@@ -8,108 +8,108 @@ describe R18n::Filters do
8
8
  @i18n = R18n::I18n.new('en', DIR)
9
9
  @i18n.reload!
10
10
  end
11
-
11
+
12
12
  after do
13
13
  R18n::Filters.defined.values.each do |filter|
14
14
  next if @system.include? filter
15
15
  R18n::Filters.delete(filter)
16
16
  end
17
-
17
+
18
18
  @enabled.each { |i| R18n::Filters.on(i) unless i.enabled? }
19
19
  (@system - @enabled).each { |i| R18n::Filters.off(i) if i.enabled? }
20
20
  end
21
-
21
+
22
22
  it "should add new filter" do
23
23
  filter = R18n::Filters.add('my', :my_filter) { |i, config| i }
24
-
24
+
25
25
  filter.should be_a(R18n::Filters::Filter)
26
26
  filter.name.should == :my_filter
27
27
  filter.types.should == ['my']
28
28
  filter.should be_enabled
29
-
29
+
30
30
  R18n::Filters.defined.should have_key(:my_filter)
31
-
31
+
32
32
  @i18n.reload!
33
33
  @i18n.my_filter.should == 'value'
34
34
  @i18n.my_tree_filter.should == {'name' => 'value'}
35
35
  end
36
-
36
+
37
37
  it "should add filter for several types" do
38
38
  filter = R18n::Filters.add(['my', 'your']) { |i, config| i + '1' }
39
39
  @i18n.reload!
40
40
  @i18n.my_filter.should == 'value1'
41
41
  @i18n.your_filter.should == 'another1'
42
42
  end
43
-
43
+
44
44
  it "should use passive filters" do
45
45
  filter = mock()
46
46
  filter.should_receive(:process).twice.and_return(1)
47
-
47
+
48
48
  R18n::Filters.add('my', :passive, :passive => true) { filter.process }
49
-
49
+
50
50
  @i18n.my_filter.should.should == 'value'
51
51
  @i18n.reload!
52
-
52
+
53
53
  @i18n.my_tree_filter.should == 1
54
54
  @i18n.my_filter.should == 1
55
55
  @i18n.my_filter.should == 1
56
56
  end
57
-
57
+
58
58
  it "should use cascade filters" do
59
59
  filter = R18n::Filters.add('my', :one) { |i, config| i + '1' }
60
60
  filter = R18n::Filters.add('my', :two) { |i, config| i + '2' }
61
61
  filter = R18n::Filters.add('my', :three, :position => 0) { |i, c| i + '3' }
62
62
  @i18n.my_filter.should == 'value312'
63
63
  end
64
-
64
+
65
65
  it "should return name for nameless filter" do
66
66
  R18n::Filters.instance_variable_set(:@last_auto_name, 0)
67
-
67
+
68
68
  R18n::Filters.add('some').name.should == 1
69
69
  R18n::Filters.add('some', :position => 0).name.should == 2
70
-
70
+
71
71
  R18n::Filters.add('some', 3)
72
72
  R18n::Filters.add('some').name.should == 4
73
73
  end
74
-
74
+
75
75
  it "should delete filter by name" do
76
76
  R18n::Filters.add('my', :my_filter) { '1' }
77
77
  @i18n.my_filter.should == '1'
78
-
78
+
79
79
  R18n::Filters.delete(:my_filter)
80
80
  R18n::Filters.defined.should_not have_key(:my_filter)
81
81
  @i18n.my_filter.should == 'value'
82
82
  end
83
-
83
+
84
84
  it "should delete filter by object" do
85
85
  filter = R18n::Filters.add('my') { '1' }
86
86
  @i18n.my_filter.should == '1'
87
-
87
+
88
88
  R18n::Filters.delete(filter)
89
89
  R18n::Filters.defined.should_not have_key(filter.name)
90
90
  @i18n.my_filter.should == 'value'
91
91
  end
92
-
92
+
93
93
  it "should use global filters" do
94
94
  R18n::Filters.add(String) { |result, config, a, b| result + a + b }
95
95
  R18n::Filters.add(String) { |result, config| result + '!' }
96
-
96
+
97
97
  @i18n.one('1', '2').should == 'One12!'
98
98
  end
99
-
99
+
100
100
  it "should turn off filter" do
101
101
  filter = R18n::Filters.add('my', :one) { |i, config| i + '1' }
102
102
  filter = R18n::Filters.add('my', :two) { |i, config| i + '2' }
103
-
103
+
104
104
  R18n::Filters.off(:one)
105
105
  R18n::Filters.defined[:one].should_not be_enabled
106
106
  @i18n.my_filter.should == 'value2'
107
-
107
+
108
108
  R18n::Filters.on(:one)
109
109
  R18n::Filters.defined[:one].should be_enabled
110
110
  @i18n.my_filter.should == 'value12'
111
111
  end
112
-
112
+
113
113
  it "should send config to filter" do
114
114
  R18n::Filters.add('my') do |i, config|
115
115
  config[:secret_value] = 1
@@ -120,18 +120,18 @@ describe R18n::Filters do
120
120
  @i18n.my_filter[:secret_value].should == 1
121
121
  @i18n.my_filter[:unknown_value].should be_nil
122
122
  end
123
-
123
+
124
124
  it "should use one config for cascade filters" do
125
125
  R18n::Filters.add('my') { |content, config| config[:new_secret] ? 2 : 1 }
126
126
  @i18n.my_filter.should == 1
127
-
127
+
128
128
  R18n::Filters.add('my', :second, :position => 0) do |content, config|
129
129
  config[:new_secret] = true
130
130
  content
131
131
  end
132
132
  @i18n.my_filter.should == 2
133
133
  end
134
-
134
+
135
135
  it "should send parameters to filter" do
136
136
  R18n::Filters.add('my') { |i, config, a, b| "#{i}#{a}#{b}" }
137
137
  @i18n['my_filter', 1, 2].should == 'value12'
@@ -146,17 +146,17 @@ describe R18n::Filters do
146
146
  @i18n.comments(0, 'article').should == 'no comments for article'
147
147
  @i18n.comments(1, 'article').should == 'one comment for article'
148
148
  @i18n.comments(5, 'article').should == '5 comments for article'
149
-
149
+
150
150
  @i18n.files(0).should == '0 files'
151
151
  @i18n.files(-5.5).should == '−5.5 files'
152
152
  @i18n.files(5000).should == '5,000 files'
153
153
  end
154
-
154
+
155
155
  it "shouldn't pluralize without first numeric parameter" do
156
156
  @i18n.files.should == { 1 => '1 file', 'n' => '%1 files' }
157
157
  @i18n.files('').should == { 1 => '1 file', 'n' => '%1 files' }
158
158
  end
159
-
159
+
160
160
  it "should convert first float parameter to number" do
161
161
  @i18n.files(1.2).should == '1 file'
162
162
  end
@@ -170,75 +170,75 @@ describe R18n::Filters do
170
170
  it "should can use params in translation" do
171
171
  @i18n.params(-1, 2).should == 'Is −1 between −1 and 2?'
172
172
  end
173
-
173
+
174
174
  it "should format untranslated" do
175
175
  @i18n.in.not.to_s.should == 'in.[not]'
176
-
176
+
177
177
  R18n::Filters.off(:untranslated)
178
178
  @i18n.in.not.to_s.should == 'in.not'
179
-
179
+
180
180
  R18n::Filters.add(R18n::Untranslated) do |v, c, trans, untrans, path|
181
181
  "#{path} #{trans}[#{untrans}]"
182
182
  end
183
183
  @i18n.in.not.to_s.should == 'in.not in.[not]'
184
184
  end
185
-
185
+
186
186
  it "should format translation path" do
187
187
  @i18n.in.another.to_s.should == 'in.another[]'
188
-
188
+
189
189
  R18n::Filters.off(:untranslated)
190
190
  @i18n.in.another.to_s.should == 'in.another'
191
-
191
+
192
192
  R18n::Filters.add(R18n::Untranslated) do |v, c, trans, untrans, path|
193
193
  "#{path} #{trans}[#{untrans}]"
194
194
  end
195
195
  @i18n.in.another.to_s.should == 'in.another in.another[]'
196
196
  end
197
-
197
+
198
198
  it "should format untranslated for web" do
199
199
  R18n::Filters.off(:untranslated)
200
200
  R18n::Filters.on(:untranslated_html)
201
201
  @i18n.in.not.to_s.should == 'in.<span style="color: red">not</span>'
202
202
  @i18n['<b>'].to_s.should == '<span style="color: red">&lt;b&gt;</span>'
203
203
  end
204
-
204
+
205
205
  it "should have filter for escape HTML" do
206
206
  @i18n.html.should == '&lt;script&gt;true &amp;&amp; false&lt;/script&gt;'
207
207
  end
208
-
208
+
209
209
  it "should have disabled global filter for escape HTML" do
210
210
  @i18n.greater('true').should == '1 < 2 is true'
211
-
211
+
212
212
  R18n::Filters.on(:global_escape_html)
213
213
  @i18n.reload!
214
214
  @i18n.greater('true').should == '1 &lt; 2 is true'
215
215
  @i18n.html.should == '&lt;script&gt;true &amp;&amp; false&lt;/script&gt;'
216
216
  end
217
-
217
+
218
218
  it "should have filter to disable global HTML escape" do
219
219
  @i18n.no_escape.should == '<b>Warning</b>'
220
-
220
+
221
221
  R18n::Filters.on(:global_escape_html)
222
222
  @i18n.reload!
223
223
  @i18n.no_escape.should == '<b>Warning</b>'
224
224
  end
225
-
225
+
226
226
  it "should have Markdown filter" do
227
227
  @i18n.markdown.simple.should == '<p><strong>Hi!</strong></p>'
228
228
  end
229
-
229
+
230
230
  it "should have Textile filter" do
231
231
  @i18n.textile.simple.should == '<p><em>Hi!</em></p>'
232
232
  end
233
-
233
+
234
234
  it "should HTML escape before Markdown and Textile filters" do
235
235
  @i18n.markdown.html.should == '<p><strong>Hi!</strong> <br /></p>'
236
236
  @i18n.textile.html.should == '<p><em>Hi!</em><br /></p>'
237
-
237
+
238
238
  R18n::Filters.on(:global_escape_html)
239
239
  @i18n.reload!
240
240
  @i18n.markdown.html.should == '<p><strong>Hi!</strong> &#60;br /&#62;</p>'
241
241
  @i18n.textile.html.should == '<p><em>Hi!</em>&lt;br /&gt;</p>'
242
242
  end
243
-
243
+
244
244
  end
data/spec/i18n_spec.rb CHANGED
@@ -5,7 +5,7 @@ describe R18n::I18n do
5
5
  before do
6
6
  @extension_places = R18n.extension_places.clone
7
7
  end
8
-
8
+
9
9
  after do
10
10
  R18n::I18n.default = 'en'
11
11
  R18n.default_loader = R18n::Loader::YAML
@@ -27,7 +27,7 @@ describe R18n::I18n do
27
27
  it "should load locales" do
28
28
  i18n = R18n::I18n.new('en', DIR)
29
29
  i18n.locales.should == [R18n::Locale.load('en')]
30
-
30
+
31
31
  i18n = R18n::I18n.new(['ru', 'no-LC'], DIR)
32
32
  i18n.locales.should == [R18n::Locale.load('ru'),
33
33
  R18n::UnsupportedLocale.new('no-LC'),
@@ -39,7 +39,7 @@ describe R18n::I18n do
39
39
  i18n = R18n::I18n.new('en', DIR)
40
40
  i18n.translation_places.should == [R18n::Loader::YAML.new(DIR)]
41
41
  end
42
-
42
+
43
43
  it "should load translations by loader" do
44
44
  loader = Class.new do
45
45
  def available; [R18n::Locale.load('en')]; end
@@ -47,7 +47,7 @@ describe R18n::I18n do
47
47
  end
48
48
  R18n::I18n.new('en', loader.new).custom.should == 'Custom'
49
49
  end
50
-
50
+
51
51
  it "should pass parameters to default loader" do
52
52
  loader = Class.new do
53
53
  def initialize(param); @param = param; end
@@ -65,7 +65,7 @@ describe R18n::I18n do
65
65
  i18n['one'].should == 'Один'
66
66
  i18n.only.english.should == 'Only in English'
67
67
  end
68
-
68
+
69
69
  it "should load translations from several dirs" do
70
70
  i18n = R18n::I18n.new(['no-LC', 'en'], [TWO, DIR])
71
71
  i18n.in.two.should == 'Two'
@@ -74,7 +74,7 @@ describe R18n::I18n do
74
74
 
75
75
  it "should use extension places" do
76
76
  R18n.extension_places << EXT
77
-
77
+
78
78
  i18n = R18n::I18n.new('en', DIR)
79
79
  i18n.ext.should == 'Extension'
80
80
  i18n.one.should == 'One'
@@ -82,15 +82,15 @@ describe R18n::I18n do
82
82
 
83
83
  it "shouldn't use extension without app translations with same locale" do
84
84
  R18n.extension_places << EXT
85
-
85
+
86
86
  i18n = R18n::I18n.new(['no-TR', 'en'], DIR)
87
87
  i18n.ext.should == 'Extension'
88
88
  end
89
-
89
+
90
90
  it "should ignore case on loading" do
91
91
  i18n = R18n::I18n.new('no-lc', [DIR])
92
92
  i18n.one.should == 'ONE'
93
-
93
+
94
94
  i18n = R18n::I18n.new('no-LC', [DIR])
95
95
  i18n.one.should == 'ONE'
96
96
  end
@@ -103,7 +103,7 @@ describe R18n::I18n do
103
103
 
104
104
  it "should load sublocales for first locale" do
105
105
  R18n::I18n.default = 'no-TR'
106
-
106
+
107
107
  i18n = R18n::I18n.new('ru', DIR)
108
108
  i18n.one.should == 'Один'
109
109
  i18n.two.should == 'Two'
@@ -118,74 +118,74 @@ describe R18n::I18n do
118
118
  R18n::Locale.load('ru'),
119
119
  R18n::Locale.load('en')]
120
120
  end
121
-
121
+
122
122
  it "should cache translations" do
123
123
  counter = CounterLoader.new('en')
124
-
124
+
125
125
  R18n::I18n.new('en', counter)
126
126
  counter.loaded.should == 1
127
-
127
+
128
128
  R18n::I18n.new('en', counter)
129
129
  counter.loaded.should == 1
130
-
130
+
131
131
  R18n.cache.clear
132
132
  R18n::I18n.new('en', counter)
133
133
  counter.loaded.should == 2
134
134
  end
135
-
135
+
136
136
  it "should cache translations by used locales" do
137
137
  counter = CounterLoader.new('en', 'ru')
138
-
138
+
139
139
  R18n::I18n.new('en', counter)
140
140
  counter.loaded.should == 1
141
-
141
+
142
142
  R18n::I18n.new(['en', 'fr'], counter)
143
143
  counter.loaded.should == 1
144
-
144
+
145
145
  R18n::I18n.new(['en', 'ru'], counter)
146
146
  counter.loaded.should == 3
147
-
147
+
148
148
  R18n::I18n.new(['ru', 'en'], counter)
149
149
  counter.loaded.should == 5
150
150
  end
151
-
151
+
152
152
  it "should cache translations by places" do
153
153
  counter = CounterLoader.new('en', 'ru')
154
-
154
+
155
155
  R18n::I18n.new('en', counter)
156
156
  counter.loaded.should == 1
157
-
157
+
158
158
  R18n::I18n.new('en', [counter, DIR])
159
159
  counter.loaded.should == 2
160
-
160
+
161
161
  R18n.extension_places << EXT
162
162
  R18n::I18n.new('en', counter)
163
163
  counter.loaded.should == 3
164
-
164
+
165
165
  same = CounterLoader.new('en', 'ru')
166
166
  R18n::I18n.new('en', same)
167
167
  same.loaded.should == 0
168
-
168
+
169
169
  different = CounterLoader.new('en', 'fr')
170
170
  R18n::I18n.new('en', different)
171
171
  different.loaded.should == 1
172
172
  end
173
-
173
+
174
174
  it "should reload translations" do
175
175
  loader = Class.new do
176
176
  @@answer = 1
177
177
  def available; [R18n::Locale.load('en')]; end
178
178
  def load(locale); { 'one' => @@answer }; end
179
179
  end
180
-
180
+
181
181
  i18n = R18n::I18n.new('en', loader.new)
182
182
  i18n.one.should == 1
183
-
183
+
184
184
  loader.class_eval { @@answer = 2 }
185
185
  i18n.reload!
186
186
  i18n.one.should == 2
187
187
  end
188
-
188
+
189
189
  it "should return translations" do
190
190
  i18n = R18n::I18n.new('en', DIR)
191
191
  i18n.t.should be_a(R18n::Translation)
@@ -200,16 +200,16 @@ describe R18n::I18n do
200
200
 
201
201
  it "should localize objects" do
202
202
  i18n = R18n::I18n.new('ru')
203
-
203
+
204
204
  i18n.l(-123456789).should == '−123 456 789'
205
205
  i18n.l(-12345.67).should == '−12 345,67'
206
-
206
+
207
207
  time = Time.at(0).utc
208
208
  i18n.l(time, '%A').should == 'Четверг'
209
209
  i18n.l(time, :month).should == 'Январь'
210
210
  i18n.l(time, :standard).should == '01.01.1970 00:00'
211
211
  i18n.l(time, :full).should == ' 1 января 1970 00:00'
212
-
212
+
213
213
  i18n.l(Date.new(0)).should == '01.01.0000'
214
214
  end
215
215