r18n-core 2.2.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +5 -5
  2. data/.rspec +1 -1
  3. data/ChangeLog.md +6 -1
  4. data/README.md +1 -20
  5. data/Rakefile +5 -3
  6. data/lib/r18n-core.rb +55 -55
  7. data/lib/r18n-core/filter_list.rb +34 -36
  8. data/lib/r18n-core/filters.rb +68 -51
  9. data/lib/r18n-core/helpers.rb +17 -17
  10. data/lib/r18n-core/i18n.rb +46 -39
  11. data/lib/r18n-core/locale.rb +79 -70
  12. data/lib/r18n-core/translated.rb +65 -66
  13. data/lib/r18n-core/translated_string.rb +24 -24
  14. data/lib/r18n-core/translation.rb +31 -30
  15. data/lib/r18n-core/unsupported_locale.rb +22 -24
  16. data/lib/r18n-core/untranslated.rb +35 -33
  17. data/lib/r18n-core/utils.rb +26 -25
  18. data/lib/r18n-core/version.rb +4 -1
  19. data/lib/r18n-core/yaml_loader.rb +26 -25
  20. data/lib/r18n-core/yaml_methods.rb +25 -28
  21. data/locales/af.rb +15 -8
  22. data/locales/az.rb +19 -12
  23. data/locales/bg.rb +16 -9
  24. data/locales/ca.rb +16 -9
  25. data/locales/cs.rb +27 -20
  26. data/locales/da.rb +15 -8
  27. data/locales/de.rb +16 -9
  28. data/locales/en-au.rb +10 -5
  29. data/locales/en-gb.rb +12 -5
  30. data/locales/en-us.rb +12 -5
  31. data/locales/en.rb +29 -22
  32. data/locales/eo.rb +14 -7
  33. data/locales/es-us.rb +12 -5
  34. data/locales/es.rb +14 -7
  35. data/locales/fa.rb +48 -32
  36. data/locales/fi.rb +19 -12
  37. data/locales/fr.rb +22 -15
  38. data/locales/gl.rb +15 -8
  39. data/locales/hr.rb +24 -17
  40. data/locales/hu.rb +28 -21
  41. data/locales/id.rb +14 -7
  42. data/locales/it.rb +21 -14
  43. data/locales/ja.rb +15 -8
  44. data/locales/kk.rb +17 -10
  45. data/locales/ko.rb +15 -9
  46. data/locales/lv.rb +24 -17
  47. data/locales/mn.rb +10 -3
  48. data/locales/nb.rb +15 -8
  49. data/locales/nl.rb +15 -8
  50. data/locales/no.rb +11 -16
  51. data/locales/pl.rb +26 -19
  52. data/locales/pt-br.rb +12 -5
  53. data/locales/pt.rb +17 -10
  54. data/locales/ru.rb +26 -19
  55. data/locales/sk.rb +27 -20
  56. data/locales/sr-latn.rb +27 -22
  57. data/locales/sv-se.rb +15 -8
  58. data/locales/th.rb +27 -20
  59. data/locales/tr.rb +16 -9
  60. data/locales/uk.rb +19 -12
  61. data/locales/vi.rb +14 -7
  62. data/locales/zh-cn.rb +12 -5
  63. data/locales/zh-tw.rb +15 -8
  64. data/locales/zh.rb +14 -7
  65. data/r18n-core.gemspec +5 -3
  66. data/spec/filters_spec.rb +71 -67
  67. data/spec/i18n_spec.rb +73 -51
  68. data/spec/locale_spec.rb +73 -68
  69. data/spec/locales/cs_spec.rb +2 -2
  70. data/spec/locales/en-us_spec.rb +9 -9
  71. data/spec/locales/en_spec.rb +2 -2
  72. data/spec/locales/fa_spec.rb +3 -3
  73. data/spec/locales/fr_spec.rb +2 -2
  74. data/spec/locales/hu_spec.rb +7 -7
  75. data/spec/locales/it_spec.rb +3 -3
  76. data/spec/locales/no_spec.rb +9 -0
  77. data/spec/locales/pl_spec.rb +2 -2
  78. data/spec/locales/ru_spec.rb +2 -2
  79. data/spec/locales/sk_spec.rb +2 -2
  80. data/spec/locales/th_spec.rb +2 -2
  81. data/spec/locales/vi_spec.rb +2 -2
  82. data/spec/r18n_spec.rb +44 -38
  83. data/spec/spec_helper.rb +13 -9
  84. data/spec/translated_spec.rb +48 -31
  85. data/spec/translation_spec.rb +29 -27
  86. data/spec/translations/general/en.yml +0 -2
  87. data/spec/yaml_loader_spec.rb +22 -18
  88. metadata +5 -3
@@ -1,7 +1,7 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ # frozen_string_literal: true
2
2
 
3
3
  describe R18n::Locales::Cs do
4
- it "uses Czech pluralization" do
4
+ it 'uses Czech pluralization' do
5
5
  cs = R18n.locale('cs')
6
6
  expect(cs.pluralize(0)).to eq(0)
7
7
  expect(cs.pluralize(1)).to eq(1)
@@ -1,13 +1,13 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ # frozen_string_literal: true
2
2
 
3
3
  describe R18n::Locales::EnUs do
4
- it "formats American English date" do
5
- enUS = R18n::I18n.new('en-US')
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')
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
12
  end
13
13
  end
@@ -1,7 +1,7 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ # frozen_string_literal: true
2
2
 
3
3
  describe R18n::Locales::En do
4
- it "formats English date" do
4
+ it 'formats English date' do
5
5
  en = R18n::I18n.new('en')
6
6
  expect(en.l(Date.parse('2009-05-01'), :full)).to eq('1st of May, 2009')
7
7
  expect(en.l(Date.parse('2009-05-02'), :full)).to eq('2nd of May, 2009')
@@ -1,9 +1,9 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ # frozen_string_literal: true
2
2
 
3
3
  describe R18n::Locales::Fa do
4
- it "formats Persian numerals" do
4
+ it 'formats Persian numerals' do
5
5
  fa = R18n::I18n.new('fa')
6
- expect(fa.l(1234567890)).to eq('۱٬۲۳۴٬۵۶۷٬۸۹۰')
6
+ expect(fa.l(1_234_567_890)).to eq('۱٬۲۳۴٬۵۶۷٬۸۹۰')
7
7
  expect(fa.l(10.123)).to eq('۱۰٫۱۲۳')
8
8
  expect(fa.l(Date.parse('2009-05-01'))).to eq('۲۰۰۹/۰۵/۰۱')
9
9
  end
@@ -1,7 +1,7 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ # frozen_string_literal: true
2
2
 
3
3
  describe R18n::Locales::Fr do
4
- it "formats French date" do
4
+ it 'formats French date' do
5
5
  fr = R18n::I18n.new('fr')
6
6
  expect(fr.l(Date.parse('2009-07-01'), :full)).to eq('1er juillet 2009')
7
7
  expect(fr.l(Date.parse('2009-07-02'), :full)).to eq(' 2 juillet 2009')
@@ -1,15 +1,15 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ # frozen_string_literal: true
2
2
 
3
3
  describe R18n::Locales::Hu do
4
- it "uses Hungarian digits groups" do
4
+ it 'uses Hungarian digits groups' do
5
5
  hu = R18n::I18n.new('hu')
6
- expect(hu.l(1000)).to eq('1000')
7
- expect(hu.l(10000)).to eq('10 000')
8
- expect(hu.l(-10000)).to eq('−10 000')
9
- expect(hu.l(100000)).to eq('100 000')
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
10
  end
11
11
 
12
- it "uses Hungarian time format" do
12
+ it 'uses Hungarian time format' do
13
13
  hu = R18n::I18n.new('hu')
14
14
  expect(hu.l(Time.at(0).utc)).to eq('1970. 01. 01., 00:00')
15
15
  expect(hu.l(Time.at(0).utc, :full)).to eq('1970. január 1., 00:00')
@@ -1,9 +1,9 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ # frozen_string_literal: true
2
2
 
3
3
  describe R18n::Locales::It do
4
- it "formats Italian date" do
4
+ it 'formats Italian date' do
5
5
  italian = R18n::I18n.new('it')
6
- expect(italian.l(Date.parse('2009-07-01'), :full)).to eq("1º luglio 2009")
6
+ expect(italian.l(Date.parse('2009-07-01'), :full)).to eq('1º luglio 2009')
7
7
  expect(italian.l(Date.parse('2009-07-02'), :full)).to eq(' 2 luglio 2009')
8
8
  expect(italian.l(Date.parse('2009-07-12'), :full)).to eq('12 luglio 2009')
9
9
  end
@@ -0,0 +1,9 @@
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
@@ -1,7 +1,7 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ # frozen_string_literal: true
2
2
 
3
3
  describe R18n::Locales::Pl do
4
- it "uses Polish pluralization" do
4
+ it 'uses Polish pluralization' do
5
5
  pl = R18n.locale('pl')
6
6
  expect(pl.pluralize(0)).to eq(0)
7
7
  expect(pl.pluralize(1)).to eq(1)
@@ -1,7 +1,7 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ # frozen_string_literal: true
2
2
 
3
3
  describe R18n::Locales::Ru do
4
- it "uses Russian pluralization" do
4
+ it 'uses Russian pluralization' do
5
5
  ru = R18n.locale('ru')
6
6
  expect(ru.pluralize(0)).to eq(0)
7
7
 
@@ -1,7 +1,7 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ # frozen_string_literal: true
2
2
 
3
3
  describe R18n::Locales::Sk do
4
- it "uses Slovak pluralization" do
4
+ it 'uses Slovak pluralization' do
5
5
  sk = R18n.locale('Sk')
6
6
  expect(sk.pluralize(0)).to eq(0)
7
7
  expect(sk.pluralize(1)).to eq(1)
@@ -1,7 +1,7 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ # frozen_string_literal: true
2
2
 
3
3
  describe R18n::Locales::Th do
4
- it "uses Thai calendar" do
4
+ it 'uses Thai calendar' do
5
5
  th = R18n::I18n.new('th')
6
6
  expect(th.l(Time.at(0).utc, '%Y %y')).to eq('2513 13')
7
7
  expect(th.l(Time.at(0).utc)).to eq('01/01/2513 00:00')
@@ -1,7 +1,7 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ # frozen_string_literal: true
2
2
 
3
3
  describe R18n::Locales::Vi do
4
- it "change times position" do
4
+ it 'change times position' do
5
5
  th = R18n::I18n.new('vi')
6
6
  expect(th.l(Time.at(0).utc)).to eq('00:00, 01/01/1970')
7
7
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path('../spec_helper', __FILE__)
1
+ # frozen_string_literal: true
2
2
 
3
3
  describe R18n do
4
4
  include R18n::Helpers
@@ -9,7 +9,7 @@ describe R18n do
9
9
  R18n.reset!
10
10
  end
11
11
 
12
- it "stores I18n" do
12
+ it 'stores I18n' do
13
13
  i18n = R18n::I18n.new('en')
14
14
  R18n.set(i18n)
15
15
  expect(R18n.get).to eq(i18n)
@@ -18,7 +18,7 @@ describe R18n do
18
18
  expect(R18n.get).to be_nil
19
19
  end
20
20
 
21
- it "sets setter to I18n" do
21
+ it 'sets setter to I18n' do
22
22
  i18n = R18n::I18n.new('en')
23
23
  R18n.set(i18n)
24
24
 
@@ -28,25 +28,25 @@ describe R18n do
28
28
  expect(R18n.get).to eq(i18n)
29
29
  end
30
30
 
31
- it "creates I18n object by shortcut" do
31
+ it 'creates I18n object by shortcut' do
32
32
  R18n.set('en', DIR)
33
33
  expect(R18n.get).to be_kind_of(R18n::I18n)
34
34
  expect(R18n.get.locales).to eq([R18n.locale('en')])
35
35
  expect(R18n.get.translation_places).to eq([R18n::Loader::YAML.new(DIR)])
36
36
  end
37
37
 
38
- it "allows to return I18n arguments in setter block" do
38
+ it 'allows to return I18n arguments in setter block' do
39
39
  R18n.set { 'en' }
40
40
  expect(R18n.get.locales).to eq([R18n.locale('en')])
41
41
  end
42
42
 
43
- it "clears cache" do
43
+ it 'clears cache' do
44
44
  R18n.cache[:a] = 1
45
45
  R18n.clear_cache!
46
46
  expect(R18n.cache).to be_empty
47
47
  end
48
48
 
49
- it "resets I18n objects and cache" do
49
+ it 'resets I18n objects and cache' do
50
50
  R18n.cache[:a] = 1
51
51
  R18n.set('en')
52
52
  R18n.thread_set('en')
@@ -56,7 +56,7 @@ describe R18n do
56
56
  expect(R18n.cache).to be_empty
57
57
  end
58
58
 
59
- it "stores I18n via thread_set" do
59
+ it 'stores I18n via thread_set' do
60
60
  i18n = R18n::I18n.new('en')
61
61
  R18n.thread_set(i18n)
62
62
  expect(R18n.get).to eq(i18n)
@@ -66,69 +66,71 @@ describe R18n do
66
66
  expect(R18n.get).to eq(i18n)
67
67
  end
68
68
 
69
- it "allows to temporary change locale" do
69
+ it 'allows to temporary change locale' do
70
70
  R18n.default_places = DIR
71
71
  expect(R18n.change('en').locales).to eq([R18n.locale('en')])
72
72
  expect(R18n.change('en').translation_places.size).to eq(1)
73
73
  expect(R18n.change('en').translation_places.first.dir).to eq(DIR.to_s)
74
74
  end
75
75
 
76
- it "allows to temporary change current locales" do
76
+ it 'allows to temporary change current locales' do
77
77
  R18n.set('ru')
78
78
  expect(R18n.change('en').locales).to eq(
79
- [R18n.locale('en'), R18n.locale('ru')])
79
+ [R18n.locale('en'), R18n.locale('ru')]
80
+ )
80
81
  expect(R18n.change('en').translation_places).to eq(
81
- R18n.get.translation_places)
82
+ R18n.get.translation_places
83
+ )
82
84
  expect(R18n.get.locale.code).to eq('ru')
83
85
  end
84
86
 
85
- it "allows to get Locale to temporary change" do
87
+ it 'allows to get Locale to temporary change' do
86
88
  R18n.set('ru')
87
89
  expect(R18n.change(R18n.locale('en')).locale.code).to eq('en')
88
90
  end
89
91
 
90
- it "has shortcut to load locale" do
92
+ it 'has shortcut to load locale' do
91
93
  expect(R18n.locale('ru')).to eq(R18n::Locale.load('ru'))
92
94
  end
93
95
 
94
- it "stores default loader class" do
96
+ it 'stores default loader class' do
95
97
  expect(R18n.default_loader).to eq(R18n::Loader::YAML)
96
98
  R18n.default_loader = Class
97
99
  expect(R18n.default_loader).to be_kind_of(Class)
98
100
  end
99
101
 
100
- it "stores cache" do
102
+ it 'stores cache' do
101
103
  expect(R18n.cache).to be_kind_of(Hash)
102
104
 
103
105
  R18n.cache = { 1 => 2 }
104
- expect(R18n.cache).to eq({ 1 => 2 })
106
+ expect(R18n.cache).to eq(1 => 2)
105
107
 
106
108
  R18n.clear_cache!
107
- expect(R18n.cache).to eq({ })
109
+ expect(R18n.cache).to eq({})
108
110
  end
109
111
 
110
- it "maps hash" do
111
- hash = R18n::Utils.hash_map({ 'a' => 1, 'b' => 2 }) { |k, v|
112
+ it 'maps hash' do
113
+ hash = R18n::Utils.hash_map('a' => 1, 'b' => 2) do |k, v|
112
114
  [k + 'a', v + 1]
113
- }
114
- expect(hash).to eq({ 'aa' => 2, 'ba' => 3 })
115
+ end
116
+ expect(hash).to eq('aa' => 2, 'ba' => 3)
115
117
  end
116
118
 
117
- it "merges hash recursively" do
118
- a = { a: 1, b: { ba: 1, bb: 1}, c: 1 }
119
- b = { b: { bb: 2, bc: 2}, c: 2 }
119
+ it 'merges hash recursively' do
120
+ a = { a: 1, b: { ba: 1, bb: 1 }, c: 1 }
121
+ b = { b: { bb: 2, bc: 2 }, c: 2 }
120
122
 
121
123
  R18n::Utils.deep_merge!(a, b)
122
- expect(a).to eq({ a: 1, b: { ba: 1, bb: 2, bc: 2 }, c: 2 })
124
+ expect(a).to eq(a: 1, b: { ba: 1, bb: 2, bc: 2 }, c: 2)
123
125
  end
124
126
 
125
- it "has l and t methods" do
127
+ it 'has l and t methods' do
126
128
  R18n.set('en')
127
129
  expect(t.yes).to eq('Yes')
128
130
  expect(l(Time.at(0).utc)).to eq('1970-01-01 00:00')
129
131
  end
130
132
 
131
- it "has helpers mixin" do
133
+ it 'has helpers mixin' do
132
134
  obj = R18n::I18n.new('en')
133
135
  R18n.set(obj)
134
136
 
@@ -138,27 +140,31 @@ describe R18n do
138
140
  expect(l(Time.at(0).utc)).to eq('1970-01-01 00:00')
139
141
  end
140
142
 
141
- it "returns available translations" do
142
- expect(R18n.available_locales(DIR)).to match_array([R18n.locale('nolocale'),
143
- R18n.locale('ru'),
144
- R18n.locale('en')])
143
+ it 'returns available translations' do
144
+ expect(R18n.available_locales(DIR)).to match_array([
145
+ R18n.locale('nolocale'),
146
+ R18n.locale('ru'),
147
+ R18n.locale('en')
148
+ ])
145
149
  end
146
150
 
147
- it "uses default places" do
151
+ it 'uses default places' do
148
152
  R18n.default_places = DIR
149
153
  R18n.set('en')
150
154
  expect(t.one).to eq('One')
151
- expect(R18n.available_locales).to match_array([R18n.locale('ru'),
152
- R18n.locale('en'),
153
- R18n.locale('nolocale')])
155
+ expect(R18n.available_locales).to match_array([
156
+ R18n.locale('ru'),
157
+ R18n.locale('en'),
158
+ R18n.locale('nolocale')
159
+ ])
154
160
  end
155
161
 
156
- it "sets default places by block" do
162
+ it 'sets default places by block' do
157
163
  R18n.default_places { DIR }
158
164
  expect(R18n.default_places).to eq(DIR)
159
165
  end
160
166
 
161
- it "allows to ignore default places" do
167
+ it 'allows to ignore default places' do
162
168
  R18n.default_places = DIR
163
169
  i18n = R18n::I18n.new('en', nil)
164
170
  expect(i18n.one).not_to be_translated
@@ -1,14 +1,18 @@
1
- require 'pp'
1
+ # frozen_string_literal: true
2
2
 
3
- dir = Pathname(__FILE__).dirname
3
+ require 'pp'
4
4
 
5
- require dir.join('../lib/r18n-core').to_s
6
- Dir.glob(dir.join('../locales/*.rb').to_s) { |locale| require locale }
5
+ require_relative '../lib/r18n-core'
6
+ Dir.glob(File.join(__dir__, '..', 'locales', '*.rb')) do |locale_file|
7
+ require locale_file
8
+ end
7
9
 
8
- TRANSLATIONS = dir + 'translations' unless defined? TRANSLATIONS
9
- DIR = TRANSLATIONS + 'general' unless defined? DIR
10
- TWO = TRANSLATIONS + 'two' unless defined? TWO
11
- EXT = R18n::Loader::YAML.new(TRANSLATIONS + 'extension') unless defined? EXT
10
+ TRANSLATIONS = File.join(__dir__, 'translations') unless defined? TRANSLATIONS
11
+ DIR = File.join(TRANSLATIONS, 'general') unless defined? DIR
12
+ TWO = File.join(TRANSLATIONS, 'two') unless defined? TWO
13
+ unless defined? EXT
14
+ EXT = R18n::Loader::YAML.new(File.join(TRANSLATIONS, 'extension'))
15
+ end
12
16
 
13
17
  RSpec.configure do |config|
14
18
  config.before { R18n.clear_cache! }
@@ -26,7 +30,7 @@ class CounterLoader
26
30
  @loaded = 0
27
31
  end
28
32
 
29
- def load(locale)
33
+ def load(_locale)
30
34
  @loaded += 1
31
35
  {}
32
36
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path('../spec_helper', __FILE__)
1
+ # frozen_string_literal: true
2
2
 
3
3
  describe R18n::Translated do
4
4
  before do
@@ -7,26 +7,29 @@ describe R18n::Translated do
7
7
  attr_accessor :name_ru, :name_en
8
8
 
9
9
  def name_ru?; end
10
+
10
11
  def name_ru!; end
11
12
  end
12
13
  R18n.set('en')
13
14
  end
14
15
 
15
- it "saves methods map" do
16
+ it 'saves methods map' do
16
17
  @user_class.translation :name, methods: { ru: :name_ru }
17
- expect(@user_class.unlocalized_getters(:name)).to eq({ 'ru' => 'name_ru' })
18
- expect(@user_class.unlocalized_setters(:name)).to eq({ 'ru' => 'name_ru=' })
18
+ expect(@user_class.unlocalized_getters(:name)).to eq('ru' => 'name_ru')
19
+ expect(@user_class.unlocalized_setters(:name)).to eq('ru' => 'name_ru=')
19
20
  end
20
21
 
21
- it "autodetects methods map" do
22
+ it 'autodetects methods map' do
22
23
  @user_class.translation :name
23
- expect(@user_class.unlocalized_getters(:name)).to eq({
24
- 'en' => 'name_en', 'ru' => 'name_ru' })
25
- expect(@user_class.unlocalized_setters(:name)).to eq({
26
- 'en' => 'name_en=', 'ru' => 'name_ru=' })
24
+ expect(@user_class.unlocalized_getters(:name)).to eq(
25
+ 'en' => 'name_en', 'ru' => 'name_ru'
26
+ )
27
+ expect(@user_class.unlocalized_setters(:name)).to eq(
28
+ 'en' => 'name_en=', 'ru' => 'name_ru='
29
+ )
27
30
  end
28
31
 
29
- it "translates methods" do
32
+ it 'translates methods' do
30
33
  @user_class.translation :name
31
34
  user = @user_class.new
32
35
 
@@ -39,10 +42,14 @@ describe R18n::Translated do
39
42
  expect(user.name).to eq('Джон')
40
43
  end
41
44
 
42
- it "returns TranslatedString" do
43
- class ::SomeTranslatedClass
45
+ it 'returns TranslatedString' do
46
+ class SomeTranslatedClass
44
47
  include R18n::Translated
45
- def name_en; 'John'; end
48
+
49
+ def name_en
50
+ 'John'
51
+ end
52
+
46
53
  translation :name
47
54
  end
48
55
  obj = ::SomeTranslatedClass.new
@@ -52,16 +59,16 @@ describe R18n::Translated do
52
59
  expect(obj.name.path).to eq('SomeTranslatedClass#name')
53
60
  end
54
61
 
55
- it "searchs translation by locales priority" do
62
+ it 'searchs translation by locales priority' do
56
63
  @user_class.translation :name
57
64
  user = @user_class.new
58
65
 
59
- R18n.set(['nolocale', 'ru', 'en'])
66
+ R18n.set(%w[nolocale ru en])
60
67
  user.name_ru = 'Иван'
61
68
  expect(user.name.locale).to eq(R18n.locale('ru'))
62
69
  end
63
70
 
64
- it "uses default locale" do
71
+ it 'uses default locale' do
65
72
  @user_class.translation :name
66
73
  user = @user_class.new
67
74
 
@@ -70,9 +77,11 @@ describe R18n::Translated do
70
77
  expect(user.name.locale).to eq(R18n.locale('en'))
71
78
  end
72
79
 
73
- it "uses filters" do
74
- @user_class.class_eval do
75
- def age_en; {1 => '%1 year', 'n' => '%1 years'} end
80
+ it 'uses filters' do
81
+ @user_class.class_exec do
82
+ def age_en
83
+ { 1 => '%1 year', 'n' => '%1 years' }
84
+ end
76
85
  translation :age, type: 'pl', no_params: true
77
86
  end
78
87
  user = @user_class.new
@@ -80,10 +89,16 @@ describe R18n::Translated do
80
89
  expect(user.age(20)).to eq('20 years')
81
90
  end
82
91
 
83
- it "sends params to method if user want it" do
84
- @user_class.class_eval do
85
- def no_params_en(*params) params.join(' '); end
86
- def params_en(*params) params.join(' '); end
92
+ it 'sends params to method if user want it' do
93
+ @user_class.class_exec do
94
+ def no_params_en(*params)
95
+ params.join(' ')
96
+ end
97
+
98
+ def params_en(*params)
99
+ params.join(' ')
100
+ end
101
+
87
102
  translations [:no_params, { no_params: true }], :params
88
103
  end
89
104
  user = @user_class.new
@@ -92,11 +107,13 @@ describe R18n::Translated do
92
107
  expect(user.params(1, 2)).to eq('1 2')
93
108
  end
94
109
 
95
- it "translates virtual methods" do
110
+ it 'translates virtual methods' do
96
111
  @virtual_class = Class.new do
97
112
  include R18n::Translated
113
+
98
114
  translation :no_method, methods: { en: :no_method_en }
99
- def method_missing(name, *params)
115
+
116
+ def method_missing(name, *_params)
100
117
  name.to_s
101
118
  end
102
119
  end
@@ -105,8 +122,8 @@ describe R18n::Translated do
105
122
  expect(virtual.no_method).to eq('no_method_en')
106
123
  end
107
124
 
108
- it "returns original type of result" do
109
- @user_class.class_eval do
125
+ it 'returns original type of result' do
126
+ @user_class.class_exec do
110
127
  translation :name
111
128
  def name_en
112
129
  :ivan
@@ -117,8 +134,8 @@ describe R18n::Translated do
117
134
  expect(user.name).to eq(:ivan)
118
135
  end
119
136
 
120
- it "returns nil" do
121
- @user_class.class_eval do
137
+ it 'returns nil' do
138
+ @user_class.class_exec do
122
139
  translation :name
123
140
  def name_en
124
141
  nil
@@ -129,8 +146,8 @@ describe R18n::Translated do
129
146
  expect(user.name).to be_nil
130
147
  end
131
148
 
132
- it "allows to change I18n object" do
133
- @user_class.class_eval do
149
+ it 'allows to change I18n object' do
150
+ @user_class.class_exec do
134
151
  translation :name
135
152
  attr_accessor :r18n
136
153
  end