r18n-core 3.1.1 → 5.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog.md +398 -0
  3. data/README.md +63 -47
  4. data/base/cy.yml +34 -0
  5. data/lib/r18n-core.rb +37 -38
  6. data/lib/r18n-core/filter_list.rb +21 -13
  7. data/lib/r18n-core/filters.rb +43 -48
  8. data/lib/r18n-core/helpers.rb +2 -2
  9. data/lib/r18n-core/i18n.rb +70 -78
  10. data/lib/r18n-core/locale.rb +137 -107
  11. data/lib/r18n-core/locales/af.rb +36 -0
  12. data/lib/r18n-core/locales/az.rb +38 -0
  13. data/lib/r18n-core/locales/bg.rb +29 -0
  14. data/{locales → lib/r18n-core/locales}/ca.rb +9 -6
  15. data/{locales → lib/r18n-core/locales}/cs.rb +15 -11
  16. data/lib/r18n-core/locales/cy.rb +50 -0
  17. data/{locales → lib/r18n-core/locales}/da.rb +10 -7
  18. data/lib/r18n-core/locales/de.rb +33 -0
  19. data/{locales → lib/r18n-core/locales}/en-au.rb +2 -2
  20. data/{locales → lib/r18n-core/locales}/en-gb.rb +2 -2
  21. data/{locales → lib/r18n-core/locales}/en-us.rb +4 -3
  22. data/lib/r18n-core/locales/en.rb +51 -0
  23. data/{locales → lib/r18n-core/locales}/eo.rb +6 -4
  24. data/lib/r18n-core/locales/es-cl.rb +16 -0
  25. data/{locales → lib/r18n-core/locales}/es-us.rb +5 -4
  26. data/{locales → lib/r18n-core/locales}/es.rb +7 -3
  27. data/{locales → lib/r18n-core/locales}/fa.rb +2 -2
  28. data/lib/r18n-core/locales/fi.rb +39 -0
  29. data/lib/r18n-core/locales/fr.rb +39 -0
  30. data/{locales → lib/r18n-core/locales}/gl.rb +5 -3
  31. data/{locales → lib/r18n-core/locales}/hr.rb +13 -10
  32. data/{locales → lib/r18n-core/locales}/hu.rb +10 -7
  33. data/{locales → lib/r18n-core/locales}/id.rb +8 -4
  34. data/lib/r18n-core/locales/it.rb +37 -0
  35. data/{locales → lib/r18n-core/locales}/ja.rb +5 -4
  36. data/{locales → lib/r18n-core/locales}/kk.rb +12 -8
  37. data/{locales → lib/r18n-core/locales}/ko.rb +0 -0
  38. data/lib/r18n-core/locales/lv.rb +46 -0
  39. data/lib/r18n-core/locales/mn.rb +30 -0
  40. data/{locales → lib/r18n-core/locales}/nb.rb +6 -4
  41. data/lib/r18n-core/locales/nl.rb +31 -0
  42. data/{locales → lib/r18n-core/locales}/no.rb +0 -0
  43. data/lib/r18n-core/locales/pl.rb +45 -0
  44. data/{locales → lib/r18n-core/locales}/pt-br.rb +1 -1
  45. data/lib/r18n-core/locales/pt.rb +37 -0
  46. data/lib/r18n-core/locales/ru.rb +46 -0
  47. data/{locales → lib/r18n-core/locales}/sk.rb +13 -9
  48. data/{locales → lib/r18n-core/locales}/sr-latn.rb +10 -8
  49. data/{locales → lib/r18n-core/locales}/sv-se.rb +7 -5
  50. data/lib/r18n-core/locales/th.rb +41 -0
  51. data/{locales → lib/r18n-core/locales}/tr.rb +7 -6
  52. data/lib/r18n-core/locales/uk.rb +31 -0
  53. data/lib/r18n-core/locales/vi.rb +37 -0
  54. data/{locales → lib/r18n-core/locales}/zh-cn.rb +2 -2
  55. data/{locales → lib/r18n-core/locales}/zh-tw.rb +4 -4
  56. data/{locales → lib/r18n-core/locales}/zh.rb +7 -4
  57. data/lib/r18n-core/translated.rb +38 -37
  58. data/lib/r18n-core/translated_string.rb +19 -8
  59. data/lib/r18n-core/translation.rb +24 -19
  60. data/lib/r18n-core/unsupported_locale.rb +14 -6
  61. data/lib/r18n-core/untranslated.rb +23 -7
  62. data/lib/r18n-core/utils.rb +19 -23
  63. data/lib/r18n-core/version.rb +1 -1
  64. data/lib/r18n-core/yaml_loader.rb +17 -13
  65. data/lib/r18n-core/yaml_methods.rb +3 -1
  66. metadata +245 -118
  67. data/.rspec +0 -1
  68. data/Rakefile +0 -13
  69. data/locales/af.rb +0 -32
  70. data/locales/az.rb +0 -34
  71. data/locales/bg.rb +0 -25
  72. data/locales/de.rb +0 -29
  73. data/locales/en.rb +0 -48
  74. data/locales/fi.rb +0 -35
  75. data/locales/fr.rb +0 -35
  76. data/locales/it.rb +0 -34
  77. data/locales/lv.rb +0 -41
  78. data/locales/mn.rb +0 -27
  79. data/locales/nl.rb +0 -28
  80. data/locales/pl.rb +0 -40
  81. data/locales/pt.rb +0 -29
  82. data/locales/ru.rb +0 -41
  83. data/locales/th.rb +0 -37
  84. data/locales/uk.rb +0 -27
  85. data/locales/vi.rb +0 -33
  86. data/r18n-core.gemspec +0 -29
  87. data/spec/filters_spec.rb +0 -324
  88. data/spec/i18n_spec.rb +0 -260
  89. data/spec/locale_spec.rb +0 -216
  90. data/spec/locales/cs_spec.rb +0 -23
  91. data/spec/locales/en-us_spec.rb +0 -13
  92. data/spec/locales/en_spec.rb +0 -13
  93. data/spec/locales/fa_spec.rb +0 -10
  94. data/spec/locales/fr_spec.rb +0 -9
  95. data/spec/locales/hu_spec.rb +0 -17
  96. data/spec/locales/it_spec.rb +0 -10
  97. data/spec/locales/no_spec.rb +0 -9
  98. data/spec/locales/pl_spec.rb +0 -23
  99. data/spec/locales/ru_spec.rb +0 -23
  100. data/spec/locales/sk_spec.rb +0 -23
  101. data/spec/locales/th_spec.rb +0 -9
  102. data/spec/locales/vi_spec.rb +0 -8
  103. data/spec/r18n_spec.rb +0 -172
  104. data/spec/spec_helper.rb +0 -41
  105. data/spec/translated_spec.rb +0 -163
  106. data/spec/translation_spec.rb +0 -164
  107. data/spec/translations/extension/deep/en.yml +0 -1
  108. data/spec/translations/extension/en.yml +0 -2
  109. data/spec/translations/extension/notransl.yml +0 -1
  110. data/spec/translations/general/en.yml +0 -47
  111. data/spec/translations/general/nolocale.yml +0 -6
  112. data/spec/translations/general/ru.yml +0 -7
  113. data/spec/translations/two/en.yml +0 -2
  114. data/spec/translations/two/fr.yml +0 -0
  115. data/spec/yaml_loader_spec.rb +0 -61
data/spec/i18n_spec.rb DELETED
@@ -1,260 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe R18n::I18n do
4
- before do
5
- @extension_places = R18n.extension_places.clone
6
- end
7
-
8
- after do
9
- R18n::I18n.default = 'en'
10
- R18n.default_loader = R18n::Loader::YAML
11
- R18n.extension_places = @extension_places
12
- end
13
-
14
- it 'parses HTTP_ACCEPT_LANGUAGE' do
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(%w[ru en])
18
- expect(R18n::I18n.parse_http('ru;q=0.8,en;q=0.9')).to eq(%w[en ru])
19
- end
20
-
21
- it 'has default locale' do
22
- R18n::I18n.default = 'ru'
23
- expect(R18n::I18n.default).to eq('ru')
24
- end
25
-
26
- it 'loads locales' do
27
- i18n = R18n::I18n.new('en', DIR)
28
- expect(i18n.locales).to eq([R18n.locale('en')])
29
-
30
- i18n = R18n::I18n.new(['ru', 'nolocale-DL'], DIR)
31
- expect(i18n.locales).to eq([
32
- R18n.locale('ru'),
33
- R18n::UnsupportedLocale.new('nolocale-DL'),
34
- R18n::UnsupportedLocale.new('nolocale'),
35
- R18n.locale('en')
36
- ])
37
- end
38
-
39
- it 'returns translations loaders' do
40
- i18n = R18n::I18n.new('en', DIR)
41
- expect(i18n.translation_places).to eq([R18n::Loader::YAML.new(DIR)])
42
- end
43
-
44
- it 'loads translations by loader' do
45
- loader = Class.new do
46
- def available
47
- [R18n.locale('en')]
48
- end
49
-
50
- def load(_locale)
51
- { 'custom' => 'Custom' }
52
- end
53
- end
54
- expect(R18n::I18n.new('en', loader.new).custom).to eq('Custom')
55
- end
56
-
57
- it 'passes parameters to default loader' do
58
- loader = Class.new do
59
- def initialize(param)
60
- @param = param
61
- end
62
-
63
- def available
64
- [R18n.locale('en')]
65
- end
66
-
67
- def load(_locale)
68
- { 'custom' => @param }
69
- end
70
- end
71
- R18n.default_loader = loader
72
- expect(R18n::I18n.new('en', 'default').custom).to eq('default')
73
- end
74
-
75
- it 'loads translations' do
76
- i18n = R18n::I18n.new(%w[ru en], DIR)
77
- expect(i18n.one).to eq('Один')
78
- expect(i18n[:one]).to eq('Один')
79
- expect(i18n['one']).to eq('Один')
80
- expect(i18n.only.english).to eq('Only in English')
81
- end
82
-
83
- it 'loads translations from several dirs' do
84
- i18n = R18n::I18n.new(%w[nolocale en], [TWO, DIR])
85
- expect(i18n.in.two).to eq('Two')
86
- expect(i18n.in.another.level).to eq('Hierarchical')
87
- end
88
-
89
- it 'uses extension places' do
90
- R18n.extension_places << EXT
91
-
92
- i18n = R18n::I18n.new('en', DIR)
93
- expect(i18n.ext).to eq('Extension')
94
- expect(i18n.one).to eq('One')
95
- end
96
-
97
- it "doesn't use extension without app translations with same locale" do
98
- R18n.extension_places << EXT
99
-
100
- i18n = R18n::I18n.new(%w[notransl en], DIR)
101
- expect(i18n.ext).to eq('Extension')
102
- end
103
-
104
- it 'ignores case on loading' do
105
- i18n = R18n::I18n.new('nolocale', [DIR])
106
- expect(i18n.one).to eq('ONE')
107
-
108
- i18n = R18n::I18n.new('nolocale', [DIR])
109
- expect(i18n.one).to eq('ONE')
110
- end
111
-
112
- it 'loads default translation' do
113
- i18n = R18n::I18n.new('nolocale', DIR)
114
- expect(i18n.one).to eq('ONE')
115
- expect(i18n.two).to eq('Two')
116
- end
117
-
118
- it 'loads sublocales for first locale' do
119
- R18n::I18n.default = 'notransl'
120
-
121
- i18n = R18n::I18n.new('ru', DIR)
122
- expect(i18n.one).to eq('Один')
123
- expect(i18n.two).to eq('Two')
124
- end
125
-
126
- it 'returns available translations' do
127
- i18n = R18n::I18n.new('en', DIR)
128
- expect(i18n.available_locales).to match_array([
129
- R18n.locale('nolocale'),
130
- R18n.locale('ru'),
131
- R18n.locale('en')
132
- ])
133
- end
134
-
135
- it 'caches translations' do
136
- counter = CounterLoader.new('en')
137
-
138
- R18n::I18n.new('en', counter)
139
- expect(counter.loaded).to eq(1)
140
-
141
- R18n::I18n.new('en', counter)
142
- expect(counter.loaded).to eq(1)
143
-
144
- R18n.clear_cache!
145
- R18n::I18n.new('en', counter)
146
- expect(counter.loaded).to eq(2)
147
- end
148
-
149
- it "doesn't clear cache when custom filters are specified" do
150
- counter = CounterLoader.new('en')
151
-
152
- R18n::I18n.new(
153
- 'en', counter, off_filters: :untranslated, on_filters: :untranslated_html
154
- )
155
- expect(counter.loaded).to eq(1)
156
-
157
- R18n::I18n.new(
158
- 'en', counter, off_filters: :untranslated, on_filters: :untranslated_html
159
- )
160
- expect(counter.loaded).to eq(1)
161
- end
162
-
163
- it 'caches translations by used locales' do
164
- counter = CounterLoader.new('en', 'ru')
165
-
166
- R18n::I18n.new('en', counter)
167
- expect(counter.loaded).to eq(1)
168
-
169
- R18n::I18n.new(%w[en fr], counter)
170
- expect(counter.loaded).to eq(1)
171
-
172
- R18n::I18n.new(%w[en ru], counter)
173
- expect(counter.loaded).to eq(3)
174
-
175
- R18n::I18n.new(%w[ru en], counter)
176
- expect(counter.loaded).to eq(5)
177
- end
178
-
179
- it 'caches translations by places' do
180
- counter = CounterLoader.new('en', 'ru')
181
-
182
- R18n::I18n.new('en', counter)
183
- expect(counter.loaded).to eq(1)
184
-
185
- R18n::I18n.new('en', [counter, DIR])
186
- expect(counter.loaded).to eq(2)
187
-
188
- R18n.extension_places << EXT
189
- R18n::I18n.new('en', counter)
190
- expect(counter.loaded).to eq(3)
191
-
192
- same = CounterLoader.new('en', 'ru')
193
- R18n::I18n.new('en', same)
194
- expect(same.loaded).to eq(0)
195
-
196
- different = CounterLoader.new('en', 'fr')
197
- R18n::I18n.new('en', different)
198
- expect(different.loaded).to eq(1)
199
- end
200
-
201
- it 'reloads translations' do
202
- loader = Class.new do
203
- def available
204
- [R18n.locale('en')]
205
- end
206
-
207
- def load(_locale)
208
- @answer ||= 0
209
- @answer += 1
210
- { 'one' => @answer }
211
- end
212
- end
213
-
214
- i18n = R18n::I18n.new('en', loader.new)
215
- expect(i18n.one).to eq(1)
216
-
217
- i18n.reload!
218
- expect(i18n.one).to eq(2)
219
- end
220
-
221
- it 'returns translations' do
222
- i18n = R18n::I18n.new('en', DIR)
223
- expect(i18n.t).to be_kind_of(R18n::Translation)
224
- expect(i18n.t.one).to eq('One')
225
- end
226
-
227
- it 'returns first locale with locale file' do
228
- i18n = R18n::I18n.new(%w[notransl nolocale ru en], DIR)
229
- expect(i18n.locale).to eq(R18n.locale('nolocale'))
230
- expect(i18n.locale.base).to eq(R18n.locale('ru'))
231
- end
232
-
233
- it 'localizes objects' do
234
- i18n = R18n::I18n.new('ru')
235
-
236
- expect(i18n.l(-123_456_789)).to eq('−123 456 789')
237
- expect(i18n.l(-12_345.67)).to eq('−12 345,67')
238
-
239
- time = Time.at(0).utc
240
- expect(i18n.l(time, '%A')).to eq('Четверг')
241
- expect(i18n.l(time, :month)).to eq('Январь')
242
- expect(i18n.l(time, :standard)).to eq('01.01.1970 00:00')
243
- expect(i18n.l(time, :full)).to eq(' 1 января 1970 00:00')
244
-
245
- expect(i18n.l(Date.new(0))).to eq('01.01.0000')
246
- end
247
-
248
- it 'returns marshalizable values' do
249
- i18n = R18n::I18n.new('en', DIR, off_filters: :untranslated,
250
- on_filters: :untranslated_html)
251
- demarsh = Marshal.load(Marshal.dump(i18n.t.one))
252
-
253
- expect(i18n.t.one).to eq(demarsh)
254
- expect(i18n.t.one.path).to eq(demarsh.path)
255
- expect(i18n.t.one.locale).to eq(demarsh.locale)
256
-
257
- demarsh = Marshal.load(Marshal.dump(i18n.t.no_translation))
258
- expect(i18n.t.no_translation).to eq(demarsh)
259
- end
260
- end
data/spec/locale_spec.rb DELETED
@@ -1,216 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bigdecimal'
4
-
5
- describe R18n::Locale do
6
- before :all do
7
- @ru = R18n.locale('ru')
8
- @en = R18n.locale('en')
9
- end
10
-
11
- it 'returns all available locales' do
12
- expect(R18n::Locale.available.class).to eq(Array)
13
- expect(R18n::Locale.available).not_to be_empty
14
- end
15
-
16
- it 'checks is locale exists' do
17
- expect(R18n::Locale.exists?('ru')).to be true
18
- expect(R18n::Locale.exists?('nolocale')).to be false
19
- end
20
-
21
- it 'sets locale properties' do
22
- locale_class = Class.new(R18n::Locale) do
23
- set one: 1
24
- set two: 2
25
- end
26
- locale = locale_class.new
27
- expect(locale.one).to eq(1)
28
- expect(locale.two).to eq(2)
29
- end
30
-
31
- it 'loads locale' do
32
- expect(@ru.class).to eq(R18n::Locales::Ru)
33
- expect(@ru.code).to eq('ru')
34
- expect(@ru.title).to eq('Русский')
35
- end
36
-
37
- it 'loads locale by Symbol' do
38
- expect(R18n.locale(:ru)).to eq(R18n.locale('ru'))
39
- end
40
-
41
- it 'equals to another locale with same code' do
42
- expect(@en).not_to eq(@ru)
43
- expect(@en).to eq(R18n.locale('en'))
44
- end
45
-
46
- it 'prints human readable representation' do
47
- expect(@ru.inspect).to eq('Locale ru (Русский)')
48
- end
49
-
50
- it 'returns pluralization type by elements count' do
51
- expect(@en.pluralize(0)).to eq(0)
52
- expect(@en.pluralize(1)).to eq(1)
53
- expect(@en.pluralize(5)).to eq('n')
54
- end
55
-
56
- it "uses UnsupportedLocale if locale file isn't exists" do
57
- expect(@en).to be_supported
58
-
59
- unsupported = R18n.locale('nolocale-DL')
60
- expect(unsupported).not_to be_supported
61
- expect(unsupported).to be_kind_of(R18n::UnsupportedLocale)
62
-
63
- expect(unsupported.code.downcase).to eq('nolocale-dl')
64
- expect(unsupported.title.downcase).to eq('nolocale-dl')
65
- expect(unsupported.ltr?).to be true
66
-
67
- expect(unsupported.pluralize(5)).to eq('n')
68
- expect(unsupported.inspect.downcase).to eq('unsupported locale nolocale-dl')
69
- end
70
-
71
- it 'formats number in local traditions' do
72
- expect(@en.localize(-123_456_789)).to eq('−123,456,789')
73
- end
74
-
75
- it 'formats float in local traditions' do
76
- expect(@en.localize(-12_345.67)).to eq('−12,345.67')
77
- expect(@en.localize(BigDecimal.new('-12345.67'))).to eq('−12,345.67')
78
- end
79
-
80
- it 'translates month, week days and am/pm names in strftime' do
81
- R18n::I18n.new('ru')
82
- time = Time.at(0).utc
83
-
84
- expect(@ru.localize(time, '%a %A')).to eq('Чтв Четверг')
85
- expect(@ru.localize(time, '%b %B')).to eq('янв января')
86
- expect(@ru.localize(time, '%H:%M%p')).to eq('00:00 утра')
87
- end
88
-
89
- it 'generates locale code by locale class name' do
90
- expect(R18n.locale('ru').code).to eq('ru')
91
- expect(R18n.locale('zh-CN').code).to eq('zh-CN')
92
- end
93
-
94
- it 'localizes date for human' do
95
- i18n = R18n::I18n.new('en')
96
-
97
- expect(@en.localize(Date.today + 2, :human, i18n)).to eq('after 2 days')
98
- expect(@en.localize(Date.today + 1, :human, i18n)).to eq('tomorrow')
99
- expect(@en.localize(Date.today, :human, i18n)).to eq('today')
100
- expect(@en.localize(Date.today - 1, :human, i18n)).to eq('yesterday')
101
- expect(@en.localize(Date.today - 3, :human, i18n)).to eq('3 days ago')
102
-
103
- y2k = Date.parse('2000-05-08')
104
- expect(@en.localize(y2k, :human, i18n, y2k + 8)).to eq('8th of May')
105
- expect(@en.localize(y2k, :human, i18n, y2k - 365)).to eq('8th of May, 2000')
106
- end
107
-
108
- it 'localizes times for human' do
109
- minute = 60
110
- hour = 60 * minute
111
- day = 24 * hour
112
- zero = Time.at(0).utc
113
- p = [:human, R18n::I18n.new('en'), zero]
114
-
115
- expect(@en.localize(zero + 7 * day, *p)).to eq('8th of January 00:00')
116
- expect(@en.localize(zero + 50 * hour, *p)).to eq('after 2 days 02:00')
117
- expect(@en.localize(zero + 25 * hour, *p)).to eq('tomorrow 01:00')
118
- expect(@en.localize(zero + 70 * minute, *p)).to eq('after 1 hour')
119
- expect(@en.localize(zero + hour, *p)).to eq('after 1 hour')
120
- expect(@en.localize(zero + 38 * minute, *p)).to eq('after 38 minutes')
121
- expect(@en.localize(zero + 5, *p)).to eq('now')
122
- expect(@en.localize(zero - 15, *p)).to eq('now')
123
- expect(@en.localize(zero - minute, *p)).to eq('1 minute ago')
124
- expect(@en.localize(zero - hour + 59, *p)).to eq('59 minutes ago')
125
- expect(@en.localize(zero - 2 * hour, *p)).to eq('2 hours ago')
126
- expect(@en.localize(zero - 13 * hour, *p)).to eq('yesterday 11:00')
127
- expect(@en.localize(zero - 50 * hour, *p)).to eq('3 days ago 22:00')
128
-
129
- expect(@en.localize(zero - 9 * day, *p)).to eq(
130
- '23rd of December, 1969 00:00'
131
- )
132
- expect(@en.localize(zero - 365 * day, *p)).to eq(
133
- '1st of January, 1969 00:00'
134
- )
135
- end
136
-
137
- it 'localizes date-times for human' do
138
- day = 1.0
139
- hour = day / 24
140
- minute = hour / 60
141
- second = minute / 60
142
- zero = DateTime.new(1970)
143
- p = [:human, R18n::I18n.new('en'), zero]
144
-
145
- expect(@en.localize(zero + 7 * day, *p)).to eq('8th of January 00:00')
146
- expect(@en.localize(zero + 50 * hour, *p)).to eq('after 2 days 02:00')
147
- expect(@en.localize(zero + 25 * hour, *p)).to eq('tomorrow 01:00')
148
- expect(@en.localize(zero + 70 * minute, *p)).to eq('after 1 hour')
149
- expect(@en.localize(zero + hour, *p)).to eq('after 1 hour')
150
- expect(@en.localize(zero + 38 * minute, *p)).to eq('after 38 minutes')
151
- expect(@en.localize(zero + 5 * second, *p)).to eq('now')
152
- expect(@en.localize(zero - 15 * second, *p)).to eq('now')
153
- expect(@en.localize(zero - minute, *p)).to eq('1 minute ago')
154
- expect(@en.localize(zero - hour + 59 * second, *p)).to eq('59 minutes ago')
155
- expect(@en.localize(zero - 2 * hour, *p)).to eq('2 hours ago')
156
- expect(@en.localize(zero - 13 * hour, *p)).to eq('yesterday 11:00')
157
- expect(@en.localize(zero - 50 * hour, *p)).to eq('3 days ago 22:00')
158
-
159
- expect(@en.localize(zero - 9 * day, *p)).to eq(
160
- '23rd of December, 1969 00:00'
161
- )
162
- expect(@en.localize(zero - 365 * day, *p)).to eq(
163
- '1st of January, 1969 00:00'
164
- )
165
- end
166
-
167
- it 'uses standard formatter by default' do
168
- expect(@ru.localize(Time.at(0).utc)).to eq('01.01.1970 00:00')
169
- end
170
-
171
- it "doesn't localize time without i18n object" do
172
- expect(@ru.localize(Time.at(0))).not_to eq(Time.at(0).to_s)
173
- expect(@ru.localize(Time.at(0), :full)).not_to eq(Time.at(0).to_s)
174
-
175
- expect(@ru.localize(Time.at(0), :human)).to eq(Time.at(0).to_s)
176
- end
177
-
178
- it 'localizes date in custom formatter if exists' do
179
- allow(@en).to receive(:format_date_my_own_way) do |date|
180
- date == Date.today ? 'DOOMSDAY!' : 'Just another day'
181
- end
182
-
183
- expect(@en.localize(Date.today, :my_own_way)).to eq('DOOMSDAY!')
184
- expect(@en.localize(Date.today + 1, :my_own_way)).to eq('Just another day')
185
- expect(@en.localize(Date.today - 1, :my_own_way)).to eq('Just another day')
186
- end
187
-
188
- it 'raises error on unknown formatter' do
189
- expect do
190
- @ru.localize(Time.at(0).utc, R18n::I18n.new('ru'), :unknown)
191
- end.to raise_error(ArgumentError, /formatter/)
192
- end
193
-
194
- it 'deletes slashed from locale for security reasons' do
195
- locale = R18n.locale('../spec/translations/general/en')
196
- expect(locale).to be_kind_of(R18n::UnsupportedLocale)
197
- end
198
-
199
- it 'ignores code case in locales' do
200
- upcase = R18n.locale('RU')
201
- downcase = R18n.locale('ru')
202
- expect(upcase).to eq(downcase)
203
- expect(upcase.code).to eq('ru')
204
- expect(downcase.code).to eq('ru')
205
-
206
- upcase = R18n.locale('nolocale')
207
- downcase = R18n.locale('nolocale')
208
- expect(upcase).to eq(downcase)
209
- expect(upcase.code).to eq('nolocale')
210
- expect(downcase.code).to eq('nolocale')
211
- end
212
-
213
- it 'loads locale with underscore' do
214
- expect(R18n.locale('nolocale-DL').code).to eq('nolocale-dl')
215
- end
216
- end