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.
- 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/i18n_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::I18n do
|
@@ -13,31 +12,31 @@ describe R18n::I18n do
|
|
13
12
|
end
|
14
13
|
|
15
14
|
it "parses HTTP_ACCEPT_LANGUAGE" do
|
16
|
-
R18n::I18n.parse_http(nil).
|
17
|
-
R18n::I18n.parse_http('').
|
18
|
-
R18n::I18n.parse_http('ru,en;q=0.9').
|
19
|
-
R18n::I18n.parse_http('ru;q=0.8,en;q=0.9').
|
15
|
+
expect(R18n::I18n.parse_http(nil)).to eq([])
|
16
|
+
expect(R18n::I18n.parse_http('')).to eq([])
|
17
|
+
expect(R18n::I18n.parse_http('ru,en;q=0.9')).to eq(['ru', 'en'])
|
18
|
+
expect(R18n::I18n.parse_http('ru;q=0.8,en;q=0.9')).to eq(['en', 'ru'])
|
20
19
|
end
|
21
20
|
|
22
21
|
it "has default locale" do
|
23
22
|
R18n::I18n.default = 'ru'
|
24
|
-
R18n::I18n.default.
|
23
|
+
expect(R18n::I18n.default).to eq('ru')
|
25
24
|
end
|
26
25
|
|
27
26
|
it "loads locales" do
|
28
27
|
i18n = R18n::I18n.new('en', DIR)
|
29
|
-
i18n.locales.
|
28
|
+
expect(i18n.locales).to eq([R18n.locale('en')])
|
30
29
|
|
31
30
|
i18n = R18n::I18n.new(['ru', 'nolocale-DL'], DIR)
|
32
|
-
i18n.locales.
|
31
|
+
expect(i18n.locales).to eq([R18n.locale('ru'),
|
33
32
|
R18n::UnsupportedLocale.new('nolocale-DL'),
|
34
33
|
R18n::UnsupportedLocale.new('nolocale'),
|
35
|
-
R18n.locale('en')]
|
34
|
+
R18n.locale('en')])
|
36
35
|
end
|
37
36
|
|
38
37
|
it "returns translations loaders" do
|
39
38
|
i18n = R18n::I18n.new('en', DIR)
|
40
|
-
i18n.translation_places.
|
39
|
+
expect(i18n.translation_places).to eq([R18n::Loader::YAML.new(DIR)])
|
41
40
|
end
|
42
41
|
|
43
42
|
it "loads translations by loader" do
|
@@ -45,7 +44,7 @@ describe R18n::I18n do
|
|
45
44
|
def available; [R18n.locale('en')]; end
|
46
45
|
def load(locale); { 'custom' => 'Custom' }; end
|
47
46
|
end
|
48
|
-
R18n::I18n.new('en', loader.new).custom.
|
47
|
+
expect(R18n::I18n.new('en', loader.new).custom).to eq('Custom')
|
49
48
|
end
|
50
49
|
|
51
50
|
it "passes parameters to default loader" do
|
@@ -55,129 +54,129 @@ describe R18n::I18n do
|
|
55
54
|
def load(locale); { 'custom' => @param }; end
|
56
55
|
end
|
57
56
|
R18n.default_loader = loader
|
58
|
-
R18n::I18n.new('en', 'default').custom.
|
57
|
+
expect(R18n::I18n.new('en', 'default').custom).to eq('default')
|
59
58
|
end
|
60
59
|
|
61
60
|
it "loads translations" do
|
62
61
|
i18n = R18n::I18n.new(['ru', 'en'], DIR)
|
63
|
-
i18n.one.
|
64
|
-
i18n[:one].
|
65
|
-
i18n['one'].
|
66
|
-
i18n.only.english.
|
62
|
+
expect(i18n.one).to eq('Один')
|
63
|
+
expect(i18n[:one]).to eq('Один')
|
64
|
+
expect(i18n['one']).to eq('Один')
|
65
|
+
expect(i18n.only.english).to eq('Only in English')
|
67
66
|
end
|
68
67
|
|
69
68
|
it "loads translations from several dirs" do
|
70
69
|
i18n = R18n::I18n.new(['nolocale', 'en'], [TWO, DIR])
|
71
|
-
i18n.in.two.
|
72
|
-
i18n.in.another.level.
|
70
|
+
expect(i18n.in.two).to eq('Two')
|
71
|
+
expect(i18n.in.another.level).to eq('Hierarchical')
|
73
72
|
end
|
74
73
|
|
75
74
|
it "uses extension places" do
|
76
75
|
R18n.extension_places << EXT
|
77
76
|
|
78
77
|
i18n = R18n::I18n.new('en', DIR)
|
79
|
-
i18n.ext.
|
80
|
-
i18n.one.
|
78
|
+
expect(i18n.ext).to eq('Extension')
|
79
|
+
expect(i18n.one).to eq('One')
|
81
80
|
end
|
82
81
|
|
83
82
|
it "doesn't use extension without app translations with same locale" do
|
84
83
|
R18n.extension_places << EXT
|
85
84
|
|
86
85
|
i18n = R18n::I18n.new(['notransl', 'en'], DIR)
|
87
|
-
i18n.ext.
|
86
|
+
expect(i18n.ext).to eq('Extension')
|
88
87
|
end
|
89
88
|
|
90
89
|
it "ignores case on loading" do
|
91
90
|
i18n = R18n::I18n.new('nolocale', [DIR])
|
92
|
-
i18n.one.
|
91
|
+
expect(i18n.one).to eq('ONE')
|
93
92
|
|
94
93
|
i18n = R18n::I18n.new('nolocale', [DIR])
|
95
|
-
i18n.one.
|
94
|
+
expect(i18n.one).to eq('ONE')
|
96
95
|
end
|
97
96
|
|
98
97
|
it "loads default translation" do
|
99
98
|
i18n = R18n::I18n.new('nolocale', DIR)
|
100
|
-
i18n.one.
|
101
|
-
i18n.two.
|
99
|
+
expect(i18n.one).to eq('ONE')
|
100
|
+
expect(i18n.two).to eq('Two')
|
102
101
|
end
|
103
102
|
|
104
103
|
it "loads sublocales for first locale" do
|
105
104
|
R18n::I18n.default = 'notransl'
|
106
105
|
|
107
106
|
i18n = R18n::I18n.new('ru', DIR)
|
108
|
-
i18n.one.
|
109
|
-
i18n.two.
|
107
|
+
expect(i18n.one).to eq('Один')
|
108
|
+
expect(i18n.two).to eq('Two')
|
110
109
|
end
|
111
110
|
|
112
111
|
it "returns available translations" do
|
113
112
|
i18n = R18n::I18n.new('en', DIR)
|
114
|
-
i18n.available_locales.
|
113
|
+
expect(i18n.available_locales).to match_array([R18n.locale('nolocale'),
|
115
114
|
R18n.locale('ru'),
|
116
|
-
R18n.locale('en')]
|
115
|
+
R18n.locale('en')])
|
117
116
|
end
|
118
117
|
|
119
118
|
it "caches translations" do
|
120
119
|
counter = CounterLoader.new('en')
|
121
120
|
|
122
121
|
R18n::I18n.new('en', counter)
|
123
|
-
counter.loaded.
|
122
|
+
expect(counter.loaded).to eq(1)
|
124
123
|
|
125
124
|
R18n::I18n.new('en', counter)
|
126
|
-
counter.loaded.
|
125
|
+
expect(counter.loaded).to eq(1)
|
127
126
|
|
128
127
|
R18n.clear_cache!
|
129
128
|
R18n::I18n.new('en', counter)
|
130
|
-
counter.loaded.
|
129
|
+
expect(counter.loaded).to eq(2)
|
131
130
|
end
|
132
131
|
|
133
132
|
it "doesn't clear cache when custom filters are specified" do
|
134
133
|
counter = CounterLoader.new('en')
|
135
134
|
|
136
|
-
R18n::I18n.new('en', counter,
|
137
|
-
:
|
138
|
-
counter.loaded.
|
135
|
+
R18n::I18n.new('en', counter,
|
136
|
+
off_filters: :untranslated, on_filters: :untranslated_html)
|
137
|
+
expect(counter.loaded).to eq(1)
|
139
138
|
|
140
|
-
R18n::I18n.new('en', counter,
|
141
|
-
:
|
142
|
-
counter.loaded.
|
139
|
+
R18n::I18n.new('en', counter,
|
140
|
+
off_filters: :untranslated, on_filters: :untranslated_html)
|
141
|
+
expect(counter.loaded).to eq(1)
|
143
142
|
end
|
144
143
|
|
145
144
|
it "caches translations by used locales" do
|
146
145
|
counter = CounterLoader.new('en', 'ru')
|
147
146
|
|
148
147
|
R18n::I18n.new('en', counter)
|
149
|
-
counter.loaded.
|
148
|
+
expect(counter.loaded).to eq(1)
|
150
149
|
|
151
150
|
R18n::I18n.new(['en', 'fr'], counter)
|
152
|
-
counter.loaded.
|
151
|
+
expect(counter.loaded).to eq(1)
|
153
152
|
|
154
153
|
R18n::I18n.new(['en', 'ru'], counter)
|
155
|
-
counter.loaded.
|
154
|
+
expect(counter.loaded).to eq(3)
|
156
155
|
|
157
156
|
R18n::I18n.new(['ru', 'en'], counter)
|
158
|
-
counter.loaded.
|
157
|
+
expect(counter.loaded).to eq(5)
|
159
158
|
end
|
160
159
|
|
161
160
|
it "caches translations by places" do
|
162
161
|
counter = CounterLoader.new('en', 'ru')
|
163
162
|
|
164
163
|
R18n::I18n.new('en', counter)
|
165
|
-
counter.loaded.
|
164
|
+
expect(counter.loaded).to eq(1)
|
166
165
|
|
167
166
|
R18n::I18n.new('en', [counter, DIR])
|
168
|
-
counter.loaded.
|
167
|
+
expect(counter.loaded).to eq(2)
|
169
168
|
|
170
169
|
R18n.extension_places << EXT
|
171
170
|
R18n::I18n.new('en', counter)
|
172
|
-
counter.loaded.
|
171
|
+
expect(counter.loaded).to eq(3)
|
173
172
|
|
174
173
|
same = CounterLoader.new('en', 'ru')
|
175
174
|
R18n::I18n.new('en', same)
|
176
|
-
same.loaded.
|
175
|
+
expect(same.loaded).to eq(0)
|
177
176
|
|
178
177
|
different = CounterLoader.new('en', 'fr')
|
179
178
|
R18n::I18n.new('en', different)
|
180
|
-
different.loaded.
|
179
|
+
expect(different.loaded).to eq(1)
|
181
180
|
end
|
182
181
|
|
183
182
|
it "reloads translations" do
|
@@ -191,50 +190,49 @@ describe R18n::I18n do
|
|
191
190
|
end
|
192
191
|
|
193
192
|
i18n = R18n::I18n.new('en', loader.new)
|
194
|
-
i18n.one.
|
193
|
+
expect(i18n.one).to eq(1)
|
195
194
|
|
196
195
|
i18n.reload!
|
197
|
-
i18n.one.
|
196
|
+
expect(i18n.one).to eq(2)
|
198
197
|
end
|
199
198
|
|
200
199
|
it "returns translations" do
|
201
200
|
i18n = R18n::I18n.new('en', DIR)
|
202
|
-
i18n.t.
|
203
|
-
i18n.t.one.
|
201
|
+
expect(i18n.t).to be_kind_of(R18n::Translation)
|
202
|
+
expect(i18n.t.one).to eq('One')
|
204
203
|
end
|
205
204
|
|
206
205
|
it "returns first locale with locale file" do
|
207
206
|
i18n = R18n::I18n.new(['notransl', 'nolocale', 'ru', 'en'], DIR)
|
208
|
-
i18n.locale.
|
209
|
-
i18n.locale.base.
|
207
|
+
expect(i18n.locale).to eq(R18n.locale('nolocale'))
|
208
|
+
expect(i18n.locale.base).to eq(R18n.locale('ru'))
|
210
209
|
end
|
211
210
|
|
212
211
|
it "localizes objects" do
|
213
212
|
i18n = R18n::I18n.new('ru')
|
214
213
|
|
215
|
-
i18n.l(-123456789).
|
216
|
-
i18n.l(-12345.67).
|
214
|
+
expect(i18n.l(-123456789)).to eq('−123 456 789')
|
215
|
+
expect(i18n.l(-12345.67)).to eq('−12 345,67')
|
217
216
|
|
218
217
|
time = Time.at(0).utc
|
219
|
-
i18n.l(time, '%A').
|
220
|
-
i18n.l(time, :month).
|
221
|
-
i18n.l(time, :standard).
|
222
|
-
i18n.l(time, :full).
|
218
|
+
expect(i18n.l(time, '%A')).to eq('Четверг')
|
219
|
+
expect(i18n.l(time, :month)).to eq('Январь')
|
220
|
+
expect(i18n.l(time, :standard)).to eq('01.01.1970 00:00')
|
221
|
+
expect(i18n.l(time, :full)).to eq(' 1 января 1970 00:00')
|
223
222
|
|
224
|
-
i18n.l(Date.new(0)).
|
223
|
+
expect(i18n.l(Date.new(0))).to eq('01.01.0000')
|
225
224
|
end
|
226
225
|
|
227
|
-
it "returns marshalizable values"
|
228
|
-
i18n = R18n::I18n.new('en', DIR, :
|
229
|
-
:
|
226
|
+
it "returns marshalizable values" do
|
227
|
+
i18n = R18n::I18n.new('en', DIR, off_filters: :untranslated,
|
228
|
+
on_filters: :untranslated_html)
|
230
229
|
demarsh = Marshal.load(Marshal.dump(i18n.t.one))
|
231
230
|
|
232
|
-
i18n.t.one.
|
233
|
-
i18n.t.one.path.
|
234
|
-
i18n.t.one.locale.
|
231
|
+
expect(i18n.t.one).to eq(demarsh)
|
232
|
+
expect(i18n.t.one.path).to eq(demarsh.path)
|
233
|
+
expect(i18n.t.one.locale).to eq(demarsh.locale)
|
235
234
|
|
236
235
|
demarsh = Marshal.load(Marshal.dump(i18n.t.no_translation))
|
237
|
-
i18n.t.no_translation.
|
236
|
+
expect(i18n.t.no_translation).to eq(demarsh)
|
238
237
|
end
|
239
|
-
|
240
238
|
end
|
data/spec/locale_spec.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
require File.expand_path('../spec_helper', __FILE__)
|
3
2
|
require 'bigdecimal'
|
4
3
|
|
@@ -9,100 +8,100 @@ describe R18n::Locale do
|
|
9
8
|
end
|
10
9
|
|
11
10
|
it "returns all available locales" do
|
12
|
-
R18n::Locale.available.class.
|
13
|
-
R18n::Locale.available.
|
11
|
+
expect(R18n::Locale.available.class).to eq(Array)
|
12
|
+
expect(R18n::Locale.available).not_to be_empty
|
14
13
|
end
|
15
14
|
|
16
15
|
it "checks is locale exists" do
|
17
|
-
R18n::Locale.exists?('ru').
|
18
|
-
R18n::Locale.exists?('nolocale').
|
16
|
+
expect(R18n::Locale.exists?('ru')).to be true
|
17
|
+
expect(R18n::Locale.exists?('nolocale')).to be false
|
19
18
|
end
|
20
19
|
|
21
20
|
it "sets locale properties" do
|
22
21
|
locale_class = Class.new(R18n::Locale) do
|
23
|
-
set :
|
24
|
-
set :
|
22
|
+
set one: 1
|
23
|
+
set two: 2
|
25
24
|
end
|
26
25
|
locale = locale_class.new
|
27
|
-
locale.one.
|
28
|
-
locale.two.
|
26
|
+
expect(locale.one).to eq(1)
|
27
|
+
expect(locale.two).to eq(2)
|
29
28
|
end
|
30
29
|
|
31
30
|
it "loads locale" do
|
32
|
-
@ru.class.
|
33
|
-
@ru.code.
|
34
|
-
@ru.title.
|
31
|
+
expect(@ru.class).to eq(R18n::Locales::Ru)
|
32
|
+
expect(@ru.code).to eq('ru')
|
33
|
+
expect(@ru.title).to eq('Русский')
|
35
34
|
end
|
36
35
|
|
37
36
|
it "loads locale by Symbol" do
|
38
|
-
R18n.locale(:ru).
|
37
|
+
expect(R18n.locale(:ru)).to eq(R18n.locale('ru'))
|
39
38
|
end
|
40
39
|
|
41
40
|
it "equals to another locale with same code" do
|
42
|
-
@en.
|
43
|
-
@en.
|
41
|
+
expect(@en).not_to eq(@ru)
|
42
|
+
expect(@en).to eq(R18n.locale('en'))
|
44
43
|
end
|
45
44
|
|
46
45
|
it "prints human readable representation" do
|
47
|
-
@ru.inspect.
|
46
|
+
expect(@ru.inspect).to eq('Locale ru (Русский)')
|
48
47
|
end
|
49
48
|
|
50
49
|
it "returns pluralization type by elements count" do
|
51
|
-
@en.pluralize(0).
|
52
|
-
@en.pluralize(1).
|
53
|
-
@en.pluralize(5).
|
50
|
+
expect(@en.pluralize(0)).to eq(0)
|
51
|
+
expect(@en.pluralize(1)).to eq(1)
|
52
|
+
expect(@en.pluralize(5)).to eq('n')
|
54
53
|
end
|
55
54
|
|
56
55
|
it "uses UnsupportedLocale if locale file isn't exists" do
|
57
|
-
@en.
|
56
|
+
expect(@en).to be_supported
|
58
57
|
|
59
58
|
unsupported = R18n.locale('nolocale-DL')
|
60
|
-
unsupported.
|
61
|
-
unsupported.
|
59
|
+
expect(unsupported).not_to be_supported
|
60
|
+
expect(unsupported).to be_kind_of(R18n::UnsupportedLocale)
|
62
61
|
|
63
|
-
unsupported.code.downcase.
|
64
|
-
unsupported.title.downcase.
|
65
|
-
unsupported.ltr
|
62
|
+
expect(unsupported.code.downcase).to eq('nolocale-dl')
|
63
|
+
expect(unsupported.title.downcase).to eq('nolocale-dl')
|
64
|
+
expect(unsupported.ltr?).to be true
|
66
65
|
|
67
|
-
unsupported.pluralize(5).
|
68
|
-
unsupported.inspect.downcase.
|
66
|
+
expect(unsupported.pluralize(5)).to eq('n')
|
67
|
+
expect(unsupported.inspect.downcase).to eq('unsupported locale nolocale-dl')
|
69
68
|
end
|
70
69
|
|
71
70
|
it "formats number in local traditions" do
|
72
|
-
@en.localize(-123456789).
|
71
|
+
expect(@en.localize(-123456789)).to eq("−123,456,789")
|
73
72
|
end
|
74
73
|
|
75
74
|
it "formats float in local traditions" do
|
76
|
-
@en.localize(-12345.67).
|
77
|
-
@en.localize(BigDecimal.new("-12345.67")).
|
75
|
+
expect(@en.localize(-12345.67)).to eq("−12,345.67")
|
76
|
+
expect(@en.localize(BigDecimal.new("-12345.67"))).to eq("−12,345.67")
|
78
77
|
end
|
79
78
|
|
80
79
|
it "translates month, week days and am/pm names in strftime" do
|
81
80
|
i18n = R18n::I18n.new('ru')
|
82
81
|
time = Time.at(0).utc
|
83
82
|
|
84
|
-
@ru.localize(time, '%a %A').
|
85
|
-
@ru.localize(time, '%b %B').
|
86
|
-
@ru.localize(time, '%H:%M%p').
|
83
|
+
expect(@ru.localize(time, '%a %A')).to eq('Чтв Четверг')
|
84
|
+
expect(@ru.localize(time, '%b %B')).to eq('янв января')
|
85
|
+
expect(@ru.localize(time, '%H:%M%p')).to eq('00:00 утра')
|
87
86
|
end
|
88
87
|
|
89
88
|
it "generates locale code by locale class name" do
|
90
|
-
R18n.locale('ru').code.
|
91
|
-
R18n.locale('zh-CN').code.
|
89
|
+
expect(R18n.locale('ru').code).to eq('ru')
|
90
|
+
expect(R18n.locale('zh-CN').code).to eq('zh-CN')
|
92
91
|
end
|
93
92
|
|
94
93
|
it "localizes date for human" do
|
95
94
|
i18n = R18n::I18n.new('en')
|
96
95
|
|
97
|
-
@en.localize(Date.today + 2, :human, i18n).
|
98
|
-
@en.localize(Date.today + 1, :human, i18n).
|
99
|
-
@en.localize(Date.today, :human, i18n).
|
100
|
-
@en.localize(Date.today - 1, :human, i18n).
|
101
|
-
@en.localize(Date.today - 3, :human, i18n).
|
96
|
+
expect(@en.localize(Date.today + 2, :human, i18n)).to eq('after 2 days')
|
97
|
+
expect(@en.localize(Date.today + 1, :human, i18n)).to eq('tomorrow')
|
98
|
+
expect(@en.localize(Date.today, :human, i18n)).to eq('today')
|
99
|
+
expect(@en.localize(Date.today - 1, :human, i18n)).to eq('yesterday')
|
100
|
+
expect(@en.localize(Date.today - 3, :human, i18n)).to eq('3 days ago')
|
102
101
|
|
103
|
-
y2k = Date.parse('2000-
|
104
|
-
@en.localize(y2k, :human, i18n, y2k + 8 ).
|
105
|
-
@en.localize(y2k, :human, i18n, y2k - 365).
|
102
|
+
y2k = Date.parse('2000-05-08')
|
103
|
+
expect(@en.localize(y2k, :human, i18n, y2k + 8 )).to eq('8th of May')
|
104
|
+
expect(@en.localize(y2k, :human, i18n, y2k - 365)).to eq('8th of May, 2000')
|
106
105
|
end
|
107
106
|
|
108
107
|
it "localizes times for human" do
|
@@ -112,62 +111,63 @@ describe R18n::Locale do
|
|
112
111
|
zero = Time.at(0).utc
|
113
112
|
p = [:human, R18n::I18n.new('en'), zero]
|
114
113
|
|
115
|
-
@en.localize( zero + 7 * day, *p).
|
116
|
-
@en.localize( zero + 50 * hour, *p).
|
117
|
-
@en.localize( zero + 25 * hour, *p).
|
118
|
-
@en.localize( zero + 70 * minute, *p).
|
119
|
-
@en.localize( zero + hour, *p).
|
120
|
-
@en.localize( zero + 38 * minute, *p).
|
121
|
-
@en.localize( zero + 5, *p).
|
122
|
-
@en.localize( zero - 15, *p).
|
123
|
-
@en.localize( zero - minute, *p).
|
124
|
-
@en.localize( zero - hour + 59, *p).
|
125
|
-
@en.localize( zero - 2 * hour, *p).
|
126
|
-
@en.localize( zero - 13 * hour, *p).
|
127
|
-
@en.localize( zero - 50 * hour, *p).
|
128
|
-
|
129
|
-
@en.localize( zero - 9 * day, *p).
|
130
|
-
|
114
|
+
expect(@en.localize( zero + 7 * day, *p)).to eq('8th of January 00:00')
|
115
|
+
expect(@en.localize( zero + 50 * hour, *p)).to eq('after 2 days 02:00')
|
116
|
+
expect(@en.localize( zero + 25 * hour, *p)).to eq('tomorrow 01:00')
|
117
|
+
expect(@en.localize( zero + 70 * minute, *p)).to eq('after 1 hour')
|
118
|
+
expect(@en.localize( zero + hour, *p)).to eq('after 1 hour')
|
119
|
+
expect(@en.localize( zero + 38 * minute, *p)).to eq('after 38 minutes')
|
120
|
+
expect(@en.localize( zero + 5, *p)).to eq('now')
|
121
|
+
expect(@en.localize( zero - 15, *p)).to eq('now')
|
122
|
+
expect(@en.localize( zero - minute, *p)).to eq('1 minute ago')
|
123
|
+
expect(@en.localize( zero - hour + 59, *p)).to eq('59 minutes ago')
|
124
|
+
expect(@en.localize( zero - 2 * hour, *p)).to eq('2 hours ago')
|
125
|
+
expect(@en.localize( zero - 13 * hour, *p)).to eq('yesterday 11:00')
|
126
|
+
expect(@en.localize( zero - 50 * hour, *p)).to eq('3 days ago 22:00')
|
127
|
+
|
128
|
+
expect(@en.localize( zero - 9 * day, *p)).to eq(
|
129
|
+
'23rd of December, 1969 00:00')
|
130
|
+
expect(@en.localize( zero - 365 * day, *p)).to eq(
|
131
|
+
'1st of January, 1969 00:00')
|
131
132
|
end
|
132
133
|
|
133
134
|
it "uses standard formatter by default" do
|
134
|
-
@ru.localize(Time.at(0).utc).
|
135
|
+
expect(@ru.localize(Time.at(0).utc)).to eq('01.01.1970 00:00')
|
135
136
|
end
|
136
137
|
|
137
138
|
it "doesn't localize time without i18n object" do
|
138
|
-
@ru.localize(Time.at(0)).
|
139
|
-
@ru.localize(Time.at(0), :full).
|
139
|
+
expect(@ru.localize(Time.at(0))).not_to eq(Time.at(0).to_s)
|
140
|
+
expect(@ru.localize(Time.at(0), :full)).not_to eq(Time.at(0).to_s)
|
140
141
|
|
141
|
-
@ru.localize(Time.at(0), :human).
|
142
|
+
expect(@ru.localize(Time.at(0), :human)).to eq(Time.at(0).to_s)
|
142
143
|
end
|
143
144
|
|
144
145
|
it "raises error on unknown formatter" do
|
145
|
-
|
146
|
+
expect {
|
146
147
|
@ru.localize(Time.at(0).utc, R18n::I18n.new('ru'), :unknown)
|
147
|
-
}.
|
148
|
+
}.to raise_error(ArgumentError, /formatter/)
|
148
149
|
end
|
149
150
|
|
150
151
|
it "deletes slashed from locale for security reasons" do
|
151
152
|
locale = R18n.locale('../spec/translations/general/en')
|
152
|
-
locale.
|
153
|
+
expect(locale).to be_kind_of(R18n::UnsupportedLocale)
|
153
154
|
end
|
154
155
|
|
155
156
|
it "ignores code case in locales" do
|
156
157
|
upcase = R18n.locale('RU')
|
157
158
|
downcase = R18n.locale('ru')
|
158
|
-
upcase.
|
159
|
-
upcase.code.
|
160
|
-
downcase.code.
|
159
|
+
expect(upcase).to eq(downcase)
|
160
|
+
expect(upcase.code).to eq('ru')
|
161
|
+
expect(downcase.code).to eq('ru')
|
161
162
|
|
162
163
|
upcase = R18n.locale('nolocale')
|
163
164
|
downcase = R18n.locale('nolocale')
|
164
|
-
upcase.
|
165
|
-
upcase.code.
|
166
|
-
downcase.code.
|
165
|
+
expect(upcase).to eq(downcase)
|
166
|
+
expect(upcase.code).to eq('nolocale')
|
167
|
+
expect(downcase.code).to eq('nolocale')
|
167
168
|
end
|
168
169
|
|
169
170
|
it "loads locale with underscore" do
|
170
|
-
R18n.locale('nolocale-DL').code.
|
171
|
+
expect(R18n.locale('nolocale-DL').code).to eq('nolocale-dl')
|
171
172
|
end
|
172
|
-
|
173
173
|
end
|
data/spec/locales/cs_spec.rb
CHANGED
@@ -3,21 +3,21 @@ require File.expand_path('../../spec_helper', __FILE__)
|
|
3
3
|
describe R18n::Locales::Cs do
|
4
4
|
it "uses Czech pluralization" do
|
5
5
|
cs = R18n.locale('cs')
|
6
|
-
cs.pluralize(0).
|
7
|
-
cs.pluralize(1).
|
6
|
+
expect(cs.pluralize(0)).to eq(0)
|
7
|
+
expect(cs.pluralize(1)).to eq(1)
|
8
8
|
|
9
|
-
cs.pluralize(2).
|
10
|
-
cs.pluralize(3).
|
11
|
-
cs.pluralize(4).
|
9
|
+
expect(cs.pluralize(2)).to eq(2)
|
10
|
+
expect(cs.pluralize(3)).to eq(2)
|
11
|
+
expect(cs.pluralize(4)).to eq(2)
|
12
12
|
|
13
|
-
cs.pluralize(5).
|
14
|
-
cs.pluralize(21).
|
15
|
-
cs.pluralize(11).
|
16
|
-
cs.pluralize(12).
|
17
|
-
cs.pluralize(22).
|
18
|
-
cs.pluralize(57).
|
19
|
-
cs.pluralize(101).
|
20
|
-
cs.pluralize(102).
|
21
|
-
cs.pluralize(111).
|
13
|
+
expect(cs.pluralize(5)).to eq('n')
|
14
|
+
expect(cs.pluralize(21)).to eq('n')
|
15
|
+
expect(cs.pluralize(11)).to eq('n')
|
16
|
+
expect(cs.pluralize(12)).to eq('n')
|
17
|
+
expect(cs.pluralize(22)).to eq('n')
|
18
|
+
expect(cs.pluralize(57)).to eq('n')
|
19
|
+
expect(cs.pluralize(101)).to eq('n')
|
20
|
+
expect(cs.pluralize(102)).to eq('n')
|
21
|
+
expect(cs.pluralize(111)).to eq('n')
|
22
22
|
end
|
23
23
|
end
|
data/spec/locales/en-us_spec.rb
CHANGED
@@ -3,11 +3,11 @@ require File.expand_path('../../spec_helper', __FILE__)
|
|
3
3
|
describe R18n::Locales::EnUs do
|
4
4
|
it "formats American English date" do
|
5
5
|
enUS = R18n::I18n.new('en-US')
|
6
|
-
enUS.l(Date.parse('2009-05-01'), :full).
|
7
|
-
enUS.l(Date.parse('2009-05-02'), :full).
|
8
|
-
enUS.l(Date.parse('2009-05-03'), :full).
|
9
|
-
enUS.l(Date.parse('2009-05-04'), :full).
|
10
|
-
enUS.l(Date.parse('2009-05-11'), :full).
|
11
|
-
enUS.l(Date.parse('2009-05-21'), :full).
|
6
|
+
expect(enUS.l(Date.parse('2009-05-01'), :full)).to eq('May 1st, 2009')
|
7
|
+
expect(enUS.l(Date.parse('2009-05-02'), :full)).to eq('May 2nd, 2009')
|
8
|
+
expect(enUS.l(Date.parse('2009-05-03'), :full)).to eq('May 3rd, 2009')
|
9
|
+
expect(enUS.l(Date.parse('2009-05-04'), :full)).to eq('May 4th, 2009')
|
10
|
+
expect(enUS.l(Date.parse('2009-05-11'), :full)).to eq('May 11th, 2009')
|
11
|
+
expect(enUS.l(Date.parse('2009-05-21'), :full)).to eq('May 21st, 2009')
|
12
12
|
end
|
13
13
|
end
|
data/spec/locales/en_spec.rb
CHANGED
@@ -3,11 +3,11 @@ require File.expand_path('../../spec_helper', __FILE__)
|
|
3
3
|
describe R18n::Locales::En do
|
4
4
|
it "formats English date" do
|
5
5
|
en = R18n::I18n.new('en')
|
6
|
-
en.l(Date.parse('2009-05-01'), :full).
|
7
|
-
en.l(Date.parse('2009-05-02'), :full).
|
8
|
-
en.l(Date.parse('2009-05-03'), :full).
|
9
|
-
en.l(Date.parse('2009-05-04'), :full).
|
10
|
-
en.l(Date.parse('2009-05-11'), :full).
|
11
|
-
en.l(Date.parse('2009-05-21'), :full).
|
6
|
+
expect(en.l(Date.parse('2009-05-01'), :full)).to eq('1st of May, 2009')
|
7
|
+
expect(en.l(Date.parse('2009-05-02'), :full)).to eq('2nd of May, 2009')
|
8
|
+
expect(en.l(Date.parse('2009-05-03'), :full)).to eq('3rd of May, 2009')
|
9
|
+
expect(en.l(Date.parse('2009-05-04'), :full)).to eq('4th of May, 2009')
|
10
|
+
expect(en.l(Date.parse('2009-05-11'), :full)).to eq('11th of May, 2009')
|
11
|
+
expect(en.l(Date.parse('2009-05-21'), :full)).to eq('21st of May, 2009')
|
12
12
|
end
|
13
13
|
end
|
data/spec/locales/fr_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require File.expand_path('../../spec_helper', __FILE__)
|
|
3
3
|
describe R18n::Locales::Fr do
|
4
4
|
it "formats French date" do
|
5
5
|
fr = R18n::I18n.new('fr')
|
6
|
-
fr.l(Date.parse('2009-07-01'), :full).
|
7
|
-
fr.l(Date.parse('2009-07-02'), :full).
|
6
|
+
expect(fr.l(Date.parse('2009-07-01'), :full)).to eq('1er juillet 2009')
|
7
|
+
expect(fr.l(Date.parse('2009-07-02'), :full)).to eq(' 2 juillet 2009')
|
8
8
|
end
|
9
9
|
end
|