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/locales/hu_spec.rb
CHANGED
@@ -1,18 +1,17 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
require File.expand_path('../../spec_helper', __FILE__)
|
3
2
|
|
4
3
|
describe R18n::Locales::Hu do
|
5
4
|
it "uses Hungarian digits groups" do
|
6
5
|
hu = R18n::I18n.new('hu')
|
7
|
-
hu.l(1000).
|
8
|
-
hu.l(10000).
|
9
|
-
hu.l(-10000).
|
10
|
-
hu.l(100000).
|
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')
|
11
10
|
end
|
12
11
|
|
13
12
|
it "uses Hungarian time format" do
|
14
13
|
hu = R18n::I18n.new('hu')
|
15
|
-
hu.l(Time.at(0).utc).
|
16
|
-
hu.l(Time.at(0).utc, :full).
|
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')
|
17
16
|
end
|
18
17
|
end
|
data/spec/locales/it_spec.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
require File.expand_path('../../spec_helper', __FILE__)
|
3
2
|
|
4
3
|
describe R18n::Locales::It do
|
5
4
|
it "formats Italian date" do
|
6
5
|
italian = R18n::I18n.new('it')
|
7
|
-
italian.l(Date.parse('2009-07-01'), :full).
|
8
|
-
italian.l(Date.parse('2009-07-02'), :full).
|
9
|
-
italian.l(Date.parse('2009-07-12'), :full).
|
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')
|
10
9
|
end
|
11
10
|
end
|
data/spec/locales/pl_spec.rb
CHANGED
@@ -3,21 +3,21 @@ require File.expand_path('../../spec_helper', __FILE__)
|
|
3
3
|
describe R18n::Locales::Pl do
|
4
4
|
it "uses Polish pluralization" do
|
5
5
|
pl = R18n.locale('pl')
|
6
|
-
pl.pluralize(0).
|
7
|
-
pl.pluralize(1).
|
6
|
+
expect(pl.pluralize(0)).to eq(0)
|
7
|
+
expect(pl.pluralize(1)).to eq(1)
|
8
8
|
|
9
|
-
pl.pluralize(2).
|
10
|
-
pl.pluralize(4).
|
11
|
-
pl.pluralize(22).
|
12
|
-
pl.pluralize(102).
|
9
|
+
expect(pl.pluralize(2)).to eq(2)
|
10
|
+
expect(pl.pluralize(4)).to eq(2)
|
11
|
+
expect(pl.pluralize(22)).to eq(2)
|
12
|
+
expect(pl.pluralize(102)).to eq(2)
|
13
13
|
|
14
|
-
pl.pluralize(5).
|
15
|
-
pl.pluralize(11).
|
16
|
-
pl.pluralize(12).
|
17
|
-
pl.pluralize(21).
|
18
|
-
pl.pluralize(57).
|
19
|
-
pl.pluralize(101).
|
20
|
-
pl.pluralize(111).
|
21
|
-
pl.pluralize(112).
|
14
|
+
expect(pl.pluralize(5)).to eq('n')
|
15
|
+
expect(pl.pluralize(11)).to eq('n')
|
16
|
+
expect(pl.pluralize(12)).to eq('n')
|
17
|
+
expect(pl.pluralize(21)).to eq('n')
|
18
|
+
expect(pl.pluralize(57)).to eq('n')
|
19
|
+
expect(pl.pluralize(101)).to eq('n')
|
20
|
+
expect(pl.pluralize(111)).to eq('n')
|
21
|
+
expect(pl.pluralize(112)).to eq('n')
|
22
22
|
end
|
23
23
|
end
|
data/spec/locales/ru_spec.rb
CHANGED
@@ -3,21 +3,21 @@ require File.expand_path('../../spec_helper', __FILE__)
|
|
3
3
|
describe R18n::Locales::Ru do
|
4
4
|
it "uses Russian pluralization" do
|
5
5
|
ru = R18n.locale('ru')
|
6
|
-
ru.pluralize(0).
|
6
|
+
expect(ru.pluralize(0)).to eq(0)
|
7
7
|
|
8
|
-
ru.pluralize(1).
|
9
|
-
ru.pluralize(21).
|
10
|
-
ru.pluralize(101).
|
8
|
+
expect(ru.pluralize(1)).to eq(1)
|
9
|
+
expect(ru.pluralize(21)).to eq(1)
|
10
|
+
expect(ru.pluralize(101)).to eq(1)
|
11
11
|
|
12
|
-
ru.pluralize(2).
|
13
|
-
ru.pluralize(4).
|
14
|
-
ru.pluralize(22).
|
15
|
-
ru.pluralize(102).
|
12
|
+
expect(ru.pluralize(2)).to eq(2)
|
13
|
+
expect(ru.pluralize(4)).to eq(2)
|
14
|
+
expect(ru.pluralize(22)).to eq(2)
|
15
|
+
expect(ru.pluralize(102)).to eq(2)
|
16
16
|
|
17
|
-
ru.pluralize(5).
|
18
|
-
ru.pluralize(11).
|
19
|
-
ru.pluralize(12).
|
20
|
-
ru.pluralize(57).
|
21
|
-
ru.pluralize(111).
|
17
|
+
expect(ru.pluralize(5)).to eq('n')
|
18
|
+
expect(ru.pluralize(11)).to eq('n')
|
19
|
+
expect(ru.pluralize(12)).to eq('n')
|
20
|
+
expect(ru.pluralize(57)).to eq('n')
|
21
|
+
expect(ru.pluralize(111)).to eq('n')
|
22
22
|
end
|
23
23
|
end
|
data/spec/locales/sk_spec.rb
CHANGED
@@ -3,21 +3,21 @@ require File.expand_path('../../spec_helper', __FILE__)
|
|
3
3
|
describe R18n::Locales::Sk do
|
4
4
|
it "uses Slovak pluralization" do
|
5
5
|
sk = R18n.locale('Sk')
|
6
|
-
sk.pluralize(0).
|
7
|
-
sk.pluralize(1).
|
6
|
+
expect(sk.pluralize(0)).to eq(0)
|
7
|
+
expect(sk.pluralize(1)).to eq(1)
|
8
8
|
|
9
|
-
sk.pluralize(2).
|
10
|
-
sk.pluralize(3).
|
11
|
-
sk.pluralize(4).
|
9
|
+
expect(sk.pluralize(2)).to eq(2)
|
10
|
+
expect(sk.pluralize(3)).to eq(2)
|
11
|
+
expect(sk.pluralize(4)).to eq(2)
|
12
12
|
|
13
|
-
sk.pluralize(5).
|
14
|
-
sk.pluralize(21).
|
15
|
-
sk.pluralize(11).
|
16
|
-
sk.pluralize(12).
|
17
|
-
sk.pluralize(22).
|
18
|
-
sk.pluralize(57).
|
19
|
-
sk.pluralize(101).
|
20
|
-
sk.pluralize(102).
|
21
|
-
sk.pluralize(111).
|
13
|
+
expect(sk.pluralize(5)).to eq('n')
|
14
|
+
expect(sk.pluralize(21)).to eq('n')
|
15
|
+
expect(sk.pluralize(11)).to eq('n')
|
16
|
+
expect(sk.pluralize(12)).to eq('n')
|
17
|
+
expect(sk.pluralize(22)).to eq('n')
|
18
|
+
expect(sk.pluralize(57)).to eq('n')
|
19
|
+
expect(sk.pluralize(101)).to eq('n')
|
20
|
+
expect(sk.pluralize(102)).to eq('n')
|
21
|
+
expect(sk.pluralize(111)).to eq('n')
|
22
22
|
end
|
23
23
|
end
|
data/spec/locales/th_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require File.expand_path('../../spec_helper', __FILE__)
|
|
3
3
|
describe R18n::Locales::Ru do
|
4
4
|
it "uses Thai calendar" do
|
5
5
|
th = R18n::I18n.new('th')
|
6
|
-
th.l(Time.at(0).utc, '%Y %y').
|
7
|
-
th.l(Time.at(0).utc).
|
6
|
+
expect(th.l(Time.at(0).utc, '%Y %y')).to eq('2513 13')
|
7
|
+
expect(th.l(Time.at(0).utc)).to eq('01/01/2513 00:00')
|
8
8
|
end
|
9
9
|
end
|
data/spec/r18n_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 do
|
@@ -13,10 +12,10 @@ describe R18n do
|
|
13
12
|
it "stores I18n" do
|
14
13
|
i18n = R18n::I18n.new('en')
|
15
14
|
R18n.set(i18n)
|
16
|
-
R18n.get.
|
15
|
+
expect(R18n.get).to eq(i18n)
|
17
16
|
|
18
17
|
R18n.reset!
|
19
|
-
R18n.get.
|
18
|
+
expect(R18n.get).to be_nil
|
20
19
|
end
|
21
20
|
|
22
21
|
it "sets setter to I18n" do
|
@@ -26,25 +25,25 @@ describe R18n do
|
|
26
25
|
i18n = R18n::I18n.new('ru')
|
27
26
|
R18n.set { i18n }
|
28
27
|
|
29
|
-
R18n.get.
|
28
|
+
expect(R18n.get).to eq(i18n)
|
30
29
|
end
|
31
30
|
|
32
31
|
it "creates I18n object by shortcut" do
|
33
32
|
R18n.set('en', DIR)
|
34
|
-
R18n.get.
|
35
|
-
R18n.get.locales.
|
36
|
-
R18n.get.translation_places.
|
33
|
+
expect(R18n.get).to be_kind_of(R18n::I18n)
|
34
|
+
expect(R18n.get.locales).to eq([R18n.locale('en')])
|
35
|
+
expect(R18n.get.translation_places).to eq([R18n::Loader::YAML.new(DIR)])
|
37
36
|
end
|
38
37
|
|
39
38
|
it "allows to return I18n arguments in setter block" do
|
40
39
|
R18n.set { 'en' }
|
41
|
-
R18n.get.locales.
|
40
|
+
expect(R18n.get.locales).to eq([R18n.locale('en')])
|
42
41
|
end
|
43
42
|
|
44
43
|
it "clears cache" do
|
45
44
|
R18n.cache[:a] = 1
|
46
45
|
R18n.clear_cache!
|
47
|
-
R18n.cache.
|
46
|
+
expect(R18n.cache).to be_empty
|
48
47
|
end
|
49
48
|
|
50
49
|
it "resets I18n objects and cache" do
|
@@ -53,116 +52,115 @@ describe R18n do
|
|
53
52
|
R18n.thread_set('en')
|
54
53
|
|
55
54
|
R18n.reset!
|
56
|
-
R18n.get.
|
57
|
-
R18n.cache.
|
55
|
+
expect(R18n.get).to be_nil
|
56
|
+
expect(R18n.cache).to be_empty
|
58
57
|
end
|
59
58
|
|
60
59
|
it "stores I18n via thread_set" do
|
61
60
|
i18n = R18n::I18n.new('en')
|
62
61
|
R18n.thread_set(i18n)
|
63
|
-
R18n.get.
|
62
|
+
expect(R18n.get).to eq(i18n)
|
64
63
|
|
65
64
|
i18n = R18n::I18n.new('ru')
|
66
65
|
R18n.thread_set { i18n }
|
67
|
-
R18n.get.
|
66
|
+
expect(R18n.get).to eq(i18n)
|
68
67
|
end
|
69
68
|
|
70
69
|
it "allows to temporary change locale" do
|
71
70
|
R18n.default_places = DIR
|
72
|
-
R18n.change('en').locales.
|
73
|
-
R18n.change('en').
|
74
|
-
R18n.change('en').translation_places.first.dir.
|
71
|
+
expect(R18n.change('en').locales).to eq([R18n.locale('en')])
|
72
|
+
expect(R18n.change('en').translation_places.size).to eq(1)
|
73
|
+
expect(R18n.change('en').translation_places.first.dir).to eq(DIR.to_s)
|
75
74
|
end
|
76
75
|
|
77
76
|
it "allows to temporary change current locales" do
|
78
77
|
R18n.set('ru')
|
79
|
-
R18n.change('en').locales.
|
80
|
-
|
81
|
-
R18n.
|
78
|
+
expect(R18n.change('en').locales).to eq(
|
79
|
+
[R18n.locale('en'), R18n.locale('ru')])
|
80
|
+
expect(R18n.change('en').translation_places).to eq(
|
81
|
+
R18n.get.translation_places)
|
82
|
+
expect(R18n.get.locale.code).to eq('ru')
|
82
83
|
end
|
83
84
|
|
84
85
|
it "allows to get Locale to temporary change" do
|
85
86
|
R18n.set('ru')
|
86
|
-
R18n.change(R18n.locale('en')).locale.code.
|
87
|
+
expect(R18n.change(R18n.locale('en')).locale.code).to eq('en')
|
87
88
|
end
|
88
89
|
|
89
90
|
it "has shortcut to load locale" do
|
90
|
-
R18n.locale('ru').
|
91
|
+
expect(R18n.locale('ru')).to eq(R18n::Locale.load('ru'))
|
91
92
|
end
|
92
93
|
|
93
94
|
it "stores default loader class" do
|
94
|
-
R18n.default_loader.
|
95
|
+
expect(R18n.default_loader).to eq(R18n::Loader::YAML)
|
95
96
|
R18n.default_loader = Class
|
96
|
-
R18n.default_loader.
|
97
|
+
expect(R18n.default_loader).to be_kind_of(Class)
|
97
98
|
end
|
98
99
|
|
99
100
|
it "stores cache" do
|
100
|
-
R18n.cache.
|
101
|
+
expect(R18n.cache).to be_kind_of(Hash)
|
101
102
|
|
102
103
|
R18n.cache = { 1 => 2 }
|
103
|
-
R18n.cache.
|
104
|
+
expect(R18n.cache).to eq({ 1 => 2 })
|
104
105
|
|
105
106
|
R18n.clear_cache!
|
106
|
-
R18n.cache.
|
107
|
-
end
|
108
|
-
|
109
|
-
it "converts Time to Date" do
|
110
|
-
R18n::Utils.to_date(Time.now).should == Date.today
|
107
|
+
expect(R18n.cache).to eq({ })
|
111
108
|
end
|
112
109
|
|
113
110
|
it "maps hash" do
|
114
|
-
R18n::Utils.hash_map({'a' => 1, 'b' => 2}) { |k, v|
|
115
|
-
|
111
|
+
hash = R18n::Utils.hash_map({ 'a' => 1, 'b' => 2 }) { |k, v|
|
112
|
+
[k + 'a', v + 1]
|
113
|
+
}
|
114
|
+
expect(hash).to eq({ 'aa' => 2, 'ba' => 3 })
|
116
115
|
end
|
117
116
|
|
118
117
|
it "merges hash recursively" do
|
119
|
-
a = { :
|
120
|
-
b = {
|
118
|
+
a = { a: 1, b: { ba: 1, bb: 1}, c: 1 }
|
119
|
+
b = { b: { bb: 2, bc: 2}, c: 2 }
|
121
120
|
|
122
121
|
R18n::Utils.deep_merge!(a, b)
|
123
|
-
a.
|
122
|
+
expect(a).to eq({ a: 1, b: { ba: 1, bb: 2, bc: 2 }, c: 2 })
|
124
123
|
end
|
125
124
|
|
126
125
|
it "has l and t methods" do
|
127
126
|
R18n.set('en')
|
128
|
-
t.yes.
|
129
|
-
l(Time.at(0).utc).
|
127
|
+
expect(t.yes).to eq('Yes')
|
128
|
+
expect(l(Time.at(0).utc)).to eq('01/01/1970 00:00')
|
130
129
|
end
|
131
130
|
|
132
131
|
it "has helpers mixin" do
|
133
132
|
obj = R18n::I18n.new('en')
|
134
133
|
R18n.set(obj)
|
135
134
|
|
136
|
-
r18n.
|
137
|
-
i18n.
|
138
|
-
t.yes.
|
139
|
-
l(Time.at(0).utc).
|
135
|
+
expect(r18n).to eq(obj)
|
136
|
+
expect(i18n).to eq(obj)
|
137
|
+
expect(t.yes).to eq('Yes')
|
138
|
+
expect(l(Time.at(0).utc)).to eq('01/01/1970 00:00')
|
140
139
|
end
|
141
140
|
|
142
141
|
it "returns available translations" do
|
143
|
-
R18n.available_locales(DIR).
|
142
|
+
expect(R18n.available_locales(DIR)).to match_array([R18n.locale('nolocale'),
|
144
143
|
R18n.locale('ru'),
|
145
|
-
R18n.locale('en')]
|
144
|
+
R18n.locale('en')])
|
146
145
|
end
|
147
146
|
|
148
147
|
it "uses default places" do
|
149
148
|
R18n.default_places = DIR
|
150
149
|
R18n.set('en')
|
151
|
-
t.one.
|
152
|
-
R18n.available_locales.
|
150
|
+
expect(t.one).to eq('One')
|
151
|
+
expect(R18n.available_locales).to match_array([R18n.locale('ru'),
|
153
152
|
R18n.locale('en'),
|
154
|
-
R18n.locale('nolocale')]
|
153
|
+
R18n.locale('nolocale')])
|
155
154
|
end
|
156
155
|
|
157
156
|
it "sets default places by block" do
|
158
157
|
R18n.default_places { DIR }
|
159
|
-
R18n.default_places.
|
158
|
+
expect(R18n.default_places).to eq(DIR)
|
160
159
|
end
|
161
160
|
|
162
161
|
it "allows to ignore default places" do
|
163
162
|
R18n.default_places = DIR
|
164
163
|
i18n = R18n::I18n.new('en', nil)
|
165
|
-
i18n.one.
|
164
|
+
expect(i18n.one).not_to be_translated
|
166
165
|
end
|
167
|
-
|
168
166
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
require 'pp'
|
3
2
|
|
4
3
|
dir = Pathname(__FILE__).dirname
|
@@ -36,9 +35,3 @@ class CounterLoader
|
|
36
35
|
@available.hash
|
37
36
|
end
|
38
37
|
end
|
39
|
-
|
40
|
-
RSpec.configure do |c|
|
41
|
-
c.filter_run_excluding :not_ruby => lambda { |version|
|
42
|
-
RUBY_VERSION.to_s.start_with? version.to_s
|
43
|
-
}
|
44
|
-
end
|
data/spec/translated_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::Translated do
|
@@ -14,17 +13,17 @@ describe R18n::Translated do
|
|
14
13
|
end
|
15
14
|
|
16
15
|
it "saves methods map" do
|
17
|
-
@user_class.translation :name, :
|
18
|
-
@user_class.unlocalized_getters(:name).
|
19
|
-
@user_class.unlocalized_setters(:name).
|
16
|
+
@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=' })
|
20
19
|
end
|
21
20
|
|
22
21
|
it "autodetects methods map" do
|
23
22
|
@user_class.translation :name
|
24
|
-
@user_class.unlocalized_getters(:name).
|
25
|
-
'en' => 'name_en', 'ru' => 'name_ru' }
|
26
|
-
@user_class.unlocalized_setters(:name).
|
27
|
-
'en' => 'name_en=', 'ru' => 'name_ru=' }
|
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=' })
|
28
27
|
end
|
29
28
|
|
30
29
|
it "translates methods" do
|
@@ -32,12 +31,12 @@ describe R18n::Translated do
|
|
32
31
|
user = @user_class.new
|
33
32
|
|
34
33
|
user.name = 'John'
|
35
|
-
user.name.
|
34
|
+
expect(user.name).to eq('John')
|
36
35
|
|
37
36
|
R18n.set('ru')
|
38
|
-
user.name.
|
37
|
+
expect(user.name).to eq('John')
|
39
38
|
user.name = 'Джон'
|
40
|
-
user.name.
|
39
|
+
expect(user.name).to eq('Джон')
|
41
40
|
end
|
42
41
|
|
43
42
|
it "returns TranslatedString" do
|
@@ -48,9 +47,9 @@ describe R18n::Translated do
|
|
48
47
|
end
|
49
48
|
obj = ::SomeTranslatedClass.new
|
50
49
|
|
51
|
-
obj.name.
|
52
|
-
obj.name.locale.
|
53
|
-
obj.name.path.
|
50
|
+
expect(obj.name).to be_kind_of(R18n::TranslatedString)
|
51
|
+
expect(obj.name.locale).to eq(R18n.locale('en'))
|
52
|
+
expect(obj.name.path).to eq('SomeTranslatedClass#name')
|
54
53
|
end
|
55
54
|
|
56
55
|
it "searchs translation by locales priority" do
|
@@ -59,7 +58,7 @@ describe R18n::Translated do
|
|
59
58
|
|
60
59
|
R18n.set(['nolocale', 'ru', 'en'])
|
61
60
|
user.name_ru = 'Иван'
|
62
|
-
user.name.locale.
|
61
|
+
expect(user.name.locale).to eq(R18n.locale('ru'))
|
63
62
|
end
|
64
63
|
|
65
64
|
it "uses default locale" do
|
@@ -68,42 +67,42 @@ describe R18n::Translated do
|
|
68
67
|
|
69
68
|
R18n.set('nolocale')
|
70
69
|
user.name_en = 'John'
|
71
|
-
user.name.locale.
|
70
|
+
expect(user.name.locale).to eq(R18n.locale('en'))
|
72
71
|
end
|
73
72
|
|
74
73
|
it "uses filters" do
|
75
74
|
@user_class.class_eval do
|
76
75
|
def age_en; {1 => '%1 year', 'n' => '%1 years'} end
|
77
|
-
translation :age, :
|
76
|
+
translation :age, type: 'pl', no_params: true
|
78
77
|
end
|
79
78
|
user = @user_class.new
|
80
79
|
|
81
|
-
user.age(20).
|
80
|
+
expect(user.age(20)).to eq('20 years')
|
82
81
|
end
|
83
82
|
|
84
83
|
it "sends params to method if user want it" do
|
85
84
|
@user_class.class_eval do
|
86
85
|
def no_params_en(*params) params.join(' '); end
|
87
86
|
def params_en(*params) params.join(' '); end
|
88
|
-
translations [:no_params, {:
|
87
|
+
translations [:no_params, { no_params: true }], :params
|
89
88
|
end
|
90
89
|
user = @user_class.new
|
91
90
|
|
92
|
-
user.no_params(1, 2).
|
93
|
-
user.params(1, 2).
|
91
|
+
expect(user.no_params(1, 2)).to eq('')
|
92
|
+
expect(user.params(1, 2)).to eq('1 2')
|
94
93
|
end
|
95
94
|
|
96
95
|
it "translates virtual methods" do
|
97
96
|
@virtual_class = Class.new do
|
98
97
|
include R18n::Translated
|
99
|
-
translation :no_method, :
|
98
|
+
translation :no_method, methods: { en: :no_method_en }
|
100
99
|
def method_missing(name, *params)
|
101
100
|
name.to_s
|
102
101
|
end
|
103
102
|
end
|
104
103
|
virtual = @virtual_class.new
|
105
104
|
|
106
|
-
virtual.no_method.
|
105
|
+
expect(virtual.no_method).to eq('no_method_en')
|
107
106
|
end
|
108
107
|
|
109
108
|
it "returns original type of result" do
|
@@ -115,7 +114,7 @@ describe R18n::Translated do
|
|
115
114
|
end
|
116
115
|
user = @user_class.new
|
117
116
|
|
118
|
-
user.name.
|
117
|
+
expect(user.name).to eq(:ivan)
|
119
118
|
end
|
120
119
|
|
121
120
|
it "returns nil" do
|
@@ -127,7 +126,7 @@ describe R18n::Translated do
|
|
127
126
|
end
|
128
127
|
user = @user_class.new
|
129
128
|
|
130
|
-
user.name.
|
129
|
+
expect(user.name).to be_nil
|
131
130
|
end
|
132
131
|
|
133
132
|
it "allows to change I18n object" do
|
@@ -140,9 +139,8 @@ describe R18n::Translated do
|
|
140
139
|
user.name_en = 'John'
|
141
140
|
|
142
141
|
user.r18n = R18n::I18n.new('ru')
|
143
|
-
user.name.
|
142
|
+
expect(user.name).to eq('Иван')
|
144
143
|
user.r18n = R18n::I18n.new('en')
|
145
|
-
user.name.
|
144
|
+
expect(user.name).to eq('John')
|
146
145
|
end
|
147
|
-
|
148
146
|
end
|