r18n-core 1.1.6 → 1.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/spec/locale_spec.rb CHANGED
@@ -8,17 +8,17 @@ describe R18n::Locale do
8
8
  @en = R18n.locale('en')
9
9
  end
10
10
 
11
- it "should return all available locales" do
11
+ it "returns all available locales" do
12
12
  R18n::Locale.available.class.should == Array
13
13
  R18n::Locale.available.should_not be_empty
14
14
  end
15
15
 
16
- it "should check is locale exists" do
16
+ it "checks is locale exists" do
17
17
  R18n::Locale.exists?('ru').should be_true
18
18
  R18n::Locale.exists?('nolocale').should be_false
19
19
  end
20
20
 
21
- it "should set locale properties" do
21
+ it "sets locale properties" do
22
22
  locale_class = Class.new(R18n::Locale) do
23
23
  set :one => 1
24
24
  set :two => 2
@@ -28,32 +28,32 @@ describe R18n::Locale do
28
28
  locale.two.should == 2
29
29
  end
30
30
 
31
- it "should load locale" do
31
+ it "loads locale" do
32
32
  @ru.class.should == R18n::Locales::Ru
33
33
  @ru.code.should == 'ru'
34
34
  @ru.title.should == 'Русский'
35
35
  end
36
36
 
37
- it "should load locale by Symbol" do
37
+ it "loads locale by Symbol" do
38
38
  R18n.locale(:ru).should == R18n.locale('ru')
39
39
  end
40
40
 
41
- it "should be equal to another locale with same code" do
41
+ it "equals to another locale with same code" do
42
42
  @en.should_not == @ru
43
43
  @en.should == R18n.locale('en')
44
44
  end
45
45
 
46
- it "should print human readable representation" do
46
+ it "prints human readable representation" do
47
47
  @ru.inspect.should == 'Locale ru (Русский)'
48
48
  end
49
49
 
50
- it "should return pluralization type by elements count" do
50
+ it "returns pluralization type by elements count" do
51
51
  @en.pluralize(0).should == 0
52
52
  @en.pluralize(1).should == 1
53
53
  @en.pluralize(5).should == 'n'
54
54
  end
55
55
 
56
- it "should use UnsupportedLocale if locale file isn't exists" do
56
+ it "uses UnsupportedLocale if locale file isn't exists" do
57
57
  @en.should be_supported
58
58
 
59
59
  unsupported = R18n.locale('nolocale-DL')
@@ -68,16 +68,16 @@ describe R18n::Locale do
68
68
  unsupported.inspect.downcase.should == 'unsupported locale nolocale-dl'
69
69
  end
70
70
 
71
- it "should format number in local traditions" do
71
+ it "formats number in local traditions" do
72
72
  @en.localize(-123456789).should == "−123,456,789"
73
73
  end
74
74
 
75
- it "should format float in local traditions" do
75
+ it "formats float in local traditions" do
76
76
  @en.localize(-12345.67).should == "−12,345.67"
77
77
  @en.localize(BigDecimal.new("-12345.67")).should == "−12,345.67"
78
78
  end
79
79
 
80
- it "should translate month, week days and am/pm names in strftime" do
80
+ it "translates month, week days and am/pm names in strftime" do
81
81
  i18n = R18n::I18n.new('ru')
82
82
  time = Time.at(0).utc
83
83
 
@@ -86,12 +86,12 @@ describe R18n::Locale do
86
86
  @ru.localize(time, '%H:%M%p').should == '00:00 утра'
87
87
  end
88
88
 
89
- it "should generate locale code by locale class name" do
89
+ it "generates locale code by locale class name" do
90
90
  R18n.locale('ru').code.should == 'ru'
91
91
  R18n.locale('zh-CN').code.should == 'zh-CN'
92
92
  end
93
93
 
94
- it "should localize date for human" do
94
+ it "localizes date for human" do
95
95
  i18n = R18n::I18n.new('en')
96
96
 
97
97
  @en.localize(Date.today + 2, :human, i18n).should == 'after 2 days'
@@ -105,7 +105,7 @@ describe R18n::Locale do
105
105
  @en.localize(y2k, :human, i18n, y2k - 365).should == '8th of January, 2000'
106
106
  end
107
107
 
108
- it "should localize times for human" do
108
+ it "localizes times for human" do
109
109
  minute = 60
110
110
  hour = 60 * minute
111
111
  day = 24 * hour
@@ -130,29 +130,29 @@ describe R18n::Locale do
130
130
  @en.localize( zero - 365 * day, *p).should == '1st of January, 1969 00:00'
131
131
  end
132
132
 
133
- it "should use standard formatter by default" do
133
+ it "uses standard formatter by default" do
134
134
  @ru.localize(Time.at(0).utc).should == '01.01.1970 00:00'
135
135
  end
136
136
 
137
- it "shouldn't localize time without i18n object" do
137
+ it "doesn't localize time without i18n object" do
138
138
  @ru.localize(Time.at(0)).should_not == Time.at(0).to_s
139
139
  @ru.localize(Time.at(0), :full).should_not == Time.at(0).to_s
140
140
 
141
141
  @ru.localize(Time.at(0), :human).should == Time.at(0).to_s
142
142
  end
143
143
 
144
- it "should raise error on unknown formatter" do
144
+ it "raises error on unknown formatter" do
145
145
  lambda {
146
146
  @ru.localize(Time.at(0).utc, R18n::I18n.new('ru'), :unknown)
147
147
  }.should raise_error(ArgumentError, /formatter/)
148
148
  end
149
149
 
150
- it "should delete slashed from locale for security reasons" do
150
+ it "deletes slashed from locale for security reasons" do
151
151
  locale = R18n.locale('../spec/translations/general/en')
152
152
  locale.should be_a(R18n::UnsupportedLocale)
153
153
  end
154
154
 
155
- it "should ignore code case in locales" do
155
+ it "ignores code case in locales" do
156
156
  upcase = R18n.locale('RU')
157
157
  downcase = R18n.locale('ru')
158
158
  upcase.should == downcase
@@ -166,7 +166,7 @@ describe R18n::Locale do
166
166
  downcase.code.should == 'nolocale'
167
167
  end
168
168
 
169
- it "should load locale with underscore" do
169
+ it "loads locale with underscore" do
170
170
  R18n.locale('nolocale-DL').code.should == 'nolocale-dl'
171
171
  end
172
172
 
@@ -1,7 +1,7 @@
1
1
  require File.expand_path('../../spec_helper', __FILE__)
2
2
 
3
3
  describe R18n::Locales::Cs do
4
- it "should use Czech pluralization" do
4
+ it "uses Czech pluralization" do
5
5
  cs = R18n.locale('cs')
6
6
  cs.pluralize(0).should == 0
7
7
  cs.pluralize(1).should == 1
@@ -1,7 +1,7 @@
1
1
  require File.expand_path('../../spec_helper', __FILE__)
2
2
 
3
3
  describe R18n::Locales::EnUs do
4
- it "should format American English date" do
4
+ it "formats American English date" do
5
5
  enUS = R18n::I18n.new('en-US')
6
6
  enUS.l(Date.parse('2009-05-01'), :full).should == 'May 1st, 2009'
7
7
  enUS.l(Date.parse('2009-05-02'), :full).should == 'May 2nd, 2009'
@@ -1,7 +1,7 @@
1
1
  require File.expand_path('../../spec_helper', __FILE__)
2
2
 
3
3
  describe R18n::Locales::En do
4
- it "should format English date" do
4
+ it "formats English date" do
5
5
  en = R18n::I18n.new('en')
6
6
  en.l(Date.parse('2009-05-01'), :full).should == '1st of May, 2009'
7
7
  en.l(Date.parse('2009-05-02'), :full).should == '2nd of May, 2009'
@@ -1,7 +1,7 @@
1
1
  require File.expand_path('../../spec_helper', __FILE__)
2
2
 
3
3
  describe R18n::Locales::Fr do
4
- it "should format French date" do
4
+ it "formats French date" do
5
5
  fr = R18n::I18n.new('fr')
6
6
  fr.l(Date.parse('2009-07-01'), :full).should == '1er juillet 2009'
7
7
  fr.l(Date.parse('2009-07-02'), :full).should == ' 2 juillet 2009'
@@ -2,7 +2,7 @@
2
2
  require File.expand_path('../../spec_helper', __FILE__)
3
3
 
4
4
  describe R18n::Locales::Hu do
5
- it "should use Hungarian digits groups" do
5
+ it "uses Hungarian digits groups" do
6
6
  hu = R18n::I18n.new('hu')
7
7
  hu.l(1000).should == '1000'
8
8
  hu.l(10000).should == '10 000'
@@ -10,7 +10,7 @@ describe R18n::Locales::Hu do
10
10
  hu.l(100000).should == '100 000'
11
11
  end
12
12
 
13
- it "should use Hungarian time format" do
13
+ it "uses Hungarian time format" do
14
14
  hu = R18n::I18n.new('hu')
15
15
  hu.l(Time.at(0).utc).should == '1970. 01. 01., 00:00'
16
16
  hu.l(Time.at(0).utc, :full).should == '1970. január 1., 00:00'
@@ -2,7 +2,7 @@
2
2
  require File.expand_path('../../spec_helper', __FILE__)
3
3
 
4
4
  describe R18n::Locales::It do
5
- it "should format Italian date" do
5
+ it "formats Italian date" do
6
6
  italian = R18n::I18n.new('it')
7
7
  italian.l(Date.parse('2009-07-01'), :full).should == "1º luglio 2009"
8
8
  italian.l(Date.parse('2009-07-02'), :full).should == ' 2 luglio 2009'
@@ -1,7 +1,7 @@
1
1
  require File.expand_path('../../spec_helper', __FILE__)
2
2
 
3
3
  describe R18n::Locales::Pl do
4
- it "should use Polish pluralization" do
4
+ it "uses Polish pluralization" do
5
5
  pl = R18n.locale('pl')
6
6
  pl.pluralize(0).should == 0
7
7
  pl.pluralize(1).should == 1
@@ -1,7 +1,7 @@
1
1
  require File.expand_path('../../spec_helper', __FILE__)
2
2
 
3
3
  describe R18n::Locales::Ru do
4
- it "should use Russian pluralization" do
4
+ it "uses Russian pluralization" do
5
5
  ru = R18n.locale('ru')
6
6
  ru.pluralize(0).should == 0
7
7
 
@@ -1,7 +1,7 @@
1
1
  require File.expand_path('../../spec_helper', __FILE__)
2
2
 
3
3
  describe R18n::Locales::Sk do
4
- it "should use Slovak pluralization" do
4
+ it "uses Slovak pluralization" do
5
5
  sk = R18n.locale('Sk')
6
6
  sk.pluralize(0).should == 0
7
7
  sk.pluralize(1).should == 1
@@ -1,7 +1,7 @@
1
1
  require File.expand_path('../../spec_helper', __FILE__)
2
2
 
3
3
  describe R18n::Locales::Ru do
4
- it "should use Thai calendar" do
4
+ it "uses Thai calendar" do
5
5
  th = R18n::I18n.new('th')
6
6
  th.l(Time.at(0).utc, '%Y %y').should == '2513 13'
7
7
  th.l(Time.at(0).utc).should == '01/01/2513 00:00'
data/spec/r18n_spec.rb CHANGED
@@ -10,7 +10,7 @@ describe R18n do
10
10
  R18n.reset!
11
11
  end
12
12
 
13
- it "should store I18n" do
13
+ it "stores I18n" do
14
14
  i18n = R18n::I18n.new('en')
15
15
  R18n.set(i18n)
16
16
  R18n.get.should == i18n
@@ -19,7 +19,7 @@ describe R18n do
19
19
  R18n.get.should be_nil
20
20
  end
21
21
 
22
- it "should set setter to I18n" do
22
+ it "sets setter to I18n" do
23
23
  i18n = R18n::I18n.new('en')
24
24
  R18n.set(i18n)
25
25
 
@@ -29,25 +29,25 @@ describe R18n do
29
29
  R18n.get.should == i18n
30
30
  end
31
31
 
32
- it "shuld create I18n object by shortcut" do
32
+ it "creates I18n object by shortcut" do
33
33
  R18n.set('en', DIR)
34
34
  R18n.get.should be_a(R18n::I18n)
35
35
  R18n.get.locales.should == [R18n.locale('en')]
36
36
  R18n.get.translation_places.should == [R18n::Loader::YAML.new(DIR)]
37
37
  end
38
38
 
39
- it "should allow to return I18n arguments in setter block" do
39
+ it "allows to return I18n arguments in setter block" do
40
40
  R18n.set { 'en' }
41
41
  R18n.get.locales.should == [R18n.locale('en')]
42
42
  end
43
43
 
44
- it "should clear cache" do
44
+ it "clears cache" do
45
45
  R18n.cache[:a] = 1
46
46
  R18n.clear_cache!
47
47
  R18n.cache.should be_empty
48
48
  end
49
49
 
50
- it "should reset I18n objects and cache" do
50
+ it "resets I18n objects and cache" do
51
51
  R18n.cache[:a] = 1
52
52
  R18n.set('en')
53
53
  R18n.thread_set('en')
@@ -57,7 +57,7 @@ describe R18n do
57
57
  R18n.cache.should be_empty
58
58
  end
59
59
 
60
- it "should store I18n via thread_set" do
60
+ it "stores I18n via thread_set" do
61
61
  i18n = R18n::I18n.new('en')
62
62
  R18n.thread_set(i18n)
63
63
  R18n.get.should == i18n
@@ -67,36 +67,36 @@ describe R18n do
67
67
  R18n.get.should == i18n
68
68
  end
69
69
 
70
- it "should allow to temporary change locale" do
70
+ it "allows to temporary change locale" do
71
71
  R18n.default_places = DIR
72
72
  R18n.change('en').locales.should == [R18n.locale('en')]
73
73
  R18n.change('en').should have(1).translation_places
74
74
  R18n.change('en').translation_places.first.dir.should == DIR.to_s
75
75
  end
76
76
 
77
- it "should allow to temporary change current locales" do
77
+ it "allows to temporary change current locales" do
78
78
  R18n.set('ru')
79
79
  R18n.change('en').locales.should == [R18n.locale('en'), R18n.locale('ru')]
80
80
  R18n.change('en').translation_places.should == R18n.get.translation_places
81
81
  R18n.get.locale.code.should.should == 'ru'
82
82
  end
83
83
 
84
- it "should allow to get Locale to temporary change" do
84
+ it "allows to get Locale to temporary change" do
85
85
  R18n.set('ru')
86
86
  R18n.change(R18n.locale('en')).locale.code.should == 'en'
87
87
  end
88
88
 
89
- it "should have shortcut to load locale" do
89
+ it "has shortcut to load locale" do
90
90
  R18n.locale('ru').should == R18n::Locale.load('ru')
91
91
  end
92
92
 
93
- it "should store default loader class" do
93
+ it "stores default loader class" do
94
94
  R18n.default_loader.should == R18n::Loader::YAML
95
95
  R18n.default_loader = Class
96
96
  R18n.default_loader.should == Class
97
97
  end
98
98
 
99
- it "should store cache" do
99
+ it "stores cache" do
100
100
  R18n.cache.should be_a(Hash)
101
101
 
102
102
  R18n.cache = { 1 => 2 }
@@ -106,16 +106,16 @@ describe R18n do
106
106
  R18n.cache.should == { }
107
107
  end
108
108
 
109
- it "should convert Time to Date" do
110
- R18n::Utils.to_date(Time.now).should == Date.today
109
+ it "converts Time to Date" do
110
+ R18n::Utils.to_date(Time.now).should == Date.today
111
111
  end
112
112
 
113
- it "should map hash" do
113
+ it "maps hash" do
114
114
  R18n::Utils.hash_map({'a' => 1, 'b' => 2}) { |k, v| [k + 'a', v + 1] }.
115
115
  should == { 'aa' => 2, 'ba' => 3 }
116
116
  end
117
117
 
118
- it "should merge hash recursively" do
118
+ it "merges hash recursively" do
119
119
  a = { :a => 1, :b => {:ba => 1, :bb => 1}, :c => 1 }
120
120
  b = { :b => {:bb => 2, :bc => 2}, :c => 2 }
121
121
 
@@ -123,13 +123,13 @@ describe R18n do
123
123
  a.should == { :a => 1, :b => { :ba => 1, :bb => 2, :bc => 2 }, :c => 2 }
124
124
  end
125
125
 
126
- it "should have l and t methods" do
126
+ it "has l and t methods" do
127
127
  R18n.set('en')
128
128
  t.yes.should == 'Yes'
129
129
  l(Time.at(0).utc).should == '01/01/1970 00:00'
130
130
  end
131
131
 
132
- it "should have helpers mixin" do
132
+ it "has helpers mixin" do
133
133
  obj = R18n::I18n.new('en')
134
134
  R18n.set(obj)
135
135
 
@@ -139,13 +139,13 @@ describe R18n do
139
139
  l(Time.at(0).utc).should == '01/01/1970 00:00'
140
140
  end
141
141
 
142
- it "should return available translations" do
142
+ it "returns available translations" do
143
143
  R18n.available_locales(DIR).should =~ [R18n.locale('nolocale'),
144
144
  R18n.locale('ru'),
145
145
  R18n.locale('en')]
146
146
  end
147
147
 
148
- it "should use default places" do
148
+ it "uses default places" do
149
149
  R18n.default_places = DIR
150
150
  R18n.set('en')
151
151
  t.one.should == 'One'
@@ -154,12 +154,12 @@ describe R18n do
154
154
  R18n.locale('nolocale')]
155
155
  end
156
156
 
157
- it "should set default places by block" do
157
+ it "sets default places by block" do
158
158
  R18n.default_places { DIR }
159
159
  R18n.default_places.should == DIR
160
160
  end
161
161
 
162
- it "should allow to ignore default places" do
162
+ it "allows to ignore default places" do
163
163
  R18n.default_places = DIR
164
164
  i18n = R18n::I18n.new('en', nil)
165
165
  i18n.one.should_not be_translated
@@ -13,13 +13,13 @@ describe R18n::Translated do
13
13
  R18n.set('en')
14
14
  end
15
15
 
16
- it "should save methods map" do
16
+ it "saves methods map" do
17
17
  @user_class.translation :name, :methods => { :ru => :name_ru }
18
18
  @user_class.unlocalized_getters(:name).should == { 'ru' => 'name_ru' }
19
19
  @user_class.unlocalized_setters(:name).should == { 'ru' => 'name_ru=' }
20
20
  end
21
21
 
22
- it "should autodetect methods map" do
22
+ it "autodetects methods map" do
23
23
  @user_class.translation :name
24
24
  @user_class.unlocalized_getters(:name).should == {
25
25
  'en' => 'name_en', 'ru' => 'name_ru' }
@@ -27,11 +27,10 @@ describe R18n::Translated do
27
27
  'en' => 'name_en=', 'ru' => 'name_ru=' }
28
28
  end
29
29
 
30
- it "should translate methods" do
30
+ it "translates methods" do
31
31
  @user_class.translation :name
32
32
  user = @user_class.new
33
33
 
34
- user.name.should_not be_translated
35
34
  user.name = 'John'
36
35
  user.name.should == 'John'
37
36
 
@@ -41,7 +40,7 @@ describe R18n::Translated do
41
40
  user.name.should == 'Джон'
42
41
  end
43
42
 
44
- it "should return TranslatedString" do
43
+ it "returns TranslatedString" do
45
44
  class ::SomeTranslatedClass
46
45
  include R18n::Translated
47
46
  def name_en; 'John'; end
@@ -54,7 +53,7 @@ describe R18n::Translated do
54
53
  obj.name.path.should == 'SomeTranslatedClass#name'
55
54
  end
56
55
 
57
- it "should search translation by locales priority" do
56
+ it "searchs translation by locales priority" do
58
57
  @user_class.translation :name
59
58
  user = @user_class.new
60
59
 
@@ -63,7 +62,7 @@ describe R18n::Translated do
63
62
  user.name.locale.should == R18n.locale('ru')
64
63
  end
65
64
 
66
- it "should use default locale" do
65
+ it "uses default locale" do
67
66
  @user_class.translation :name
68
67
  user = @user_class.new
69
68
 
@@ -72,7 +71,7 @@ describe R18n::Translated do
72
71
  user.name.locale.should == R18n.locale('en')
73
72
  end
74
73
 
75
- it "should use filters" do
74
+ it "uses filters" do
76
75
  @user_class.class_eval do
77
76
  def age_en; {1 => '%1 year', 'n' => '%1 years'} end
78
77
  translation :age, :type => 'pl', :no_params => true
@@ -82,7 +81,7 @@ describe R18n::Translated do
82
81
  user.age(20).should == '20 years'
83
82
  end
84
83
 
85
- it "should send params to method if user want it" do
84
+ it "sends params to method if user want it" do
86
85
  @user_class.class_eval do
87
86
  def no_params_en(*params) params.join(' '); end
88
87
  def params_en(*params) params.join(' '); end
@@ -94,20 +93,7 @@ describe R18n::Translated do
94
93
  user.params(1, 2).should == '1 2'
95
94
  end
96
95
 
97
- it "should return Untranslated when can't find translation" do
98
- class ::SomeUntranslatedClass
99
- include R18n::Translated
100
-
101
- translation :no
102
- end
103
- obj = ::SomeUntranslatedClass.new
104
-
105
- obj.no.should be_a(R18n::Untranslated)
106
- obj.no.translated_path.should == 'SomeUntranslatedClass#'
107
- obj.no.untranslated_path.should == 'no'
108
- end
109
-
110
- it "should translate virtual methods" do
96
+ it "translates virtual methods" do
111
97
  @virtual_class = Class.new do
112
98
  include R18n::Translated
113
99
  translation :no_method, :methods => { :en => :no_method_en }
@@ -120,7 +106,7 @@ describe R18n::Translated do
120
106
  virtual.no_method.should == 'no_method_en'
121
107
  end
122
108
 
123
- it "should return original type of result" do
109
+ it "returns original type of result" do
124
110
  @user_class.class_eval do
125
111
  translation :name
126
112
  def name_en
@@ -132,7 +118,19 @@ describe R18n::Translated do
132
118
  user.name.should == :ivan
133
119
  end
134
120
 
135
- it "should allow to change I18n object" do
121
+ it "returns nil" do
122
+ @user_class.class_eval do
123
+ translation :name
124
+ def name_en
125
+ nil
126
+ end
127
+ end
128
+ user = @user_class.new
129
+
130
+ user.name.should be_nil
131
+ end
132
+
133
+ it "allows to change I18n object" do
136
134
  @user_class.class_eval do
137
135
  translation :name
138
136
  attr_accessor :r18n