r18n-core 0.4.14 → 1.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.
Files changed (56) hide show
  1. data/.yardopts +1 -1
  2. data/ChangeLog +21 -0
  3. data/LICENSE +2 -2
  4. data/README.md +456 -0
  5. data/Rakefile +2 -1
  6. data/base/gl.yml +31 -0
  7. data/base/it.yml +1 -1
  8. data/lib/r18n-core/filter_list.rb +157 -0
  9. data/lib/r18n-core/filters.rb +40 -36
  10. data/lib/r18n-core/i18n.rb +17 -9
  11. data/lib/r18n-core/locale.rb +5 -2
  12. data/lib/r18n-core/translated.rb +18 -15
  13. data/lib/r18n-core/translated_string.rb +14 -0
  14. data/lib/r18n-core/translation.rb +19 -20
  15. data/lib/r18n-core/untranslated.rb +8 -5
  16. data/lib/r18n-core/utils.rb +5 -1
  17. data/lib/r18n-core/version.rb +1 -1
  18. data/lib/r18n-core/yaml_loader.rb +2 -2
  19. data/lib/r18n-core.rb +60 -13
  20. data/locales/ca.rb +1 -0
  21. data/locales/cs.rb +0 -1
  22. data/locales/en-au.rb +0 -1
  23. data/locales/en-gb.rb +0 -1
  24. data/locales/en-us.rb +0 -1
  25. data/locales/en.rb +1 -1
  26. data/locales/fr.rb +1 -1
  27. data/locales/gl.rb +21 -0
  28. data/locales/hu.rb +1 -2
  29. data/locales/nb-no.rb +2 -3
  30. data/locales/nl.rb +4 -2
  31. data/locales/pt-br.rb +0 -1
  32. data/locales/pt.rb +0 -1
  33. data/locales/sv-se.rb +2 -3
  34. data/locales/th.rb +1 -1
  35. data/locales/tr.rb +2 -4
  36. data/locales/zh-cn.rb +7 -0
  37. data/locales/zh-tw.rb +7 -0
  38. data/r18n-core.gemspec +10 -10
  39. data/spec/filters_spec.rb +38 -7
  40. data/spec/i18n_spec.rb +15 -18
  41. data/spec/locale_spec.rb +19 -14
  42. data/spec/locales/cs_spec.rb +1 -1
  43. data/spec/locales/pl_spec.rb +1 -1
  44. data/spec/locales/ru_spec.rb +1 -1
  45. data/spec/locales/sk_spec.rb +1 -1
  46. data/spec/r18n_spec.rb +64 -22
  47. data/spec/spec_helper.rb +2 -3
  48. data/spec/translated_spec.rb +18 -4
  49. data/spec/translation_spec.rb +17 -6
  50. data/spec/translations/general/en.yml +1 -0
  51. data/spec/yaml_loader_spec.rb +10 -10
  52. metadata +163 -141
  53. data/Gemfile +0 -5
  54. data/Gemfile.lock +0 -35
  55. data/README.rdoc +0 -482
  56. data/spec/translations/empty/en.yml +0 -0
data/locales/fr.rb CHANGED
@@ -20,7 +20,7 @@ module R18n
20
20
  def format_date_full(date, year = true, *params)
21
21
  full = super(date, year)
22
22
  if ' 1' == full[0..1]
23
- '1er' + full[2..-1]
23
+ '1er' + full[2..-1]
24
24
  else
25
25
  full
26
26
  end
data/locales/gl.rb ADDED
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ module R18n
3
+ class Locales::Gl < Locale
4
+ set :title => 'Galego',
5
+ :sublocales => %w{es en},
6
+
7
+ :wday_names => %w{domingo luns martes mércores xoves venres sábado},
8
+ :wday_abbrs => %w{dom lun mar mér xov ven sáb},
9
+
10
+ :month_names => %w{xaneiro febreiro marzo abril maio xuño xullo
11
+ agosto setembro outubro novembro decembro},
12
+ :month_abbrs => %w{xan feb mar abr mai xuñ xul ago set out nov dec},
13
+
14
+ :date_format => '%d/%m/%Y',
15
+ :full_format => '%d de %B',
16
+ :year_format => '_ de %Y',
17
+
18
+ :number_decimal => ",",
19
+ :number_group => "."
20
+ end
21
+ end
data/locales/hu.rb CHANGED
@@ -17,7 +17,7 @@ module R18n
17
17
  :time_format => '%H:%M',
18
18
 
19
19
  :number_decimal => ",",
20
- :number_group => " "
20
+ :number_group => " "
21
21
 
22
22
  def format_integer(integer)
23
23
  str = integer.to_s
@@ -42,6 +42,5 @@ module R18n
42
42
  def format_time_full(time, *params)
43
43
  format_date_full(time) + ', ' + format_time(time)
44
44
  end
45
-
46
45
  end
47
46
  end
data/locales/nb-no.rb CHANGED
@@ -2,8 +2,7 @@
2
2
  module R18n
3
3
  class Locales::NbNo < Locale
4
4
  set :title => 'Norsk', #Bokmål
5
- :code => 'nb-NO',
6
- :sublocales => %w{no nn-NO},
5
+ :sublocales => %w{no nn-NO en},
7
6
 
8
7
  :week_start => :monday,
9
8
  :wday_names => %w{søndag mandag tirsdag onsdag torsdag fredag lørdag},
@@ -11,7 +10,7 @@ module R18n
11
10
 
12
11
  :month_names => %w{januar februar mars april mai juni juli august
13
12
  september oktober november desember},
14
- :month_abbrs => %w{jan feb mar apr mai jun jul aug okt nov des},
13
+ :month_abbrs => %w{jan feb mar apr mai jun jul aug sep okt nov des},
15
14
 
16
15
  :date_format => '%d.%m.%Y',
17
16
  :full_format => '%e. %B %Y',
data/locales/nl.rb CHANGED
@@ -3,10 +3,12 @@ module R18n
3
3
  class Locales::Nl < Locale
4
4
  set :title => 'Nederlands',
5
5
 
6
- :wday_names => %w{zondag maandag dinsdag woensdag donderdag vrijdag zaterdag},
6
+ :wday_names => %w{zondag maandag dinsdag woensdag donderdag vrijdag
7
+ zaterdag},
7
8
  :wday_abbrs => %w{zo ma di wo do vr za},
8
9
 
9
- :month_names => %w{januari februari maart april mei juni juli augustus september oktober november december},
10
+ :month_names => %w{januari februari maart april mei juni juli augustus
11
+ september oktober november december},
10
12
  :month_abbrs => %w{jan feb mrt apr mei jun jul aug sep okt nov dec},
11
13
 
12
14
  :time_am => '\'s ochtends',
data/locales/pt-br.rb CHANGED
@@ -4,7 +4,6 @@ require File.join(File.dirname(__FILE__), 'pt')
4
4
  module R18n::Locales
5
5
  class PtBr < Pt
6
6
  set :title => 'Português brasileiro',
7
- :code => 'pt-BR',
8
7
  :sublocales => %w{pt en}
9
8
  end
10
9
  end
data/locales/pt.rb CHANGED
@@ -2,7 +2,6 @@
2
2
  module R18n
3
3
  class Locales::Pt < R18n::Locale
4
4
  set :title => 'Português',
5
- :code => 'pt',
6
5
 
7
6
  :wday_names => %w{domingo segunda-feira terça-feira quarta-feira
8
7
  quinta-feira sexta-feira sábado},
data/locales/sv-se.rb CHANGED
@@ -2,8 +2,7 @@
2
2
  module R18n
3
3
  class Locales::SvSe < Locale
4
4
  set :title => 'Svenska',
5
- :code => 'sv-SE',
6
- :sublocales => %w{sv},
5
+ :sublocales => %w{sv en},
7
6
 
8
7
  :wday_names => %w{söndag måndag tisdag onsdag torsdag fredag
9
8
  lördag},
@@ -17,6 +16,6 @@ module R18n
17
16
  :full_format => '%e %B %Y',
18
17
 
19
18
  :number_decimal => ",",
20
- :number_group => "."
19
+ :number_group => "."
21
20
  end
22
21
  end
data/locales/th.rb CHANGED
@@ -17,7 +17,7 @@ module R18n
17
17
  :year_format => '_, %Y',
18
18
 
19
19
  :number_decimal => ".",
20
- :number_group => ","
20
+ :number_group => ","
21
21
 
22
22
  def strftime(time, format)
23
23
  year = (time.year + 543).to_s
data/locales/tr.rb CHANGED
@@ -8,7 +8,7 @@ module R18n
8
8
  Cumartesi},
9
9
  :wday_abbrs => %w{Paz Pzt Sal Çar Per Cum Cmt},
10
10
 
11
- :month_names => %w{Ocak Şubat Mart Nisan Mayıs Haziran Temmuz
11
+ :month_names => %w{Ocak Şubat Mart Nisan Mayıs Haziran Temmuz
12
12
  Ağustos Eylül Ekim Kasım Aralık},
13
13
  :month_abbrs => %w{Oca Şub Mar Nis May Haz Tem Ağu Eyl Eki Kas Ara},
14
14
 
@@ -18,8 +18,6 @@ module R18n
18
18
  :time_format => '%H:%M',
19
19
 
20
20
  :number_decimal => ".",
21
- :number_group => ","
22
-
23
-
21
+ :number_group => ","
24
22
  end
25
23
  end
data/locales/zh-cn.rb ADDED
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+ module R18n
3
+ class Locales::ZhCn < R18n::Locale
4
+ set :title => '简体中文',
5
+ :sublocales => %w{zh en}
6
+ end
7
+ end
data/locales/zh-tw.rb ADDED
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+ module R18n
3
+ class Locales::ZhTw < R18n::Locale
4
+ set :title => '繁體中文',
5
+ :sublocales => %w{zh en}
6
+ end
7
+ end
data/r18n-core.gemspec CHANGED
@@ -11,18 +11,17 @@ Gem::Specification.new do |s|
11
11
  It has nice Ruby-style syntax, filters, flexible locales, custom loaders,
12
12
  translation support for any classes, time and number localization, several
13
13
  user language support, agnostic core package with out-of-box support for
14
- Rails, Sinatra, Merb and desktop applications.
14
+ Rails, Sinatra and desktop applications.
15
15
  EOF
16
16
 
17
- s.files = `git ls-files`.split("\n")
18
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
- s.extra_rdoc_files = ['README.rdoc', 'LICENSE', 'ChangeLog']
20
- s.require_path = 'lib'
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.extra_rdoc_files = ['README.md', 'LICENSE', 'ChangeLog']
20
+ s.require_path = 'lib'
21
21
 
22
- s.author = 'Andrey "A.I." Sitnik'
23
- s.email = 'andrey@sitnik.ru'
24
- s.homepage = 'http://r18n.rubyforge.org/'
25
- s.rubyforge_project = 'r18n-core'
22
+ s.author = 'Andrey "A.I." Sitnik'
23
+ s.email = 'andrey@sitnik.ru'
24
+ s.homepage = 'https://github.com/ai/r18n'
26
25
 
27
26
  s.add_development_dependency "bundler", [">= 1.0.10"]
28
27
  s.add_development_dependency "yard", [">= 0"]
@@ -30,6 +29,7 @@ Gem::Specification.new do |s|
30
29
  s.add_development_dependency "rspec-core", [">= 0"]
31
30
  s.add_development_dependency "rspec-expectations", [">= 0"]
32
31
  s.add_development_dependency "rspec-mocks", [">= 0"]
33
- s.add_development_dependency "maruku", [">= 0"]
32
+ s.add_development_dependency "kramdown", [">= 0"]
34
33
  s.add_development_dependency "RedCloth", [">= 0"]
34
+ s.add_development_dependency "redcarpet", [">= 0"]
35
35
  end
data/spec/filters_spec.rb CHANGED
@@ -147,7 +147,7 @@ describe R18n::Filters do
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
- @i18n.files(0).should == '0 files'
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
@@ -172,7 +172,8 @@ describe R18n::Filters do
172
172
  end
173
173
 
174
174
  it "should format untranslated" do
175
- @i18n.in.not.to_s.should == 'in.[not]'
175
+ @i18n.in.not.to_s.should == 'in.[not]'
176
+ @i18n.in.not.to_str.should == 'in.[not]'
176
177
 
177
178
  R18n::Filters.off(:untranslated)
178
179
  @i18n.in.not.to_s.should == 'in.not'
@@ -198,8 +199,17 @@ describe R18n::Filters do
198
199
  it "should format untranslated for web" do
199
200
  R18n::Filters.off(:untranslated)
200
201
  R18n::Filters.on(:untranslated_html)
201
- @i18n.in.not.to_s.should == 'in.<span style="color: red">not</span>'
202
- @i18n['<b>'].to_s.should == '<span style="color: red">&lt;b&gt;</span>'
202
+ @i18n.in.not.to_s.should == 'in.<span style="color: red">[not]</span>'
203
+ @i18n['<b>'].to_s.should == '<span style="color: red">[&lt;b&gt;]</span>'
204
+ end
205
+
206
+ it "should allow to set custom filters" do
207
+ R18n::Filters.add(R18n::Untranslated, :a) { |v, c| "a #{v}" }
208
+ R18n::Filters.off(:a)
209
+
210
+ html = R18n::I18n.new('en', DIR, :off_filters => :untranslated,
211
+ :on_filters => [:untranslated_html, :a])
212
+ html.in.not.to_s.should == 'a in.<span style="color: red">[not]</span>'
203
213
  end
204
214
 
205
215
  it "should have filter for escape HTML" do
@@ -224,7 +234,7 @@ describe R18n::Filters do
224
234
  end
225
235
 
226
236
  it "should have Markdown filter" do
227
- @i18n.markdown.simple.should == '<p><strong>Hi!</strong></p>'
237
+ @i18n.markdown.simple.should == "<p><strong>Hi!</strong></p>\n"
228
238
  end
229
239
 
230
240
  it "should have Textile filter" do
@@ -232,13 +242,34 @@ describe R18n::Filters do
232
242
  end
233
243
 
234
244
  it "should HTML escape before Markdown and Textile filters" do
235
- @i18n.markdown.html.should == '<p><strong>Hi!</strong> <br /></p>'
245
+ @i18n.markdown.html.should == "<p><strong>Hi!</strong> <br /></p>\n"
236
246
  @i18n.textile.html.should == '<p><em>Hi!</em><br /></p>'
237
247
 
238
248
  R18n::Filters.on(:global_escape_html)
239
249
  @i18n.reload!
240
- @i18n.markdown.html.should == '<p><strong>Hi!</strong> &#60;br /&#62;</p>'
250
+ @i18n.markdown.html.should == "<p><strong>Hi!</strong> &lt;br /&gt;</p>\n"
241
251
  @i18n.textile.html.should == '<p><em>Hi!</em>&lt;br /&gt;</p>'
242
252
  end
243
253
 
254
+ it "should allow to listen filters adding" do
255
+ R18n::Filters.listen {
256
+ R18n::Filters.add(String, :a) { }
257
+ }.should == [R18n::Filters.defined[:a]]
258
+ end
259
+
260
+ it "should escape variables if ActiveSupport is loaded" do
261
+ @i18n.escape_params('<br>').should == '<b><br></b>'
262
+ require 'active_support'
263
+ @i18n.escape_params('<br>').should == '<b>&lt;br&gt;</b>'
264
+ end
265
+
266
+ it "should use SafeBuffer if it is loaded" do
267
+ require 'active_support'
268
+
269
+ R18n::Filters.on(:global_escape_html)
270
+ @i18n.reload!
271
+
272
+ @i18n.greater('<b>'.html_safe).should == '1 &lt; 2 is <b>'
273
+ end
274
+
244
275
  end
data/spec/i18n_spec.rb CHANGED
@@ -26,13 +26,13 @@ describe R18n::I18n do
26
26
 
27
27
  it "should load locales" do
28
28
  i18n = R18n::I18n.new('en', DIR)
29
- i18n.locales.should == [R18n::Locale.load('en')]
29
+ i18n.locales.should == [R18n.locale('en')]
30
30
 
31
31
  i18n = R18n::I18n.new(['ru', 'no-LC'], DIR)
32
- i18n.locales.should == [R18n::Locale.load('ru'),
32
+ i18n.locales.should == [R18n.locale('ru'),
33
33
  R18n::UnsupportedLocale.new('no-LC'),
34
34
  R18n::UnsupportedLocale.new('no'),
35
- R18n::Locale.load('en')]
35
+ R18n.locale('en')]
36
36
  end
37
37
 
38
38
  it "should return translations loaders" do
@@ -42,7 +42,7 @@ describe R18n::I18n do
42
42
 
43
43
  it "should load translations by loader" do
44
44
  loader = Class.new do
45
- def available; [R18n::Locale.load('en')]; end
45
+ def available; [R18n.locale('en')]; end
46
46
  def load(locale); { 'custom' => 'Custom' }; end
47
47
  end
48
48
  R18n::I18n.new('en', loader.new).custom.should == 'Custom'
@@ -51,7 +51,7 @@ describe R18n::I18n do
51
51
  it "should pass parameters to default loader" do
52
52
  loader = Class.new do
53
53
  def initialize(param); @param = param; end
54
- def available; [R18n::Locale.load('en')]; end
54
+ def available; [R18n.locale('en')]; end
55
55
  def load(locale); { 'custom' => @param }; end
56
56
  end
57
57
  R18n.default_loader = loader
@@ -110,13 +110,10 @@ describe R18n::I18n do
110
110
  end
111
111
 
112
112
  it "should return available translations" do
113
- R18n::I18n.available_locales(DIR).should =~ [R18n::Locale.load('no-lc'),
114
- R18n::Locale.load('ru'),
115
- R18n::Locale.load('en')]
116
113
  i18n = R18n::I18n.new('en', DIR)
117
- i18n.available_locales.should =~ [R18n::Locale.load('no-lc'),
118
- R18n::Locale.load('ru'),
119
- R18n::Locale.load('en')]
114
+ i18n.available_locales.should =~ [R18n.locale('no-lc'),
115
+ R18n.locale('ru'),
116
+ R18n.locale('en')]
120
117
  end
121
118
 
122
119
  it "should cache translations" do
@@ -174,7 +171,7 @@ describe R18n::I18n do
174
171
  it "should reload translations" do
175
172
  loader = Class.new do
176
173
  @@answer = 1
177
- def available; [R18n::Locale.load('en')]; end
174
+ def available; [R18n.locale('en')]; end
178
175
  def load(locale); { 'one' => @@answer }; end
179
176
  end
180
177
 
@@ -194,21 +191,21 @@ describe R18n::I18n do
194
191
 
195
192
  it "should return first locale with locale file" do
196
193
  i18n = R18n::I18n.new(['no-TR', 'no-LC', 'ru', 'en'], DIR)
197
- i18n.locale.should == R18n::Locale.load('no-LC')
198
- i18n.locale.base.should == R18n::Locale.load('ru')
194
+ i18n.locale.should == R18n.locale('no-LC')
195
+ i18n.locale.base.should == R18n.locale('ru')
199
196
  end
200
197
 
201
198
  it "should localize objects" do
202
199
  i18n = R18n::I18n.new('ru')
203
200
 
204
201
  i18n.l(-123456789).should == '−123 456 789'
205
- i18n.l(-12345.67).should == '−12 345,67'
202
+ i18n.l(-12345.67).should == '−12 345,67'
206
203
 
207
204
  time = Time.at(0).utc
208
- i18n.l(time, '%A').should == 'Четверг'
209
- i18n.l(time, :month).should == 'Январь'
205
+ i18n.l(time, '%A').should == 'Четверг'
206
+ i18n.l(time, :month).should == 'Январь'
210
207
  i18n.l(time, :standard).should == '01.01.1970 00:00'
211
- i18n.l(time, :full).should == ' 1 января 1970 00:00'
208
+ i18n.l(time, :full).should == ' 1 января 1970 00:00'
212
209
 
213
210
  i18n.l(Date.new(0)).should == '01.01.0000'
214
211
  end
data/spec/locale_spec.rb CHANGED
@@ -3,8 +3,8 @@ require File.expand_path('../spec_helper', __FILE__)
3
3
 
4
4
  describe R18n::Locale do
5
5
  before :all do
6
- @ru = R18n::Locale.load('ru')
7
- @en = R18n::Locale.load('en')
6
+ @ru = R18n.locale('ru')
7
+ @en = R18n.locale('en')
8
8
  end
9
9
 
10
10
  it "should return all available locales" do
@@ -34,12 +34,12 @@ describe R18n::Locale do
34
34
  end
35
35
 
36
36
  it "should load locale by Symbol" do
37
- R18n::Locale.load(:ru).should == R18n::Locale.load('ru')
37
+ R18n.locale(:ru).should == R18n.locale('ru')
38
38
  end
39
39
 
40
40
  it "should be equal to another locale with same code" do
41
41
  @en.should_not == @ru
42
- @en.should == R18n::Locale.load('en')
42
+ @en.should == R18n.locale('en')
43
43
  end
44
44
 
45
45
  it "should print human readable representation" do
@@ -55,7 +55,7 @@ describe R18n::Locale do
55
55
  it "should use UnsupportedLocale if locale file isn't exists" do
56
56
  @en.should be_supported
57
57
 
58
- unsupported = R18n::Locale.load('no-LC')
58
+ unsupported = R18n.locale('no-LC')
59
59
  unsupported.should_not be_supported
60
60
  unsupported.should be_a(R18n::UnsupportedLocale)
61
61
 
@@ -76,7 +76,7 @@ describe R18n::Locale do
76
76
  end
77
77
 
78
78
  it "should translate month, week days and am/pm names in strftime" do
79
- i18n = R18n::I18n.new 'ru'
79
+ i18n = R18n::I18n.new('ru')
80
80
  time = Time.at(0).utc
81
81
 
82
82
  @ru.localize(time, '%a %A').should == 'Чтв Четверг'
@@ -84,6 +84,11 @@ describe R18n::Locale do
84
84
  @ru.localize(time, '%H:%M%p').should == '00:00 утра'
85
85
  end
86
86
 
87
+ it "should generate locale code by locale class name" do
88
+ R18n.locale('ru').code.should == 'ru'
89
+ R18n.locale('zh-CN').code.should == 'zh-CN'
90
+ end
91
+
87
92
  it "should localize date for human" do
88
93
  i18n = R18n::I18n.new('en')
89
94
 
@@ -141,26 +146,26 @@ describe R18n::Locale do
141
146
  end
142
147
 
143
148
  it "should delete slashed from locale for security reasons" do
144
- locale = R18n::Locale.load('../spec/translations/general/en')
149
+ locale = R18n.locale('../spec/translations/general/en')
145
150
  locale.should be_a(R18n::UnsupportedLocale)
146
151
  end
147
152
 
148
153
  it "should ignore code case in locales" do
149
- upcase = R18n::Locale.load('RU')
150
- downcase = R18n::Locale.load('ru')
154
+ upcase = R18n.locale('RU')
155
+ downcase = R18n.locale('ru')
151
156
  upcase.should == downcase
152
- upcase.code.should == 'ru'
157
+ upcase.code.should == 'ru'
153
158
  downcase.code.should == 'ru'
154
159
 
155
- upcase = R18n::Locale.load('no-LC')
156
- downcase = R18n::Locale.load('no-lc')
160
+ upcase = R18n.locale('no-LC')
161
+ downcase = R18n.locale('no-lc')
157
162
  upcase.should == downcase
158
- upcase.code.should == 'no-lc'
163
+ upcase.code.should == 'no-lc'
159
164
  downcase.code.should == 'no-lc'
160
165
  end
161
166
 
162
167
  it "should load locale with underscore" do
163
- R18n::Locale.load('no_LC').code.should == 'no-lc'
168
+ R18n.locale('no_LC').code.should == 'no-lc'
164
169
  end
165
170
 
166
171
  end
@@ -2,7 +2,7 @@ require File.expand_path('../../spec_helper', __FILE__)
2
2
 
3
3
  describe R18n::Locales::Cs do
4
4
  it "should use Czech pluralization" do
5
- cs = R18n::Locale.load('cs')
5
+ cs = R18n.locale('cs')
6
6
  cs.pluralize(0).should == 0
7
7
  cs.pluralize(1).should == 1
8
8
 
@@ -2,7 +2,7 @@ require File.expand_path('../../spec_helper', __FILE__)
2
2
 
3
3
  describe R18n::Locales::Pl do
4
4
  it "should use Polish pluralization" do
5
- pl = R18n::Locale.load 'pl'
5
+ pl = R18n.locale('pl')
6
6
  pl.pluralize(0).should == 0
7
7
  pl.pluralize(1).should == 1
8
8
 
@@ -2,7 +2,7 @@ require File.expand_path('../../spec_helper', __FILE__)
2
2
 
3
3
  describe R18n::Locales::Ru do
4
4
  it "should use Russian pluralization" do
5
- ru = R18n::Locale.load 'ru'
5
+ ru = R18n.locale('ru')
6
6
  ru.pluralize(0).should == 0
7
7
 
8
8
  ru.pluralize(1).should == 1
@@ -2,7 +2,7 @@ require File.expand_path('../../spec_helper', __FILE__)
2
2
 
3
3
  describe R18n::Locales::Sk do
4
4
  it "should use Slovak pluralization" do
5
- sk = R18n::Locale.load('Sk')
5
+ sk = R18n.locale('Sk')
6
6
  sk.pluralize(0).should == 0
7
7
  sk.pluralize(1).should == 1
8
8
 
data/spec/r18n_spec.rb CHANGED
@@ -6,6 +6,7 @@ describe R18n do
6
6
 
7
7
  after do
8
8
  R18n.default_loader = R18n::Loader::YAML
9
+ R18n.default_places = nil
9
10
  R18n.reset
10
11
  end
11
12
 
@@ -31,38 +32,58 @@ describe R18n do
31
32
  it "shuld create I18n object by shortcut" do
32
33
  R18n.set('en', DIR)
33
34
  R18n.get.should be_a(R18n::I18n)
34
- R18n.get.locales.should == [R18n::Locale.load('en')]
35
+ R18n.get.locales.should == [R18n.locale('en')]
35
36
  R18n.get.translation_places.should == [R18n::Loader::YAML.new(DIR)]
36
37
  end
37
38
 
38
- it "should store I18n via thread_set" do
39
- i18n = R18n::I18n.new('en')
40
- R18n.thread_set(i18n)
41
- R18n.get.should == i18n
42
-
43
- R18n.reset
44
- R18n.get.should be_nil
39
+ it "should allow to return I18n arguments in setter block" do
40
+ R18n.set { 'en' }
41
+ R18n.get.locales.should == [R18n.locale('en')]
45
42
  end
46
43
 
47
44
  it "should reset I18n objects and cache" do
48
45
  R18n.cache[:a] = 1
49
- R18n.thread_set(R18n::I18n.new('en'))
46
+ R18n.set('en')
47
+ R18n.thread_set('en')
50
48
 
51
49
  R18n.reset
52
50
  R18n.get.should be_nil
53
51
  R18n.cache.should be_empty
54
52
  end
55
53
 
56
- it "should thread_set setter to I18n" do
54
+ it "should store I18n via thread_set" do
57
55
  i18n = R18n::I18n.new('en')
58
56
  R18n.thread_set(i18n)
57
+ R18n.get.should == i18n
59
58
 
60
59
  i18n = R18n::I18n.new('ru')
61
60
  R18n.thread_set { i18n }
62
-
63
61
  R18n.get.should == i18n
64
62
  end
65
63
 
64
+ it "should allow to temporary change locale" do
65
+ R18n.default_places = DIR
66
+ R18n.change('en').locales.should == [R18n.locale('en')]
67
+ R18n.change('en').should have(1).translation_places
68
+ R18n.change('en').translation_places.first.dir.should == DIR.to_s
69
+ end
70
+
71
+ it "should allow to temporary change current locales" do
72
+ R18n.set('ru')
73
+ R18n.change('en').locales.should == [R18n.locale('en'), R18n.locale('ru')]
74
+ R18n.change('en').translation_places.should == R18n.get.translation_places
75
+ R18n.get.locale.code.should.should == 'ru'
76
+ end
77
+
78
+ it "should allow to get Locale to temporary change" do
79
+ R18n.set('ru')
80
+ R18n.change(R18n.locale('en')).locale.code.should == 'en'
81
+ end
82
+
83
+ it "should have shortcut to load locale" do
84
+ R18n.locale('ru').should == R18n::Locale.load('ru')
85
+ end
86
+
66
87
  it "should store default loader class" do
67
88
  R18n.default_loader.should == R18n::Loader::YAML
68
89
  R18n.default_loader = Class
@@ -89,16 +110,11 @@ describe R18n do
89
110
  end
90
111
 
91
112
  it "should merge hash recursively" do
92
- a = { :a => 1,
93
- :b => {:ba => 1, :bb => 1},
94
- :c => 1 }
95
- b = { :b => {:bb => 2, :bc => 2},
96
- :c => 2 }
113
+ a = { :a => 1, :b => {:ba => 1, :bb => 1}, :c => 1 }
114
+ b = { :b => {:bb => 2, :bc => 2}, :c => 2 }
97
115
 
98
116
  R18n::Utils.deep_merge!(a, b)
99
- a.should == { :a => 1,
100
- :b => { :ba => 1, :bb => 2, :bc => 2 },
101
- :c => 2 }
117
+ a.should == { :a => 1, :b => { :ba => 1, :bb => 2, :bc => 2 }, :c => 2 }
102
118
  end
103
119
 
104
120
  it "should have l and t methods" do
@@ -108,13 +124,39 @@ describe R18n do
108
124
  end
109
125
 
110
126
  it "should have helpers mixin" do
111
- obj = R18n::I18n.new 'en'
127
+ obj = R18n::I18n.new('en')
112
128
  R18n.set(obj)
113
129
 
114
- r18n.should == obj
115
- i18n.should == obj
130
+ r18n.should == obj
131
+ i18n.should == obj
116
132
  t.yes.should == 'Yes'
117
133
  l(Time.at(0).utc).should == '01/01/1970 00:00'
118
134
  end
119
135
 
136
+ it "should return available translations" do
137
+ R18n.available_locales(DIR).should =~ [R18n.locale('no-lc'),
138
+ R18n.locale('ru'),
139
+ R18n.locale('en')]
140
+ end
141
+
142
+ it "should use default places" do
143
+ R18n.default_places = DIR
144
+ R18n.set('en')
145
+ t.one.should == 'One'
146
+ R18n.available_locales.should =~ [R18n.locale('ru'),
147
+ R18n.locale('en'),
148
+ R18n.locale('no-lc')]
149
+ end
150
+
151
+ it "should set default places by block" do
152
+ R18n.default_places { DIR }
153
+ R18n.default_places.should == DIR
154
+ end
155
+
156
+ it "should allow to ignore default places" do
157
+ R18n.default_places = DIR
158
+ i18n = R18n::I18n.new('en', nil)
159
+ i18n.one.should_not be_translated
160
+ end
161
+
120
162
  end