r18n-core 2.2.0 → 3.0.0
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.
- checksums.yaml +5 -5
- data/.rspec +1 -1
- data/ChangeLog.md +6 -1
- data/README.md +1 -20
- data/Rakefile +5 -3
- data/lib/r18n-core.rb +55 -55
- data/lib/r18n-core/filter_list.rb +34 -36
- data/lib/r18n-core/filters.rb +68 -51
- data/lib/r18n-core/helpers.rb +17 -17
- data/lib/r18n-core/i18n.rb +46 -39
- data/lib/r18n-core/locale.rb +79 -70
- data/lib/r18n-core/translated.rb +65 -66
- data/lib/r18n-core/translated_string.rb +24 -24
- data/lib/r18n-core/translation.rb +31 -30
- data/lib/r18n-core/unsupported_locale.rb +22 -24
- data/lib/r18n-core/untranslated.rb +35 -33
- data/lib/r18n-core/utils.rb +26 -25
- data/lib/r18n-core/version.rb +4 -1
- data/lib/r18n-core/yaml_loader.rb +26 -25
- data/lib/r18n-core/yaml_methods.rb +25 -28
- data/locales/af.rb +15 -8
- data/locales/az.rb +19 -12
- data/locales/bg.rb +16 -9
- data/locales/ca.rb +16 -9
- data/locales/cs.rb +27 -20
- data/locales/da.rb +15 -8
- data/locales/de.rb +16 -9
- data/locales/en-au.rb +10 -5
- data/locales/en-gb.rb +12 -5
- data/locales/en-us.rb +12 -5
- data/locales/en.rb +29 -22
- data/locales/eo.rb +14 -7
- data/locales/es-us.rb +12 -5
- data/locales/es.rb +14 -7
- data/locales/fa.rb +48 -32
- data/locales/fi.rb +19 -12
- data/locales/fr.rb +22 -15
- data/locales/gl.rb +15 -8
- data/locales/hr.rb +24 -17
- data/locales/hu.rb +28 -21
- data/locales/id.rb +14 -7
- data/locales/it.rb +21 -14
- data/locales/ja.rb +15 -8
- data/locales/kk.rb +17 -10
- data/locales/ko.rb +15 -9
- data/locales/lv.rb +24 -17
- data/locales/mn.rb +10 -3
- data/locales/nb.rb +15 -8
- data/locales/nl.rb +15 -8
- data/locales/no.rb +11 -16
- data/locales/pl.rb +26 -19
- data/locales/pt-br.rb +12 -5
- data/locales/pt.rb +17 -10
- data/locales/ru.rb +26 -19
- data/locales/sk.rb +27 -20
- data/locales/sr-latn.rb +27 -22
- data/locales/sv-se.rb +15 -8
- data/locales/th.rb +27 -20
- data/locales/tr.rb +16 -9
- data/locales/uk.rb +19 -12
- data/locales/vi.rb +14 -7
- data/locales/zh-cn.rb +12 -5
- data/locales/zh-tw.rb +15 -8
- data/locales/zh.rb +14 -7
- data/r18n-core.gemspec +5 -3
- data/spec/filters_spec.rb +71 -67
- data/spec/i18n_spec.rb +73 -51
- data/spec/locale_spec.rb +73 -68
- data/spec/locales/cs_spec.rb +2 -2
- data/spec/locales/en-us_spec.rb +9 -9
- data/spec/locales/en_spec.rb +2 -2
- data/spec/locales/fa_spec.rb +3 -3
- data/spec/locales/fr_spec.rb +2 -2
- data/spec/locales/hu_spec.rb +7 -7
- data/spec/locales/it_spec.rb +3 -3
- data/spec/locales/no_spec.rb +9 -0
- data/spec/locales/pl_spec.rb +2 -2
- data/spec/locales/ru_spec.rb +2 -2
- data/spec/locales/sk_spec.rb +2 -2
- data/spec/locales/th_spec.rb +2 -2
- data/spec/locales/vi_spec.rb +2 -2
- data/spec/r18n_spec.rb +44 -38
- data/spec/spec_helper.rb +13 -9
- data/spec/translated_spec.rb +48 -31
- data/spec/translation_spec.rb +29 -27
- data/spec/translations/general/en.yml +0 -2
- data/spec/yaml_loader_spec.rb +22 -18
- metadata +5 -3
data/spec/locales/cs_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe R18n::Locales::Cs do
|
4
|
-
it
|
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)
|
data/spec/locales/en-us_spec.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe R18n::Locales::EnUs do
|
4
|
-
it
|
5
|
-
|
6
|
-
expect(
|
7
|
-
expect(
|
8
|
-
expect(
|
9
|
-
expect(
|
10
|
-
expect(
|
11
|
-
expect(
|
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
|
data/spec/locales/en_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe R18n::Locales::En do
|
4
|
-
it
|
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')
|
data/spec/locales/fa_spec.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe R18n::Locales::Fa do
|
4
|
-
it
|
4
|
+
it 'formats Persian numerals' do
|
5
5
|
fa = R18n::I18n.new('fa')
|
6
|
-
expect(fa.l(
|
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
|
data/spec/locales/fr_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe R18n::Locales::Fr do
|
4
|
-
it
|
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')
|
data/spec/locales/hu_spec.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe R18n::Locales::Hu do
|
4
|
-
it
|
4
|
+
it 'uses Hungarian digits groups' do
|
5
5
|
hu = R18n::I18n.new('hu')
|
6
|
-
expect(hu.l(1000)).to
|
7
|
-
expect(hu.l(
|
8
|
-
expect(hu.l(-
|
9
|
-
expect(hu.l(
|
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
|
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')
|
data/spec/locales/it_spec.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe R18n::Locales::It do
|
4
|
-
it
|
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(
|
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
|
data/spec/locales/pl_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe R18n::Locales::Pl do
|
4
|
-
it
|
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)
|
data/spec/locales/ru_spec.rb
CHANGED
data/spec/locales/sk_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe R18n::Locales::Sk do
|
4
|
-
it
|
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)
|
data/spec/locales/th_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe R18n::Locales::Th do
|
4
|
-
it
|
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')
|
data/spec/locales/vi_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe R18n::Locales::Vi do
|
4
|
-
it
|
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
|
data/spec/r18n_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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(
|
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
|
111
|
-
hash = R18n::Utils.hash_map(
|
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(
|
115
|
+
end
|
116
|
+
expect(hash).to eq('aa' => 2, 'ba' => 3)
|
115
117
|
end
|
116
118
|
|
117
|
-
it
|
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(
|
124
|
+
expect(a).to eq(a: 1, b: { ba: 1, bb: 2, bc: 2 }, c: 2)
|
123
125
|
end
|
124
126
|
|
125
|
-
it
|
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
|
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
|
142
|
-
expect(R18n.available_locales(DIR)).to match_array([
|
143
|
-
|
144
|
-
|
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
|
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([
|
152
|
-
|
153
|
-
|
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
|
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
|
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
|
data/spec/spec_helper.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'pp'
|
4
4
|
|
5
|
-
|
6
|
-
Dir.glob(
|
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 =
|
9
|
-
DIR = TRANSLATIONS
|
10
|
-
TWO = TRANSLATIONS
|
11
|
-
|
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(
|
33
|
+
def load(_locale)
|
30
34
|
@loaded += 1
|
31
35
|
{}
|
32
36
|
end
|
data/spec/translated_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
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
|
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(
|
18
|
-
expect(@user_class.unlocalized_setters(:name)).to eq(
|
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
|
22
|
+
it 'autodetects methods map' do
|
22
23
|
@user_class.translation :name
|
23
|
-
expect(@user_class.unlocalized_getters(:name)).to eq(
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
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
|
43
|
-
class
|
45
|
+
it 'returns TranslatedString' do
|
46
|
+
class SomeTranslatedClass
|
44
47
|
include R18n::Translated
|
45
|
-
|
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
|
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([
|
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
|
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
|
74
|
-
@user_class.
|
75
|
-
def age_en
|
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
|
84
|
-
@user_class.
|
85
|
-
def no_params_en(*params)
|
86
|
-
|
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
|
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
|
-
|
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
|
109
|
-
@user_class.
|
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
|
121
|
-
@user_class.
|
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
|
133
|
-
@user_class.
|
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
|