r18n-core 4.0.0 → 5.0.1

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 (70) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog.md +398 -0
  3. data/README.md +23 -13
  4. data/lib/r18n-core.rb +10 -25
  5. data/lib/r18n-core/filter_list.rb +6 -3
  6. data/lib/r18n-core/filters.rb +21 -22
  7. data/lib/r18n-core/i18n.rb +9 -16
  8. data/lib/r18n-core/locale.rb +20 -21
  9. data/lib/r18n-core/locales/cy.rb +1 -1
  10. data/lib/r18n-core/locales/en-au.rb +1 -1
  11. data/lib/r18n-core/locales/en-gb.rb +1 -1
  12. data/lib/r18n-core/locales/en-us.rb +1 -1
  13. data/lib/r18n-core/locales/en.rb +2 -2
  14. data/lib/r18n-core/locales/es-cl.rb +1 -1
  15. data/lib/r18n-core/locales/es-us.rb +1 -1
  16. data/lib/r18n-core/locales/es.rb +2 -0
  17. data/lib/r18n-core/locales/fi.rb +2 -2
  18. data/lib/r18n-core/locales/fr.rb +3 -3
  19. data/lib/r18n-core/locales/it.rb +3 -3
  20. data/lib/r18n-core/locales/pt.rb +2 -0
  21. data/lib/r18n-core/locales/zh-cn.rb +1 -1
  22. data/lib/r18n-core/locales/zh-tw.rb +1 -1
  23. data/lib/r18n-core/locales/zh.rb +2 -0
  24. data/lib/r18n-core/translated.rb +4 -4
  25. data/lib/r18n-core/translated_string.rb +1 -6
  26. data/lib/r18n-core/translation.rb +1 -1
  27. data/lib/r18n-core/unsupported_locale.rb +2 -0
  28. data/lib/r18n-core/utils.rb +1 -1
  29. data/lib/r18n-core/version.rb +1 -1
  30. metadata +198 -89
  31. data/.rspec +0 -1
  32. data/Rakefile +0 -13
  33. data/r18n-core.gemspec +0 -29
  34. data/spec/filters_spec.rb +0 -327
  35. data/spec/i18n_spec.rb +0 -274
  36. data/spec/locale_spec.rb +0 -251
  37. data/spec/locales/af_spec.rb +0 -9
  38. data/spec/locales/cs_spec.rb +0 -23
  39. data/spec/locales/en-us_spec.rb +0 -28
  40. data/spec/locales/en_spec.rb +0 -13
  41. data/spec/locales/es-us_spec.rb +0 -11
  42. data/spec/locales/fa_spec.rb +0 -10
  43. data/spec/locales/fi_spec.rb +0 -9
  44. data/spec/locales/fr_spec.rb +0 -9
  45. data/spec/locales/hu_spec.rb +0 -19
  46. data/spec/locales/id_spec.rb +0 -23
  47. data/spec/locales/it_spec.rb +0 -10
  48. data/spec/locales/no_spec.rb +0 -9
  49. data/spec/locales/pl_spec.rb +0 -23
  50. data/spec/locales/ru_spec.rb +0 -23
  51. data/spec/locales/sk_spec.rb +0 -23
  52. data/spec/locales/th_spec.rb +0 -9
  53. data/spec/locales/vi_spec.rb +0 -9
  54. data/spec/r18n_spec.rb +0 -192
  55. data/spec/spec_helper.rb +0 -38
  56. data/spec/translated_spec.rb +0 -225
  57. data/spec/translation_spec.rb +0 -189
  58. data/spec/translations/extension/deep/en.yml +0 -1
  59. data/spec/translations/extension/en.yml +0 -2
  60. data/spec/translations/extension/notransl.yml +0 -1
  61. data/spec/translations/general/en.yml +0 -52
  62. data/spec/translations/general/nolocale.yml +0 -6
  63. data/spec/translations/general/ru.yml +0 -7
  64. data/spec/translations/two/en.yml +0 -2
  65. data/spec/translations/two/fr.yml +0 -0
  66. data/spec/translations/with_regions/en-US.yml +0 -0
  67. data/spec/translations/yaml/en-GB.yml +0 -1
  68. data/spec/translations/yaml/en-us.yml +0 -1
  69. data/spec/translations/yaml/en.yaml +0 -1
  70. data/spec/yaml_loader_spec.rb +0 -63
data/spec/locale_spec.rb DELETED
@@ -1,251 +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 'checks is locale exists' do
12
- expect(R18n::Locale.exists?('ru')).to be true
13
- expect(R18n::Locale.exists?('nolocale')).to be false
14
- end
15
-
16
- it 'sets locale properties' do
17
- locale_class = Class.new(R18n::Locale) do
18
- def self.name
19
- 'Foo'
20
- end
21
-
22
- set one: 1
23
- set two: 2
24
- end
25
- locale = locale_class.new
26
- expect(locale.one).to eq(1)
27
- expect(locale.two).to eq(2)
28
- end
29
-
30
- it 'loads locale' do
31
- expect(@ru.class).to eq(R18n::Locales::Ru)
32
- expect(@ru.code).to eq('ru')
33
- expect(@ru.title).to eq('Русский')
34
- end
35
-
36
- it 'loads locale by Symbol' do
37
- expect(R18n.locale(:ru)).to eq(R18n.locale('ru'))
38
- end
39
-
40
- it 'equals to another locale with same code' do
41
- expect(@en).not_to eq(@ru)
42
- expect(@en).to eq(R18n.locale('en'))
43
- end
44
-
45
- it 'prints human readable representation' do
46
- expect(@ru.inspect).to eq('Locale ru (Русский)')
47
- end
48
-
49
- it 'returns pluralization type by elements count' do
50
- expect(@en.pluralize(0)).to eq(0)
51
- expect(@en.pluralize(1)).to eq(1)
52
- expect(@en.pluralize(5)).to eq('n')
53
- end
54
-
55
- it "uses UnsupportedLocale if locale file isn't exists" do
56
- expect(@en).to be_supported
57
-
58
- unsupported = R18n.locale('nolocale-DL')
59
- expect(unsupported).not_to be_supported
60
- expect(unsupported).to be_kind_of(R18n::UnsupportedLocale)
61
-
62
- expect(unsupported.code).to eq('nolocale-dl')
63
- expect(unsupported.title.downcase).to eq('nolocale-dl')
64
- expect(unsupported.ltr?).to be true
65
-
66
- expect(unsupported.pluralize(5)).to eq('n')
67
- expect(unsupported.inspect.downcase).to eq('unsupported locale nolocale-dl')
68
- end
69
-
70
- it 'formats number in local traditions' do
71
- expect(@en.localize(-123_456_789)).to eq('−123,456,789')
72
- end
73
-
74
- it 'formats float in local traditions' do
75
- expect(@en.localize(-12_345.67)).to eq('−12,345.67')
76
- expect(@en.localize(BigDecimal('-12345.67'))).to eq('−12,345.67')
77
- end
78
-
79
- it 'translates month, week days and am/pm names in strftime' do
80
- R18n::I18n.new('ru')
81
- time = Time.at(0).utc
82
-
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 утра')
86
- end
87
-
88
- it 'generates locale code by locale class name' do
89
- expect(R18n.locale('ru').code).to eq('ru')
90
- expect(R18n.locale('zh-CN').code).to eq('zh-CN')
91
- end
92
-
93
- it 'localizes date for human' do
94
- i18n = R18n::I18n.new('en')
95
-
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')
101
-
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')
105
- end
106
-
107
- it 'localizes times for human' do
108
- minute = 60
109
- hour = 60 * minute
110
- day = 24 * hour
111
- zero = Time.at(0).utc
112
- now = Time.now
113
- now_params = [:human, R18n::I18n.new('en')]
114
- zero_params = [*now_params, zero]
115
-
116
- expect(@en.localize(now + 70 * minute, *now_params)).to eq('after 1 hour')
117
- expect(@en.localize(now + hour + minute, *now_params)).to eq('after 1 hour')
118
- expect(@en.localize(now + 38 * minute, *now_params))
119
- .to eq('after 38 minutes')
120
- expect(@en.localize(now + 5, *now_params)).to eq('now')
121
- expect(@en.localize(now - 15, *now_params)).to eq('now')
122
- expect(@en.localize(now - minute, *now_params)).to eq('1 minute ago')
123
- expect(@en.localize(now - hour + 59, *now_params))
124
- .to eq('59 minutes ago')
125
- expect(@en.localize(now - 2 * hour, *now_params)).to eq('2 hours ago')
126
-
127
- expect(@en.localize(zero + 7 * day, *zero_params))
128
- .to eq('8th of January 00:00')
129
- expect(@en.localize(zero + 50 * hour, *zero_params))
130
- .to eq('after 2 days 02:00')
131
- expect(@en.localize(zero + 25 * hour, *zero_params))
132
- .to eq('tomorrow 01:00')
133
- expect(@en.localize(zero - 13 * hour, *zero_params))
134
- .to eq('yesterday 11:00')
135
- expect(@en.localize(zero - 50 * hour, *zero_params))
136
- .to eq('3 days ago 22:00')
137
-
138
- expect(@en.localize(zero - 9 * day, *zero_params))
139
- .to eq('23rd of December, 1969 00:00')
140
- expect(@en.localize(zero - 365 * day, *zero_params))
141
- .to eq('1st of January, 1969 00:00')
142
- end
143
-
144
- it 'localizes date-times for human' do
145
- day = 1.0
146
- hour = day / 24
147
- minute = hour / 60
148
- second = minute / 60
149
- zero = DateTime.new(1970)
150
- now = DateTime.now
151
- now_params = [:human, R18n::I18n.new('en')]
152
- zero_params = [*now_params, zero]
153
-
154
- expect(@en.localize(now + 70 * minute, *now_params)).to eq('after 1 hour')
155
- expect(@en.localize(now + hour + minute, *now_params)).to eq('after 1 hour')
156
- expect(@en.localize(now + 38 * minute, *now_params))
157
- .to eq('after 38 minutes')
158
- expect(@en.localize(now + 5 * second, *now_params)).to eq('now')
159
- expect(@en.localize(now - 15 * second, *now_params)).to eq('now')
160
- expect(@en.localize(now - minute, *now_params)).to eq('1 minute ago')
161
-
162
- expect(@en.localize(now - hour + 59 * second, *now_params))
163
- .to eq('59 minutes ago')
164
-
165
- expect(@en.localize(now - 2 * hour, *now_params)).to eq('2 hours ago')
166
-
167
- expect(@en.localize(zero + 7 * day, *zero_params))
168
- .to eq('8th of January 00:00')
169
- expect(@en.localize(zero + 50 * hour, *zero_params))
170
- .to eq('after 2 days 02:00')
171
- expect(@en.localize(zero + 25 * hour, *zero_params))
172
- .to eq('tomorrow 01:00')
173
- expect(@en.localize(zero - 13 * hour, *zero_params))
174
- .to eq('yesterday 11:00')
175
- expect(@en.localize(zero - 50 * hour, *zero_params))
176
- .to eq('3 days ago 22:00')
177
-
178
- expect(@en.localize(zero - 9 * day, *zero_params))
179
- .to eq('23rd of December, 1969 00:00')
180
- expect(@en.localize(zero - 365 * day, *zero_params))
181
- .to eq('1st of January, 1969 00:00')
182
- end
183
-
184
- it 'uses standard formatter by default' do
185
- expect(@ru.localize(Time.at(0).utc)).to eq('01.01.1970 00:00')
186
- end
187
-
188
- it "doesn't localize time without i18n object" do
189
- expect(@ru.localize(Time.at(0))).not_to eq(Time.at(0).to_s)
190
- expect(@ru.localize(Time.at(0), :full)).not_to eq(Time.at(0).to_s)
191
-
192
- expect(@ru.localize(Time.at(0), :human)).to eq(Time.at(0).to_s)
193
- end
194
-
195
- it 'localizes date in custom formatter if exists' do
196
- allow(@en).to receive(:format_date_my_own_way) do |date|
197
- date == Date.today ? 'DOOMSDAY!' : 'Just another day'
198
- end
199
-
200
- expect(@en.localize(Date.today, :my_own_way)).to eq('DOOMSDAY!')
201
- expect(@en.localize(Date.today + 1, :my_own_way)).to eq('Just another day')
202
- expect(@en.localize(Date.today - 1, :my_own_way)).to eq('Just another day')
203
- end
204
-
205
- it 'localizes custom classes if formatter exists' do
206
- stub_const(
207
- 'FooBar', Class.new do
208
- attr_reader :value
209
-
210
- def initialize(value)
211
- @value = value
212
- end
213
- end
214
- )
215
-
216
- foo_bar = FooBar.new 'something'
217
-
218
- allow(@en).to receive(:format_foo_bar_human, &:value)
219
-
220
- expect(@en.localize(foo_bar, :human)).to eq('something')
221
- end
222
-
223
- it 'raises error on unknown formatter' do
224
- expect do
225
- @ru.localize(Time.at(0).utc, R18n::I18n.new('ru'), :unknown)
226
- end.to raise_error(ArgumentError, /formatter/)
227
- end
228
-
229
- it 'deletes slashed from locale for security reasons' do
230
- locale = R18n.locale('../spec/translations/general/en')
231
- expect(locale).to be_kind_of(R18n::UnsupportedLocale)
232
- end
233
-
234
- it 'ignores code case in locales' do
235
- upcase = R18n.locale('RU')
236
- downcase = R18n.locale('ru')
237
- expect(upcase).to eq(downcase)
238
- expect(upcase.code).to eq('ru')
239
- expect(downcase.code).to eq('ru')
240
-
241
- upcase = R18n.locale('nolocale')
242
- downcase = R18n.locale('nolocale')
243
- expect(upcase).to eq(downcase)
244
- expect(upcase.code).to eq('nolocale')
245
- expect(downcase.code).to eq('nolocale')
246
- end
247
-
248
- it 'loads locale with underscore' do
249
- expect(R18n.locale('nolocale_DL').code).to eq('nolocale-dl')
250
- end
251
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe R18n::Locales::Af do
4
- it 'formats Afrikaans time' do
5
- af = R18n::I18n.new('af')
6
- expect(af.l(Time.utc(2009, 5, 1, 6, 7, 8), :standard, with_seconds: true))
7
- .to eq('01/05/2009, 06:07:08')
8
- end
9
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe R18n::Locales::Cs do
4
- it 'uses Czech pluralization' do
5
- cs = R18n.locale('cs')
6
- expect(cs.pluralize(0)).to eq(0)
7
- expect(cs.pluralize(1)).to eq(1)
8
-
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
-
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
- end
23
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe R18n::Locales::EnUS do
4
- it 'formats American English date' do
5
- en_us = R18n::I18n.new('en-US')
6
- expect(en_us.l(Date.parse('2009-05-01'), :full)).to eq('May 1st, 2009')
7
- expect(en_us.l(Date.parse('2009-05-02'), :full)).to eq('May 2nd, 2009')
8
- expect(en_us.l(Date.parse('2009-05-03'), :full)).to eq('May 3rd, 2009')
9
- expect(en_us.l(Date.parse('2009-05-04'), :full)).to eq('May 4th, 2009')
10
- expect(en_us.l(Date.parse('2009-05-11'), :full)).to eq('May 11th, 2009')
11
- expect(en_us.l(Date.parse('2009-05-21'), :full)).to eq('May 21st, 2009')
12
- end
13
-
14
- it 'formats American English time' do
15
- en_us = R18n::I18n.new('en-US')
16
- expect(
17
- en_us.l(Time.utc(2009, 5, 1, 6, 7, 8), :standard, with_seconds: true)
18
- )
19
- .to eq('05/01/2009 06:07:08 AM')
20
- end
21
-
22
- it 'takes locaize from `en` locale when loaded from dir with only regions' do
23
- en_us = R18n::I18n.new(
24
- 'en-US', File.join(__dir__, '..', 'translations', 'with_regions')
25
- )
26
- expect(en_us.l(Time.now - 61, :human)).to eq '1 minute ago'
27
- end
28
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe R18n::Locales::En do
4
- it 'formats English date' do
5
- en = R18n::I18n.new('en')
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
- end
13
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe R18n::Locales::EnUS do
4
- it 'formats American Spanish time' do
5
- es_us = R18n::I18n.new('es-US')
6
- expect(
7
- es_us.l(Time.utc(2009, 5, 1, 6, 7, 8), :standard, with_seconds: true)
8
- )
9
- .to eq('05/01/2009 06:07:08 AM')
10
- end
11
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe R18n::Locales::Fa do
4
- it 'formats Persian numerals' do
5
- fa = R18n::I18n.new('fa')
6
- expect(fa.l(1_234_567_890)).to eq('۱٬۲۳۴٬۵۶۷٬۸۹۰')
7
- expect(fa.l(10.123)).to eq('۱۰٫۱۲۳')
8
- expect(fa.l(Date.parse('2009-05-01'))).to eq('۲۰۰۹/۰۵/۰۱')
9
- end
10
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe R18n::Locales::Fi do
4
- it 'formats Finnish time' do
5
- fi = R18n::I18n.new('fi')
6
- expect(fi.l(Time.utc(2009, 5, 1, 6, 7, 8), :standard, with_seconds: true))
7
- .to eq('01.05.2009 06.07.08')
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe R18n::Locales::Fr do
4
- it 'formats French date' do
5
- fr = R18n::I18n.new('fr')
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
- end
9
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe R18n::Locales::Hu do
4
- it 'uses Hungarian digits groups' do
5
- hu = R18n::I18n.new('hu')
6
- expect(hu.l(1000)).to eq('1000')
7
- expect(hu.l(10_000)).to eq('10 000')
8
- expect(hu.l(-10_000)).to eq('−10 000')
9
- expect(hu.l(100_000)).to eq('100 000')
10
- end
11
-
12
- it 'uses Hungarian time format' do
13
- hu = R18n::I18n.new('hu')
14
- expect(hu.l(Time.at(0).utc)).to eq('1970. 01. 01., 00:00')
15
- expect(hu.l(Time.at(0).utc, :full)).to eq('1970. január 1., 00:00')
16
- expect(hu.l(Time.utc(2009, 5, 1, 6, 7, 8), :standard, with_seconds: true))
17
- .to eq('2009. 05. 01., 06:07:08')
18
- end
19
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe R18n::Locales::Id do
4
- it 'formats Indonesian date' do
5
- id = R18n::I18n.new('id')
6
-
7
- expect(id.l(Date.parse('2009-11-01'), :full)).to eq('1 November 2009')
8
- expect(id.l(Date.parse('2009-11-02'), :standard)).to eq('02/11/2009')
9
- expect(id.l(Date.parse('2009-11-21'), '%d/%b/%y')).to eq('21/Nov/09')
10
- end
11
-
12
- it 'formats Indonesian time' do
13
- id = R18n::I18n.new('id')
14
- time = id.l(Time.utc(2009, 5, 1, 6, 7, 8), :standard)
15
- expect(time).to eq('01/05/2009 pukul 06.07')
16
- end
17
-
18
- it 'formats Indonesian time with seconds' do
19
- id = R18n::I18n.new('id')
20
- time = id.l(Time.utc(2009, 5, 1, 6, 7, 8), :standard, with_seconds: true)
21
- expect(time).to eq('01/05/2009 pukul 06.07.08')
22
- end
23
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe R18n::Locales::It do
4
- it 'formats Italian date' do
5
- italian = R18n::I18n.new('it')
6
- expect(italian.l(Date.parse('2009-07-01'), :full)).to eq('1º luglio 2009')
7
- expect(italian.l(Date.parse('2009-07-02'), :full)).to eq('2 luglio 2009')
8
- expect(italian.l(Date.parse('2009-07-12'), :full)).to eq('12 luglio 2009')
9
- end
10
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe R18n::Locales::No do
4
- it 'deprecated' do
5
- expect { R18n::I18n.new('no') }.to output(
6
- /R18n::Locales::No.new is deprecated; use R18n::Locales::Nb.new instead./
7
- ).to_stderr
8
- end
9
- end